def from_decimal(decimal): if decimal.HasField("u_int_32"): return int(decimal.u_int_32) elif decimal.HasField("s_int_32"): return int(decimal.s_int_32) elif decimal.HasField("u_int_64"): return int(decimal.u_int_64) elif decimal.HasField("s_int_64"): return int(decimal.s_int_64) elif decimal.HasField("floating"): return float(decimal.floating) elif decimal.HasField("string_sequence"): raise MishmashNotImplementedYetException("string_sequence not implemented yet") elif decimal.HasField("big_decimal"): raise MishmashNotImplementedYetException("big_decimal not implemented yet") else: raise MishmashNotImplementedYetException("wrong decimal value")
def __getitem__(self, name): new_mishmash = self.__intersection(name) if self.is_async: raise MishmashNotImplementedYetException( "not implemented async __getitem__ logic") return new_mishmash
def to_value(arg): if isinstance(arg, int): return mishmash_rpc_pb2.Value(decimal=to_decimal(arg)) elif isinstance(arg, bool): return mishmash_rpc_pb2.Value(boolean=mishmash_rpc_pb2.BooleanValue(boolean=arg)) elif arg is None: return mishmash_rpc_pb2.Value(null=mishmash_rpc_pb2.NullValue()) elif isinstance(arg, float): return mishmash_rpc_pb2.Value(decimal=to_decimal(arg)) elif isinstance(arg, str): return mishmash_rpc_pb2.Value(string=mishmash_rpc_pb2.StringValue(sequence=arg)) elif utils.isinstance_datetime(arg): return mishmash_rpc_pb2.Value(date=mishmash_rpc_pb2.DateValue(iso8601=arg.isoformat())) else: raise MishmashNotImplementedYetException(f"value with type {type(arg)} is not implemented yet")
def from_value(value): if value.HasField("boolean"): return from_boolean(value.boolean) elif value.HasField("decimal"): return from_decimal(value.decimal) elif value.HasField("string"): return from_string(value.string) elif value.HasField("date"): return datetime.strptime(value.date.iso8601, "%Y-%m-%dT%H:%M:%SZ") elif value.HasField("buffer"): raise MishmashNotImplementedYetException("get buffer not implemented yet") elif value.HasField("null"): return None else: raise MishmashInvalidMessageException( "wrong value = {} with type = {}".format(value, type(value)))
def __union_lambda(self, v): raise MishmashNotImplementedYetException( "union with lambda function are not implemented yet")
def __union_memoryview(self, v): raise MishmashNotImplementedYetException( "union with memoryview object are not implemented yet")
def __union_slice(self, v): raise MishmashNotImplementedYetException( "union with slice are not implemented yet")
def __union_namedtuple(self, v): raise MishmashNotImplementedYetException( "union with namedtuple are not implemented yet")
def __union_bytes(self, v): raise MishmashNotImplementedYetException( "union with bytes object are not implemented yet")
def __intersect_generator(self, v): raise MishmashNotImplementedYetException("intersect with generator")
def __intersect_namedtuple(self, v): raise MishmashNotImplementedYetException("intersect with namedtuple")
def __intersect_memoryview(self, v): raise MishmashNotImplementedYetException("intersect with memoryview")
def __intersect_bytearray(self, v): raise MishmashNotImplementedYetException("intersect with bytearray")
def __intersect_slice(self, v): raise MishmashNotImplementedYetException("intersection with slice")
def __intersect_range(self, v): raise MishmashNotImplementedYetException("intersection with range")
def __union_generator(self, v): raise MishmashNotImplementedYetException( "union with generator are not implemented yet")
def __union_method(self, v): raise MishmashNotImplementedYetException( "union with method are not implemented yet")
def __intersect_method(self, v): raise MishmashNotImplementedYetException("intersect with method")
async def __anext__(self): raise MishmashNotImplementedYetException("__anext__ not implemented next")
def __intersect_lambda(self, v): raise MishmashNotImplementedYetException("intersect with lambda")
def __xor__(self, y): raise MishmashNotImplementedYetException( " xor logic not implemented yet")
def __union_complex(self, v): raise MishmashNotImplementedYetException( "complex number are not implemented yet")