Return an Ocean DID from given a hex id.
324815
def id_to_did(did_id, method='op'):
    """"""
    if isinstance(did_id, bytes):
        did_id = Web3.toHex(did_id)

    # remove leading '0x' of a hex string
    if isinstance(did_id, str):
        did_id = remove_0x_prefix(did_id)
    else:
        raise TypeError("did id must be a hex string or bytes")

    # test for zero address
    if Web3.toBytes(hexstr=did_id) == b'':
        did_id = '0'
    return f'did:{method}:{did_id}'
722837
def _get_oid(data, position, dummy0, dummy1, dummy2):
    """"""
    end = position + 12
    return ObjectId(data[position:end]), end
1155599
def get_from_human_key(self, key):
        """"""
        if key in self._identifier_map:
            return self._identifier_map[key]
        raise KeyError(key)
475844
def _dehex(s):
    """"""
    import re
    import binascii

    # Remove all non-hexadecimal digits
    s = re.sub(br'[^a-fA-F\d]', b'', s)
    # binscii.unhexlify works in Python 2 and Python 3 (unlike
    # thing.decode('hex')).
    return binascii.unhexlify(s)
602604
def get_obj(ref):
    """"""
    oid = int(ref)
    return server.id2ref.get(oid) or server.id2obj[oid]
1118521
def from_rep(u):
        """"""
        if isinstance(u, pyversion.string_types):
            return uuid.UUID(u)

        # hack to remove signs
        a = ctypes.c_ulong(u[0])
        b = ctypes.c_ulong(u[1])
        combined = a.value << 64 | b.value
        return uuid.UUID(int=combined)
384604
def hexstr(x, onlyasc=0, onlyhex=0, color=False):
    """"""
    x = bytes_encode(x)
    _sane_func = sane_color if color else sane
    s = []
    if not onlyasc:
        s.append(" ".join("%02X" % orb(b) for b in x))
    if not onlyhex:
        s.append(_sane_func(x))
    return "  ".join(s)
208879
def get_ridx(self, iloc):
        """"""
        with h5py.File(self.source_file, "r") as hdf5:
            return hdf5[self.idx_set["geol"] + "/RuptureIndex"][iloc]
1234702
def from_string(cls, s, space):
        """"""

        import hashlib

        hs = hashlib.sha1(s).hexdigest()

        return cls.from_hex(hs, space)
721005
def _extract_id_from_batch_response(r, name='id'):
        """"""
        names = name + 's'
        if names in r:
            # soon-to-be deprecated batch reponse
            if 'errors' in r and r['errors']:
                raise GeneralException(r['errors'][0]['desc'])
            id = r[names][0]
        else:
            # new-style simplified api response
            id = r[name]
        return int(id)
788024
def aws_to_unix_id(aws_key_id):
    """"""
    uid_bytes = hashlib.sha256(aws_key_id.encode()).digest()[-2:]
    if USING_PYTHON2:
        return 2000 + int(from_bytes(uid_bytes) // 2)
    else:
        return 2000 + (int.from_bytes(uid_bytes, byteorder=sys.byteorder) // 2)
1180031
function makeObjectID() {
    return hexString(8, Date.now() / 1000) +
        hexString(6, machineId) +
        hexString(4, processId) +
        hexString(6, counter++); // a 3-byte counter, starting with a random value.
}
559766
def hexedit(x):
    """"""
    x = bytes(x)
    fname = get_temp_file()
    with open(fname,"wb") as f:
      f.write(x)
    subprocess.call([conf.prog.hexedit, fname])
    with open(fname, "rb") as f:
      x = f.read()
    return x
1371334
def get_environment(id=None, name=None):
    
    data = get_environment_raw(id, name)
    if data:
        return utils.format_json(data)
1082196
def _get_object(data, position, obj_end, opts):
    """"""
    obj_size = _UNPACK_INT(data[position:position + 4])[0]
    end = position + obj_size - 1
    if data[end:position + obj_size] != b"\x00":
        raise InvalidBSON("bad eoo")
    if end >= obj_end:
        raise InvalidBSON("invalid object length")
    obj = _elements_to_dict(data, position + 4, end, opts, subdocument=True)

    position += obj_size
    if "$ref" in obj:
        return (DBRef(obj.pop("$ref"), obj.pop("$id", None),
                      obj.pop("$db", None), obj), position)
    return obj, position
992829
def hexists(self, hashkey, attribute):
        """"""

        redis_hash = self._get_hash(hashkey, 'HEXISTS')
        return self._encode(attribute) in redis_hash
329804
def unhex(inp):
    ''''''
    res = inp.split(r'\x')
    for i in xrange(1, len(res)):
        item = res[i]
        try:
            res[i] = _hextochr[item[:2]] + item[2:]
        except KeyError:
            res[i] = '%' + item
        except UnicodeDecodeError:
            res[i] = unichr(int(item[:2], 16)) + item[2:]
    return ''.join(res)