django-macaddress-1.3.2/0000775000076400007640000000000012564600702014621 5ustar kra3kra300000000000000django-macaddress-1.3.2/setup.cfg0000664000076400007640000000013012564600702016434 0ustar kra3kra300000000000000[bdist_wheel] universal = 1 [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 django-macaddress-1.3.2/PKG-INFO0000664000076400007640000001370512564600702015724 0ustar kra3kra300000000000000Metadata-Version: 1.1 Name: django-macaddress Version: 1.3.2 Summary: MAC address model and form fields for Django apps. Home-page: http://github.com/tubaman/django-macaddress Author: Arun K. R. Author-email: the1.arun@gmail.com License: BSD Description: django-macaddress ================ .. image:: https://api.travis-ci.org/tubaman/django-macaddress.png?branch=master :alt: Build Status :target: https://travis-ci.org/tubaman/django-macaddress .. image:: https://pypip.in/v/django-macaddress/badge.png :target: https://crate.io/packages/django-macaddress .. image:: https://pypip.in/d/django-macaddress/badge.png :target: https://crate.io/packages/django-macaddress MAC Address model and form fields for Django We use netaddr to parse and validate the MAC address. The tests aren't complete yet. Patches welcome: http://github.com/tubaman/django-macaddress Release Notes: ************** v1.3 ---- + Added the option to store MAC Addresses in the database as strings, based on a an initialization argument (see documentation, below). + Added support for defining a default EUI dialect class (netaddr built-in, or custom) to ``settings.py`` as the ``MACADDRESS_DEFAULT_DIALECT`` variable (see documentation, below). + Added a utility function, ``format_mac`` to return the stored MAC Address as a string formatted using any provided subclass of ``netaddr.eui_48`` (see example below). Getting Started *************** settings.MACADDRESS_DEFAULT_DIALECT ----------------------------------- To specify a default dialect for presentation (and storage, see below), specify:: settings.MACADDRESS_DEFAULT_DIALECT = 'module.dialect_class' where the specified value is a string composed of a parent python module name and the child dialect class name. For example:: settings.MACADDRESS_DEFAULT_DIALECT = 'netaddr.mac_eui48' PS: old default of macaddress.mac_linux (uppercase and divided by ':' ) will be used by default. If the custom dialect is defined in a package module, you will need to define the class in or import into the package's ``__init__.py``. ``default_dialect`` and ``format_mac`` -------------------------------------- To get the default dialect for your project, import and call the ``default_dialect`` function:: >>> from macaddress import default_dialect >>> dialect = default_dialect() This function may, optionally, be called with an ``netaddr.EUI`` class instance as its argument. If no default is defined in ``settings``, it will return the dialect of the provided ``EUI`` object. The ``format_mac`` function takes an ``EUI`` instance and a dialect class (``netaddr.mac_eui48`` or a subclass) as its arguments. The dialect class may be specified as a string in the same manner as ``settings.MACADDRESS_DEFAULT_DIALECT``:: >>> from netaddr import EUI, mac_bare >>> from macaddress import format_mac >>> mac = EUI('00:12:3c:37:64:8f') >>> format_mac(mac, mac_bare) '00123C37648F' >>> format_mac(mac, 'netaddr.mac_cisco') '0012.3c37.648f' MACAddressField (ModelField) ---------------------------- This is an example model using MACAddressField:: from macaddress.fields import MACAddressField class Computer(models.Model): name = models.CharField(max_length=32) eth0 = MACAddressField(null=True, blank=True) ... The default behavior is to store the MAC Address in the database is a BigInteger. If you would, rather, store the value as a string (to, for instance, facilitate sub-string searches), you can specify ``integer=False`` and the value will be stored as a string:: class Computer(models.Model): name = models.CharField(max_length=32) eth0 = MACAddressField(blank=True, integer=False) ... If you want to set ``unique=True`` on a MACAddressField that is stored as a string, you will need to set ``null=True`` and create custom ``clean_`` methods on your ``forms.ModelForm`` class for each MACAddressField that return ``None`` when the value provided is an ``''`` (empty string):: from .models import Computer class ComputerForm(forms.ModelForm): class Meta: model = Computer def clean_eth0(self): return self.cleaned_data['eth0'] or None You should avoid changing the value of ``integer`` after running ``managy.py syncdb``, unless you are using a schema migration solution like South or Django's built-in migrations. To Do ***** + Add greater support for partial string queries when storing MACs as strings in the database. + Add custom validator to check for duplicate MACs when mixing string and integer storage types. + Add deprecation warning and timeline for changeover to default string storage. Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Framework :: Django Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Topic :: Internet :: WWW/HTTP django-macaddress-1.3.2/setup.py0000664000076400007640000000202112564577531016343 0ustar kra3kra300000000000000import os from setuptools import setup, find_packages version = "1.3.2" def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() setup( name = "django-macaddress", version = version, url = 'http://github.com/tubaman/django-macaddress', license = 'BSD', description = "MAC address model and form fields for Django apps.", long_description = read('README.rst'), author = 'Ryan Nowakowski', author_email = 'tubaman@fattuba.com', maintainer = 'Arun K. R.', maintainer_email = 'the1.arun@gmail.com', packages = ['macaddress'], install_requires = ['netaddr'], tests_require = ['django'], test_suite="runtests.runtests", classifiers = [ 'Development Status :: 5 - Production/Stable', 'Framework :: Django', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Internet :: WWW/HTTP', ] ) django-macaddress-1.3.2/LICENSE0000664000076400007640000000277112564576166015655 0ustar kra3kra300000000000000Copyright (c) 2011 Ryan Nowakowski All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of this project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. django-macaddress-1.3.2/MANIFEST.in0000664000076400007640000000004412564576166016375 0ustar kra3kra300000000000000include LICENSE include README.rst django-macaddress-1.3.2/README.rst0000664000076400007640000001070012564576203016316 0ustar kra3kra300000000000000django-macaddress ================ .. image:: https://api.travis-ci.org/tubaman/django-macaddress.png?branch=master :alt: Build Status :target: https://travis-ci.org/tubaman/django-macaddress .. image:: https://pypip.in/v/django-macaddress/badge.png :target: https://crate.io/packages/django-macaddress .. image:: https://pypip.in/d/django-macaddress/badge.png :target: https://crate.io/packages/django-macaddress MAC Address model and form fields for Django We use netaddr to parse and validate the MAC address. The tests aren't complete yet. Patches welcome: http://github.com/tubaman/django-macaddress Release Notes: ************** v1.3 ---- + Added the option to store MAC Addresses in the database as strings, based on a an initialization argument (see documentation, below). + Added support for defining a default EUI dialect class (netaddr built-in, or custom) to ``settings.py`` as the ``MACADDRESS_DEFAULT_DIALECT`` variable (see documentation, below). + Added a utility function, ``format_mac`` to return the stored MAC Address as a string formatted using any provided subclass of ``netaddr.eui_48`` (see example below). Getting Started *************** settings.MACADDRESS_DEFAULT_DIALECT ----------------------------------- To specify a default dialect for presentation (and storage, see below), specify:: settings.MACADDRESS_DEFAULT_DIALECT = 'module.dialect_class' where the specified value is a string composed of a parent python module name and the child dialect class name. For example:: settings.MACADDRESS_DEFAULT_DIALECT = 'netaddr.mac_eui48' PS: old default of macaddress.mac_linux (uppercase and divided by ':' ) will be used by default. If the custom dialect is defined in a package module, you will need to define the class in or import into the package's ``__init__.py``. ``default_dialect`` and ``format_mac`` -------------------------------------- To get the default dialect for your project, import and call the ``default_dialect`` function:: >>> from macaddress import default_dialect >>> dialect = default_dialect() This function may, optionally, be called with an ``netaddr.EUI`` class instance as its argument. If no default is defined in ``settings``, it will return the dialect of the provided ``EUI`` object. The ``format_mac`` function takes an ``EUI`` instance and a dialect class (``netaddr.mac_eui48`` or a subclass) as its arguments. The dialect class may be specified as a string in the same manner as ``settings.MACADDRESS_DEFAULT_DIALECT``:: >>> from netaddr import EUI, mac_bare >>> from macaddress import format_mac >>> mac = EUI('00:12:3c:37:64:8f') >>> format_mac(mac, mac_bare) '00123C37648F' >>> format_mac(mac, 'netaddr.mac_cisco') '0012.3c37.648f' MACAddressField (ModelField) ---------------------------- This is an example model using MACAddressField:: from macaddress.fields import MACAddressField class Computer(models.Model): name = models.CharField(max_length=32) eth0 = MACAddressField(null=True, blank=True) ... The default behavior is to store the MAC Address in the database is a BigInteger. If you would, rather, store the value as a string (to, for instance, facilitate sub-string searches), you can specify ``integer=False`` and the value will be stored as a string:: class Computer(models.Model): name = models.CharField(max_length=32) eth0 = MACAddressField(blank=True, integer=False) ... If you want to set ``unique=True`` on a MACAddressField that is stored as a string, you will need to set ``null=True`` and create custom ``clean_`` methods on your ``forms.ModelForm`` class for each MACAddressField that return ``None`` when the value provided is an ``''`` (empty string):: from .models import Computer class ComputerForm(forms.ModelForm): class Meta: model = Computer def clean_eth0(self): return self.cleaned_data['eth0'] or None You should avoid changing the value of ``integer`` after running ``managy.py syncdb``, unless you are using a schema migration solution like South or Django's built-in migrations. To Do ***** + Add greater support for partial string queries when storing MACs as strings in the database. + Add custom validator to check for duplicate MACs when mixing string and integer storage types. + Add deprecation warning and timeline for changeover to default string storage. django-macaddress-1.3.2/django_macaddress.egg-info/0000775000076400007640000000000012564600702021743 5ustar kra3kra300000000000000django-macaddress-1.3.2/django_macaddress.egg-info/top_level.txt0000664000076400007640000000001312564600702024467 0ustar kra3kra300000000000000macaddress django-macaddress-1.3.2/django_macaddress.egg-info/SOURCES.txt0000664000076400007640000000057312564600702023634 0ustar kra3kra300000000000000LICENSE MANIFEST.in README.rst setup.cfg setup.py django_macaddress.egg-info/PKG-INFO django_macaddress.egg-info/SOURCES.txt django_macaddress.egg-info/dependency_links.txt django_macaddress.egg-info/pbr.json django_macaddress.egg-info/requires.txt django_macaddress.egg-info/top_level.txt macaddress/__init__.py macaddress/fields.py macaddress/formfields.py macaddress/models.pydjango-macaddress-1.3.2/django_macaddress.egg-info/PKG-INFO0000664000076400007640000001370512564600702023046 0ustar kra3kra300000000000000Metadata-Version: 1.1 Name: django-macaddress Version: 1.3.2 Summary: MAC address model and form fields for Django apps. Home-page: http://github.com/tubaman/django-macaddress Author: Arun K. R. Author-email: the1.arun@gmail.com License: BSD Description: django-macaddress ================ .. image:: https://api.travis-ci.org/tubaman/django-macaddress.png?branch=master :alt: Build Status :target: https://travis-ci.org/tubaman/django-macaddress .. image:: https://pypip.in/v/django-macaddress/badge.png :target: https://crate.io/packages/django-macaddress .. image:: https://pypip.in/d/django-macaddress/badge.png :target: https://crate.io/packages/django-macaddress MAC Address model and form fields for Django We use netaddr to parse and validate the MAC address. The tests aren't complete yet. Patches welcome: http://github.com/tubaman/django-macaddress Release Notes: ************** v1.3 ---- + Added the option to store MAC Addresses in the database as strings, based on a an initialization argument (see documentation, below). + Added support for defining a default EUI dialect class (netaddr built-in, or custom) to ``settings.py`` as the ``MACADDRESS_DEFAULT_DIALECT`` variable (see documentation, below). + Added a utility function, ``format_mac`` to return the stored MAC Address as a string formatted using any provided subclass of ``netaddr.eui_48`` (see example below). Getting Started *************** settings.MACADDRESS_DEFAULT_DIALECT ----------------------------------- To specify a default dialect for presentation (and storage, see below), specify:: settings.MACADDRESS_DEFAULT_DIALECT = 'module.dialect_class' where the specified value is a string composed of a parent python module name and the child dialect class name. For example:: settings.MACADDRESS_DEFAULT_DIALECT = 'netaddr.mac_eui48' PS: old default of macaddress.mac_linux (uppercase and divided by ':' ) will be used by default. If the custom dialect is defined in a package module, you will need to define the class in or import into the package's ``__init__.py``. ``default_dialect`` and ``format_mac`` -------------------------------------- To get the default dialect for your project, import and call the ``default_dialect`` function:: >>> from macaddress import default_dialect >>> dialect = default_dialect() This function may, optionally, be called with an ``netaddr.EUI`` class instance as its argument. If no default is defined in ``settings``, it will return the dialect of the provided ``EUI`` object. The ``format_mac`` function takes an ``EUI`` instance and a dialect class (``netaddr.mac_eui48`` or a subclass) as its arguments. The dialect class may be specified as a string in the same manner as ``settings.MACADDRESS_DEFAULT_DIALECT``:: >>> from netaddr import EUI, mac_bare >>> from macaddress import format_mac >>> mac = EUI('00:12:3c:37:64:8f') >>> format_mac(mac, mac_bare) '00123C37648F' >>> format_mac(mac, 'netaddr.mac_cisco') '0012.3c37.648f' MACAddressField (ModelField) ---------------------------- This is an example model using MACAddressField:: from macaddress.fields import MACAddressField class Computer(models.Model): name = models.CharField(max_length=32) eth0 = MACAddressField(null=True, blank=True) ... The default behavior is to store the MAC Address in the database is a BigInteger. If you would, rather, store the value as a string (to, for instance, facilitate sub-string searches), you can specify ``integer=False`` and the value will be stored as a string:: class Computer(models.Model): name = models.CharField(max_length=32) eth0 = MACAddressField(blank=True, integer=False) ... If you want to set ``unique=True`` on a MACAddressField that is stored as a string, you will need to set ``null=True`` and create custom ``clean_`` methods on your ``forms.ModelForm`` class for each MACAddressField that return ``None`` when the value provided is an ``''`` (empty string):: from .models import Computer class ComputerForm(forms.ModelForm): class Meta: model = Computer def clean_eth0(self): return self.cleaned_data['eth0'] or None You should avoid changing the value of ``integer`` after running ``managy.py syncdb``, unless you are using a schema migration solution like South or Django's built-in migrations. To Do ***** + Add greater support for partial string queries when storing MACs as strings in the database. + Add custom validator to check for duplicate MACs when mixing string and integer storage types. + Add deprecation warning and timeline for changeover to default string storage. Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Framework :: Django Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Topic :: Internet :: WWW/HTTP django-macaddress-1.3.2/django_macaddress.egg-info/dependency_links.txt0000664000076400007640000000000112564600702026011 0ustar kra3kra300000000000000 django-macaddress-1.3.2/django_macaddress.egg-info/pbr.json0000664000076400007640000000005712564600702023423 0ustar kra3kra300000000000000{"is_release": false, "git_version": "61662c5"}django-macaddress-1.3.2/django_macaddress.egg-info/requires.txt0000664000076400007640000000000712564600702024340 0ustar kra3kra300000000000000netaddrdjango-macaddress-1.3.2/macaddress/0000775000076400007640000000000012564600702016727 5ustar kra3kra300000000000000django-macaddress-1.3.2/macaddress/__init__.py0000664000076400007640000000476512564576203021064 0ustar kra3kra300000000000000from 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 django-macaddress-1.3.2/macaddress/formfields.py0000664000076400007640000000166612564576203021454 0ustar kra3kra300000000000000from django.forms import Field from django.forms.fields import EMPTY_VALUES #"From Django 1.8: The django.forms.util module has been renamed. Use django.forms.utils instead." try: from django.forms.utils import ValidationError except ImportError: from django.forms.util import ValidationError from netaddr import EUI, AddrFormatError class MACAddressField(Field): default_error_messages = { 'invalid': 'Enter a valid MAC Address.', } def clean(self, value): """ Validates that EUI() can be called on the input. Returns the result of EUI(). Returns None for empty values. """ value = super(MACAddressField, self).clean(value) if value in EMPTY_VALUES: return None try: value = EUI(str(value)) except (ValueError, TypeError, AddrFormatError): raise ValidationError(self.error_messages['invalid']) return value django-macaddress-1.3.2/macaddress/models.py0000664000076400007640000000004612564576166020604 0ustar kra3kra300000000000000# This file intentionally left blank. django-macaddress-1.3.2/macaddress/fields.py0000664000076400007640000000701512564576203020562 0ustar kra3kra300000000000000from django.core.exceptions import ValidationError from django.db import models from netaddr import EUI, AddrFormatError from .formfields import MACAddressField as MACAddressFormField from . import default_dialect, format_mac, mac_linux import warnings class MACAddressField(models.Field): description = "A MAC address validated by netaddr.EUI" empty_strings_allowed = False __metaclass__ = models.SubfieldBase dialect = None def __init__(self, *args, **kwargs): self.integer = kwargs.pop('integer', True) if not self.integer: # If storing MAC address as string, set max_length to default (17) or use supplied kwarg value. kwargs['max_length'] = kwargs.get('max_length', 17) super(MACAddressField, self).__init__(*args, **kwargs) def deconstruct(self): ''' Django 1.7 migrations require this method https://docs.djangoproject.com/en/dev/howto/custom-model-fields/#field-deconstruction ''' name, path, args, kwargs = super(MACAddressField, self).deconstruct() kwargs['integer'] = self.integer return name, path, args, kwargs @classmethod def set_dialect(cls, new_dialect_clazz): ''' Setting dialect for EUI (MAC addresses) globally to this Field class. Class new_dialect_clazz should (finally) extend netaddr.strategy.eui48.mac_eui48. ''' warnings.warn( "The set_dialect method 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, ) cls.dialect = new_dialect_clazz def get_prep_value(self, value): if value is None: return None if not isinstance(value, EUI): value = EUI(value, dialect=default_dialect()) if self.integer: return int(value) return str(value) value.dialect = default_dialect(self) if self.integer: return int(value) return str(value) def get_internal_type(self): if self.integer: return 'BigIntegerField' return 'CharField' def to_python(self, value): if value is None: return value if isinstance(value, EUI): value.dialect = default_dialect(value) return value try: return EUI(value, dialect=default_dialect()) except (TypeError, ValueError, AddrFormatError): raise ValidationError( "This value must be a valid MAC address.") def formfield(self, **kwargs): defaults = {'form_class': MACAddressFormField} defaults.update(kwargs) return super(MACAddressField, self).formfield(**defaults) def get_prep_lookup(self, lookup_type, value): # data is stored internally as integer so searching as string # yeild 0 result. for example: useful for search in admin. if lookup_type in ('exact', 'iexact', 'icontains', 'icontains'): try: return self.get_prep_value(value) except AddrFormatError: return None else: raise TypeError('Lookup type %r not supported.' % lookup_type) try: from south.modelsinspector import add_introspection_rules add_introspection_rules([], ["^macaddress\.fields\.MACAddressField"]) except ImportError: pass