From 68df3ddcb9cca97652dc28c9fb50f32778bba2c1 Mon Sep 17 00:00:00 2001 From: bashmak Date: Wed, 5 Jul 2017 13:35:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B5=20=D0=BC=D0=B0=D0=BA?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=B2=20=D0=BE=D0=B1=D1=89=D0=B5=D0=B5=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- abonapp/__init__.py | 59 -------------------------------------------- djing/__init__.py | 60 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 59 deletions(-) diff --git a/abonapp/__init__.py b/abonapp/__init__.py index 8e82010..e69de29 100644 --- a/abonapp/__init__.py +++ b/abonapp/__init__.py @@ -1,59 +0,0 @@ -from django.conf import settings - -from netaddr import mac_unix, mac_eui48 - -import importlib -import warnings - -class mac_linux(mac_unix): - """MAC format with zero-padded all upper-case hex and colon separated""" - word_fmt = '%.2X' - -def default_dialect(eui_obj=None): - # Check to see if a default dialect class has been specified in settings, - # using 'module.dialect_cls' string and use importlib and getattr to retrieve dialect class. 'module' is the module and - # 'dialect_cls' is the class name of the custom dialect. The dialect must either be defined or imported by the module's - # __init__.py if the module is a package. - from .fields import MACAddressField # Remove import at v1.4 - if hasattr(settings, 'MACADDRESS_DEFAULT_DIALECT') and not MACAddressField.dialect: - module, dialect_cls = settings.MACADDRESS_DEFAULT_DIALECT.split('.') - dialect = getattr(importlib.import_module(module), dialect_cls, mac_linux) - return dialect - else: - if MACAddressField.dialect: # Remove this "if" statement at v1.4 - warnings.warn( - "The set_dialect class method on MACAddressField has been deprecated, in favor of the default_dialect " - "utility function and settings.MACADDRESS_DEFAULT_DIALECT. See macaddress.__init__.py source or the " - "project README for more information.", - DeprecationWarning, - ) - return MACAddressField.dialect - if eui_obj: - return eui_obj.dialect - else: - return mac_linux - -def format_mac(eui_obj, dialect): - # Format a EUI instance as a string using the supplied dialect class, allowing custom string classes by - # passing directly or as a string, a la 'module.dialect_cls', where 'module' is the module and 'dialect_cls' - # is the class name of the custom dialect. The dialect must either be defined or imported by the module's __init__.py if - # the module is a package. - if not isinstance(dialect, mac_eui48): - if isinstance(dialect, str): - module, dialect_cls = dialect.split('.') - dialect = getattr(importlib.import_module(module), dialect_cls) - eui_obj.dialect = dialect - return str(eui_obj) - - -from pkg_resources import get_distribution, DistributionNotFound -import os.path - -try: - _dist = get_distribution('django-macaddress') -except DistributionNotFound: - __version__ = 'Please install this project with setup.py' -else: - __version__ = _dist.version -VERSION = __version__ # synonym -default_app_config = 'abonapp.apps.AbonappConfig' diff --git a/djing/__init__.py b/djing/__init__.py index e69de29..8c21558 100644 --- a/djing/__init__.py +++ b/djing/__init__.py @@ -0,0 +1,60 @@ +import importlib +import warnings + +from django.conf import settings +from netaddr import mac_unix, mac_eui48 + + +MAC_ADDR_REGEX = r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$' + +class mac_linux(mac_unix): + """MAC format with zero-padded all upper-case hex and colon separated""" + word_fmt = '%.2X' + +def default_dialect(eui_obj=None): + # Check to see if a default dialect class has been specified in settings, + # using 'module.dialect_cls' string and use importlib and getattr to retrieve dialect class. 'module' is the module and + # 'dialect_cls' is the class name of the custom dialect. The dialect must either be defined or imported by the module's + # __init__.py if the module is a package. + from .fields import MACAddressField # Remove import at v1.4 + if hasattr(settings, 'MACADDRESS_DEFAULT_DIALECT') and not MACAddressField.dialect: + module, dialect_cls = settings.MACADDRESS_DEFAULT_DIALECT.split('.') + dialect = getattr(importlib.import_module(module), dialect_cls, mac_linux) + return dialect + else: + if MACAddressField.dialect: # Remove this "if" statement at v1.4 + warnings.warn( + "The set_dialect class method on MACAddressField has been deprecated, in favor of the default_dialect " + "utility function and settings.MACADDRESS_DEFAULT_DIALECT. See macaddress.__init__.py source or the " + "project README for more information.", + DeprecationWarning, + ) + return MACAddressField.dialect + if eui_obj: + return eui_obj.dialect + else: + return mac_linux + +def format_mac(eui_obj, dialect): + # Format a EUI instance as a string using the supplied dialect class, allowing custom string classes by + # passing directly or as a string, a la 'module.dialect_cls', where 'module' is the module and 'dialect_cls' + # is the class name of the custom dialect. The dialect must either be defined or imported by the module's __init__.py if + # the module is a package. + if not isinstance(dialect, mac_eui48): + if isinstance(dialect, str): + module, dialect_cls = dialect.split('.') + dialect = getattr(importlib.import_module(module), dialect_cls) + eui_obj.dialect = dialect + return str(eui_obj) + + +from pkg_resources import get_distribution, DistributionNotFound + +try: + _dist = get_distribution('django-macaddress') +except DistributionNotFound: + __version__ = 'Please install this project with setup.py' +else: + __version__ = _dist.version +VERSION = __version__ # synonym +default_app_config = 'abonapp.apps.AbonappConfig'