Ejemplo n.º 1
0
def repr_to_oid(repr):
    repr = ascii_bytes(repr)
    if repr.startswith(b"0x"):
        repr = repr[2:]
    as_bin = unhexlify(repr)
    as_bin = b"\x00"*(8-len(as_bin)) + as_bin
    return as_bin
Ejemplo n.º 2
0
 def path_to_oid(self, path):
     if self.blob_path_pattern.match(path) is None:
         raise ValueError("Not a valid OID path: `%s`" % path)
     path = [ascii_bytes(x) for x in path.split(os.path.sep)]
     # Each path segment stores a byte in hex representation. Turn it into
     # an int and then get the character for our byte string.
     oid = b''.join(binascii.unhexlify(byte[2:]) for byte in path)
     return oid
Ejemplo n.º 3
0
Archivo: blob.py Proyecto: axiros/ZODB
 def path_to_oid(self, path):
     if self.blob_path_pattern.match(path) is None:
         raise ValueError("Not a valid OID path: `%s`" % path)
     path = [ascii_bytes(x) for x in path.split(os.path.sep)]
     # Each path segment stores a byte in hex representation. Turn it into
     # an int and then get the character for our byte string.
     oid = b''.join(binascii.unhexlify(byte[2:]) for byte in path)
     return oid
Ejemplo n.º 4
0
    def oid_to_path(self, oid):
        directories = []
        # Create the bushy directory structure with the least significant byte
        # first
        for byte in ascii_bytes(oid):
            if isinstance(byte,INT_TYPES): # Py3k iterates byte strings as ints
                hex_segment_bytes = b'0x' + binascii.hexlify(bytes([byte]))
                hex_segment_string = hex_segment_bytes.decode('ascii')
            else:
                hex_segment_string = '0x%s' % binascii.hexlify(byte)
            directories.append(hex_segment_string)

        return os.path.sep.join(directories)
Ejemplo n.º 5
0
    def oid_to_path(self, oid):
        # Create the bushy directory structure with the least significant byte
        # first
        oid_bytes = ascii_bytes(oid)
        hex_bytes = binascii.hexlify(oid_bytes)
        assert len(hex_bytes) == 16

        directories = [b'0x' + hex_bytes[x:x + 2] for x in range(0, 16, 2)]

        if bytes is not str:  # py3
            sep_bytes = os.path.sep.encode('ascii')
            path_bytes = sep_bytes.join(directories)
            return path_bytes.decode('ascii')
        else:
            return os.path.sep.join(directories)
Ejemplo n.º 6
0
Archivo: blob.py Proyecto: navytux/ZODB
    def oid_to_path(self, oid):
        # Create the bushy directory structure with the least significant byte
        # first
        oid_bytes = ascii_bytes(oid)
        hex_bytes = binascii.hexlify(oid_bytes)
        assert len(hex_bytes) == 16

        directories = [b'0x' + hex_bytes[x:x+2]
                       for x in range(0, 16, 2)]

        if bytes is not str: # py3
            sep_bytes = os.path.sep.encode('ascii')
            path_bytes = sep_bytes.join(directories)
            return path_bytes.decode('ascii')
        else:
            return os.path.sep.join(directories)