class SomeService(Service): @srpc(Decimal(120,4), _returns=Decimal) def some_call(p): print(p) print(type(p)) assert type(p) == decimal.Decimal assert d == p return p
def _get_spyne_type(v): """This function maps sqlalchemy types to spyne types.""" rpc_type = None if isinstance(v.type, sqlalchemy.Enum): if v.type.convert_unicode: rpc_type = Unicode(values=v.type.enums) else: rpc_type = Enum(*v.type.enums, **{'type_name': v.type.name}) elif isinstance(v.type, sqlalchemy.Unicode): rpc_type = Unicode(v.type.length) elif isinstance(v.type, sqlalchemy.UnicodeText): rpc_type = Unicode elif isinstance(v.type, sqlalchemy.Text): rpc_type = String elif isinstance(v.type, sqlalchemy.String): rpc_type = String(v.type.length) elif isinstance(v.type, (sqlalchemy.Numeric)): rpc_type = Decimal(v.type.precision, v.type.scale) elif isinstance(v.type, PGXml): rpc_type = AnyXml elif isinstance(v.type, PGHtml): rpc_type = AnyHtml elif type(v.type) in _sq2sp_type_map: rpc_type = _sq2sp_type_map[type(v.type)] elif isinstance(v.type, (PGObjectJson, PGObjectXml)): rpc_type = v.type.cls elif isinstance(v.type, PGFileJson): rpc_type = v.FileData else: raise Exception("Spyne type was not found. Probably _sq2sp_type_map " "needs a new entry. %r" % v) return rpc_type
def _get_spyne_type(v): """Map sqlalchemy types to spyne types.""" if isinstance(v.type, sqlalchemy.Enum): if v.type.convert_unicode: return Unicode(values=v.type.enums) else: return Enum(*v.type.enums, **{'type_name': v.type.name}) if isinstance(v.type, (sqlalchemy.UnicodeText, sqlalchemy.Text)): return Unicode if isinstance(v.type, (sqlalchemy.Unicode, sqlalchemy.String, sqlalchemy.VARCHAR)): return Unicode(v.type.length) if isinstance(v.type, sqlalchemy.Numeric): return Decimal(v.type.precision, v.type.scale) if isinstance(v.type, PGXml): return AnyXml if isinstance(v.type, PGHtml): return AnyHtml if type(v.type) in _sq2sp_type_map: return _sq2sp_type_map[type(v.type)] if isinstance(v.type, (PGObjectJson, PGObjectXml)): return v.type.cls if isinstance(v.type, PGFileJson): return v.FileData raise Exception("Spyne type was not found. Probably _sq2sp_type_map " "needs a new entry. %r" % v)
def _get_spyne_type(v): """Map sqlalchemy types to spyne types.""" cust = {} if v.primary_key: cust['primary_key'] = True if not v.nullable: cust['nullable'] = False cust['min_occurs'] = 1 if isinstance(v.type, sqlalchemy.Enum): if v.type.convert_unicode: return Unicode(values=v.type.enums, **cust) else: cust['type_name'] = v.type.name return Enum(*v.type.enums, **cust) if isinstance(v.type, (sqlalchemy.UnicodeText, sqlalchemy.Text)): return Unicode(**cust) if isinstance(v.type, (sqlalchemy.Unicode, sqlalchemy.String, sqlalchemy.VARCHAR)): return Unicode(v.type.length, **cust) if isinstance(v.type, sqlalchemy.Numeric): return Decimal(v.type.precision, v.type.scale, **cust) if isinstance(v.type, PGXml): if len(cust) > 0: return AnyXml(**cust) else: return AnyXml if isinstance(v.type, PGHtml): if len(cust) > 0: return AnyHtml(**cust) else: return AnyHtml if type(v.type) in _sq2sp_type_map: retval = _sq2sp_type_map[type(v.type)] if len(cust) > 0: return retval.customize(**cust) else: return retval if isinstance(v.type, (PGObjectJson, PGObjectXml)): retval = v.type.cls if len(cust) > 0: return retval.customize(**cust) else: return retval if isinstance(v.type, PGFileJson): retval = v.FileData if len(cust) > 0: return v.FileData.customize(**cust) else: return retval raise Exception("Spyne type was not found. Probably _sq2sp_type_map " "needs a new entry. %r" % v)