def fromGlobalId(globalId): ''' Takes the "global ID" created by toGlobalID, and retuns the type name and ID used to create it. ''' unbasedGlobalId = unbase64(globalId) _type, _id = unbasedGlobalId.split(':', 1) return ResolvedGlobalId(_type, _id)
def cursorToOffset(cursor): ''' Rederives the offset from the cursor string. ''' try: return int(unbase64(cursor)[len(PREFIX):len(PREFIX)+10]) except: return None
def from_global_id(global_id): ''' Takes the "global ID" created by toGlobalID, and retuns the type name and ID used to create it. ''' unbased_global_id = unbase64(global_id) _type, _id = unbased_global_id.split(':', 1) return _type, _id
def from_global_id(global_id): """return a db int id""" if isinstance(global_id, int) or global_id.isdigit(): return global_id unbased_global_id = unbase64(global_id) _type, _id = unbased_global_id.split(':', 1) return _type, _id
def converts_invalid_base64_to_empty_string(): assert unbase64("") == "" assert unbase64("invalid") == "" assert unbase64(example_base64[-1:]) == "" assert unbase64(example_base64[1:]) == "" assert unbase64("!" + example_base64[1:]) == "" assert unbase64("Ü" + example_base64[1:]) == ""
def from_global_cursor(cursor) -> List[str]: values = unbase64(cursor) return json.loads(values)
def converts_from_base_64_to_unicode(): assert unbase64(example_base64) == example_unicode
def converts_from_base64_as_bytes_to_unicode(): bytes_example_code = example_base64.encode("ascii") assert unbase64(bytes_example_code) == example_unicode # type: ignore bytearray_example_code = bytearray(bytes_example_code) assert unbase64( bytearray_example_code) == example_unicode # type: ignore