Package netaddr
[hide private]
[frames] | no frames]

Source Code for Package netaddr

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