def unpack_farray_int(self, n): if not self.unpackIntDict.has_key(n): fmt = ">" + "l" * n self.unpackIntDict[n] = Struct(fmt).unpack i = self.__pos self.__pos = j = i + 4 * n return self.unpackIntDict[n](self.__buf[i:j])
def unpack_farray_double(self, n): if not self.unpackDoubleDict.has_key(n): fmt = ">" + "d" * n self.unpackDoubleDict[n] = Struct(fmt).unpack i = self.__pos self.__pos = j = i + 8 * n return self.unpackDoubleDict[n](self.__buf[i:j])
def _compile(fmt): # Internal: compile struct pattern if len(_cache) >= _MAXCACHE: _cache.clear() s = Struct(fmt) _cache[fmt] = s return s
def py_djb_hash(s): '''Return the value of DJB's hash function for the given 8-bit string.''' h = 5381 for c in s: h = (((h << 5) + h) ^ ord(c)) & 0xffffffff return h try: from _cdblib import djb_hash except ImportError: djb_hash = py_djb_hash read_2_le4 = Struct('<LL').unpack write_2_le4 = Struct('<LL').pack class Reader(object): '''A dictionary-like object for reading a Constant Database accessed through a string or string-like sequence, such as mmap.mmap().''' def __init__(self, data, hashfn=djb_hash): '''Create an instance reading from a sequence and using hashfn to hash keys.''' if len(data) < 2048: raise IOError('CDB too small') self.data = data self.hashfn = hashfn
5381 >>> py_djb_hash('\x01') 177572 >>> py_djb_hash('€') 193278953 """ h = 5381 for c in s.encode('UTF-8'): h = (((h << 5) + h) ^ c) & 0xffffffff return h # 2014-03-04 bd808: removed try block for importing C hash implementation DJB_HASH = py_djb_hash READ_2_LE4 = Struct('<LL').unpack WRITE_2_LE4 = Struct('<LL').pack class Reader(object): """ A dictionary-like object for reading a Constant Database. Reader accesses through a string or string-like sequence such as mmap.mmap(). """ def __init__(self, data, hashfn=DJB_HASH): """ Create an instance reading from a sequence and hash keys using hashfn. >>> Reader(data=b'')
from _struct import Struct, unpack_from, pack import numpy as np import lib.geo as geo from enum import Enum # UNPACKERS UINT8 = Struct('<B').unpack_from UINT16 = Struct('<H').unpack_from UINT16_2D = Struct('<HH').unpack_from SINT16 = Struct('<h').unpack_from UINT32 = Struct('<L').unpack_from SINT32 = Struct('<l').unpack_from FLOAT32 = Struct('<f').unpack_from FLOAT32_2D = Struct('<ff').unpack_from FLOAT32_3D = Struct('<fff').unpack_from RGBA = Struct('<ffff').unpack_from FLOAT64 = Struct('<d').unpack_from FLOAT64_2D = Struct('<dd').unpack_from FLOAT64_3D = Struct('<ddd').unpack_from DATETIME = Struct('<Q').unpack_from def getEntityRef(data, offset): index, i = getSInt32(data, offset) return index, i def getTagChar(data, index): return data[index], index + 1