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.4' 
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_DESCR = { 
29      AT_UNSPEC : 'unspecified', 
30      AT_LINK   : 'MAC', 
31      AT_EUI64  : 'EUI-64', 
32      AT_INET   : 'IPv4', 
33      AT_INET6  : 'IPv6', 
34  } 
35   
36  #----------------------------------------------------------------------------- 
37  #   Custom exceptions. 
38  #----------------------------------------------------------------------------- 
39   
40 -class AddrFormatError(Exception):
41 """ 42 Network address format not recognised. 43 """ 44 pass
45
46 -class AddrConversionError(Exception):
47 """ 48 Conversion between address types or notations failed. 49 """ 50 pass
51 52 #----------------------------------------------------------------------------- 53 # Public interface and exports. 54 #----------------------------------------------------------------------------- 55 56 from netaddr.address import Addr, AddrRange, nrange, AddrFormatError, \ 57 AddrConversionError, IP, CIDR, Wildcard, EUI 58 59 from netaddr.strategy import ST_IPV4, ST_IPV6, ST_EUI48, ST_EUI64 60 61 __all__ = [ 62 'Addr', 'AddrRange', 'nrange', # generic functionality 63 'AddrFormatError', 'AddrConversionError', # custom exceptions 64 'IP', 'CIDR', 'Wildcard', 'EUI', # general purpose classes 65 'ST_IPV4', 'ST_IPV6', 'ST_EUI48', 'ST_EUI64', # shared strategy objects 66 'AT_INET', 'AT_INET6', 'AT_LINK', 'AT_EUI64', # type constants 67 ] 68