Package netaddr
[frames] | no frames]

Source Code for Package netaddr

 1  #!/usr/bin/env python 
 2  #----------------------------------------------------------------------------- 
 3  #   Copyright (c) 2008, David P. D. Moss. All rights reserved. 
 4  # 
 5  #   Released under the BSD license. See the LICENSE file for details. 
 6  #----------------------------------------------------------------------------- 
 7  """ 
 8  network address manipulation, done Pythonically 
 9  """ 
10  __version__ = '0.6' 
11   
12  import struct as _struct 
13   
14  #----------------------------------------------------------------------------- 
15  #  Constants. 
16  #----------------------------------------------------------------------------- 
17   
18  #: True if platform is natively big endian, False otherwise. 
19  BIG_ENDIAN_PLATFORM = _struct.pack('=h', 1) == _struct.pack('>h', 1) 
20   
21  AT_UNSPEC = 0x0     #: unspecified address type constant. 
22  AT_INET   = 0x4     #: IPv4 address type constant. 
23  AT_INET6  = 0x6     #: IPv6 address type constant. 
24  AT_LINK   = 0x30    #: MAC/EUI-48 address type constant. 
25  AT_EUI64  = 0x40    #: EUI-64 address type constant. 
26   
27  #: Address type to address description lookup dictionary. 
28  AT_NAMES = { 
29      #   Address Type : Descriptive Name. 
30      AT_UNSPEC   : 'unspecified', 
31      AT_INET     : 'IPv4', 
32      AT_INET6    : 'IPv6', 
33      AT_LINK     : 'MAC', 
34      AT_EUI64    : 'EUI-64', 
35  } 
36   
37  #----------------------------------------------------------------------------- 
38  #   Custom exceptions. 
39  #----------------------------------------------------------------------------- 
40   
41 -class AddrFormatError(Exception):
42 """ 43 An Exception indicating that a network address format is not recognised. 44 """ 45 pass
46
47 -class AddrConversionError(Exception):
48 """ 49 An Exception indicating a failure to convert between address types or 50 notations. 51 """ 52 pass
53 54 #----------------------------------------------------------------------------- 55 # Submodule imports. 56 #----------------------------------------------------------------------------- 57 58 from netaddr.address import nrange, IP, IPRange, IPRangeSet, CIDR, \ 59 Wildcard, EUI 60 61 from netaddr.eui import OUI, IAB, NotRegisteredError 62 63 from netaddr.strategy import ST_IPV4, ST_IPV6, ST_EUI48, ST_EUI64 64 65 #----------------------------------------------------------------------------- 66 # Public interface. 67 #----------------------------------------------------------------------------- 68 __all__ = [ 69 # type constants 70 'AT_INET', 'AT_INET6', 'AT_LINK', 'AT_EUI64', 71 72 # module specific exceptions 73 'AddrFormatError', 'AddrConversionError', 'NotRegisteredError', 74 75 # shared strategy objects 76 'ST_IPV4', 'ST_IPV6', 'ST_EUI48', 'ST_EUI64', 77 78 # main interface classes 79 'CIDR', 'IP', 'IPRange', 'IPRangeSet', 'Wildcard', 80 'EUI', 'OUI', 'IAB', 81 82 # functions 83 'nrange', 84 ] 85