Esempio n. 1
0
 def __init__(self, data):
     """
     Sets `vendor_class` data.
     
     :param dict data: A dictionary of data-strings keyed by ID-ints.
     """
     self._value = []
     for (enterprise_number, payload) in sorted(data.items()):
         self._value += longToList(enterprise_number)
         self._value.append(chr(len(payload)))
         self._value += payload
Esempio n. 2
0
 def __init__(self, data):
     """
     Sets `vendor_class` data.
     
     :param dict data: A dictionary of data-strings keyed by ID-ints.
     """
     self._value = []
     for (enterprise_number, payload) in sorted(data.items()):
         self._value += longToList(enterprise_number)
         self._value.append(chr(len(payload)))
         self._value += payload
Esempio n. 3
0
    def __init__(self, address):
        """
        Constructs an IPv4 abstraction from a concrete representation.
        
        :param address: An IPv4, which may be a dotted quad, a quadruple of
                        bytes, or a 32-bit, unsigned integer.
        :except ValueError: The address could not be processed.
        """
        if isinstance(address, IntegerTypes):
            if not 0 <= address <= _MAX_IP_INT:
                raise ValueError(
                    "'%(ip)i' is not a valid IP: not a 32-bit unsigned integer"
                    % {
                        'ip': address,
                    })
            self._ip = int(address)
            self._ip_tuple = tuple(longToList(self._ip))
        else:
            if isinstance(address, StringTypes):
                octets = (i.strip() for i in address.split('.'))
            else:
                octets = address

            try:
                octets = [int(i) for i in octets][:4]
            except Exception:
                raise ValueError(
                    "%(ip)r is not a valid IPv4: non-integer data supplied" % {
                        'ip': address,
                    })
            else:
                if len(octets) < 4:
                    raise ValueError("%(ip)r is not a valid IPv4: length < 4" %
                                     {
                                         'ip': address,
                                     })

                if any(True for i in octets if i < 0 or i > 255):
                    raise ValueError(
                        "%(ip)r is not a valid IPv4: non-byte values present" %
                        {
                            'ip': address,
                        })

                self._ip_tuple = tuple(octets)
Esempio n. 4
0
 def __init__(self, isns_functions, dd_access, admin_flags, isns_security, ips):
     """
     Sets iSNS configuration parameters.
     
     :param int isns_functions: A sixteen-bit value.
     :param int dd_access: A sixteen-bit value.
     :param int admin_flags: A sixteen-bit value.
     :param int isns_security: A thirty-two-bit value.
     :param str ips: Comma-delimited IPv4s to be processed.
     """
     isns_functions = intToList(isns_functions)
     dd_access = intToList(dd_access)
     admin_flags = intToList(admin_flags)
     isns_security = longToList(isns_security)
     
     self._value = isns_functions + dd_access + admin_flags + isns_security
     for token in [tok for tok in [t.strip() for t in ips.split(',')] if tok]:
         self._value.extend(IPv4(token))
Esempio n. 5
0
 def __init__(self, isns_functions, dd_access, admin_flags, isns_security, ips):
     """
     Sets iSNS configuration parameters.
     
     :param int isns_functions: A sixteen-bit value.
     :param int dd_access: A sixteen-bit value.
     :param int admin_flags: A sixteen-bit value.
     :param int isns_security: A thirty-two-bit value.
     :param str ips: Comma-delimited IPv4s to be processed.
     """
     isns_functions = intToList(isns_functions)
     dd_access = intToList(dd_access)
     admin_flags = intToList(admin_flags)
     isns_security = longToList(isns_security)
     
     self._value = isns_functions + dd_access + admin_flags + isns_security
     for token in [tok for tok in [t.strip() for t in ips.split(',')] if tok]:
         self._value.extend(IPv4(token))
Esempio n. 6
0
 def __init__(self, data):
     """
     Sets `vendor_specific` data.
     
     :param dict data: A dictionary of dictionaries of data-strings, keyed
         by ID-ints at both levels.
     """
     self._value = []
     for (enterprise_number, payload) in sorted(data.items()):
         self._value += longToList(enterprise_number)
         
         subdata = []
         for (subopt_code, subpayload) in sorted(payload.items()):
             subdata.append(chr(subopt_code))
             subdata.append(chr(len(subpayload)))
             subdata += subpayload
             
         self._value.append(chr(len(subdata)))
         self._value += subdata
Esempio n. 7
0
 def __init__(self, data):
     """
     Sets `vendor_specific` data.
     
     :param dict data: A dictionary of dictionaries of data-strings, keyed
         by ID-ints at both levels.
     """
     self._value = []
     for (enterprise_number, payload) in sorted(data.items()):
         self._value += longToList(enterprise_number)
         
         subdata = []
         for (subopt_code, subpayload) in sorted(payload.items()):
             subdata.append(chr(subopt_code))
             subdata.append(chr(len(subpayload)))
             subdata += subpayload
             
         self._value.append(chr(len(subdata)))
         self._value += subdata
Esempio n. 8
0
 def __init__(self, address):
     """
     Constructs an IPv4 abstraction from a concrete representation.
     
     :param address: An IPv4, which may be a dotted quad, a quadruple of
                     bytes, or a 32-bit, unsigned integer.
     :except ValueError: The address could not be processed.
     """
     if isinstance(address, IntegerTypes):
         if not 0 <= address <= 4294967295:
             raise ValueError("'%(ip)i' is not a valid IP: not a 32-bit unsigned integer" % {
              'ip': address,
             })
         self._ip = int(address)
         self._ip_tuple = tuple(longToList(self._ip))
     else:
         if isinstance(address, StringTypes):
             octets = (i.strip() for i in address.split('.'))
         else:
             octets = address
             
         try:
             octets = [int(i) for i in octets][:4]
         except Exception:
             raise ValueError("%(ip)r is not a valid IPv4: non-integer data supplied" % {
              'ip': address,
             })
         else:
             if len(octets) < 4:
                 raise ValueError("%(ip)r is not a valid IPv4: length < 4" % {
                  'ip': address,
                 })
                 
             if any(True for i in octets if i < 0 or i > 255):
                 raise ValueError("%(ip)r is not a valid IPv4: non-byte values present" % {
                  'ip': address,
                 })
                 
             self._ip_tuple = tuple(octets)