1# Copyright 2013 The Distro Tracker Developers 

2# See the COPYRIGHT file at the top-level directory of this distribution and 

3# at https://deb.li/DTAuthors 

4# 

5# This file is part of Distro Tracker. It is subject to the license terms 

6# in the LICENSE file found in the top-level directory of this 

7# distribution and at https://deb.li/DTLicense. No part of Distro Tracker, 

8# including this file, may be copied, modified, propagated, or distributed 

9# except according to the terms contained in the LICENSE file. 

10""" 

11This Django app implements a custom User authentication model which lets users 

12log in using a set of different email addresses. 

13""" 

14import importlib 

15 

16from django.conf import settings 

17 

18 

19def run_hook(name, *args, **kwargs): 

20 """ 

21 Since :mod:`django_email_accounts` provides a way for users to execute 

22 custom functions at certain points, this function is used to run find 

23 the appropriate one and run it with the given arguments and keyword 

24 arguments. 

25 """ 

26 name_to_setting = { 

27 'post-merge': 'DJANGO_EMAIL_ACCOUNTS_POST_MERGE_HOOK', 

28 'pre-login': 'DJANGO_EMAIL_ACCOUNTS_PRE_LOGIN_HOOK', 

29 'post-logout-redirect': 'DJANGO_EMAIL_ACCOUNTS_POST_LOGOUT_REDIRECT', 

30 } 

31 if name not in name_to_setting: 31 ↛ 32line 31 didn't jump to line 32, because the condition on line 31 was never true

32 return 

33 

34 settings_name = name_to_setting[name] 

35 function_name = getattr(settings, settings_name, None) 

36 if not function_name: 36 ↛ 39line 36 didn't jump to line 39, because the condition on line 36 was never false

37 return 

38 

39 module, function_name = function_name.rsplit('.', 1) 

40 module = importlib.import_module(module) 

41 function = getattr(module, function_name) 

42 

43 return function(*args, **kwargs)