Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from sqlalchemy.orm import sessionmaker
db = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=db)
TableModel = TTableModel(MetaData(bind=db))
class User(TableModel):
__tablename__ = 'spyne_user'
# This is only needed for sqlite
__table_args__ = {"sqlite_autoincrement": True}
id = UnsignedInteger32(pk=True)
user_name = Unicode(32, min_len=4, pattern='[a-z0-9.]+')
full_name = Unicode(64, pattern='\w+( \w+)+')
email = Unicode(64, pattern=r'[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}')
_uuid_validate = {
None: _uuid_validate_string,
'hex': _Tuuid_validate('hex'),
'urn': _Tuuid_validate('urn'),
six.binary_type: _Tuuid_validate('bytes'),
'bytes': _Tuuid_validate('bytes'),
'bytes_le': _Tuuid_validate('bytes_le'),
'fields': _Tuuid_validate('fields'),
int: _Tuuid_validate('int'),
'int': _Tuuid_validate('int'),
}
class Uuid(Unicode(pattern=UUID_PATTERN)):
"""Unicode subclass for Universially-Unique Identifiers."""
__namespace__ = 'http://spyne.io/schema'
__type_name__ = 'uuid'
Value = uuid.UUID
class Attributes(Unicode(pattern=UUID_PATTERN).Attributes):
serialize_as = None
@staticmethod
def validate_string(cls, value):
return _uuid_validate[cls.Attributes.serialize_as](cls, value)
@staticmethod
def validate_native(cls, value):
return SimpleModel.validate_native(cls, value)
# Copyright (c) 2015 Torben Hohn
# Copyright (c) 2016-2017 Manuel Traut
#
# SPDX-License-Identifier: GPL-3.0-or-later
from spyne.model.complex import ComplexModel
from spyne.model.primitive import Unicode, DateTime, Integer
class SoapProject (ComplexModel):
__namespace__ = 'soap'
builddir = Unicode()
name = Unicode()
version = Unicode()
status = Unicode()
edit = DateTime()
def __init__(self, prj):
self.builddir = prj.builddir
self.name = prj.name
self.version = prj.version
self.status = prj.status
self.edit = prj.edit
class SoapFile (ComplexModel):
__namespace__ = 'soap'
name = Unicode()
description = Unicode()
from spyne.model.primitive import UnsignedInteger32
from spyne.model.complex import Array
from spyne.model.complex import Iterable
from spyne.model.complex import ComplexModel
from spyne.server.wsgi import WsgiApplication
from spyne.service import ServiceBase
_user_database = {}
_user_id_seq = 0
class Permission(ComplexModel):
__namespace__ = 'spyne.examples.user_manager'
id = UnsignedInteger32
application = Unicode(values=('usermgr', 'accountmgr'))
operation = Unicode(values=('read', 'modify', 'delete'))
class User(ComplexModel):
__namespace__ = 'spyne.examples.user_manager'
id = UnsignedInteger32
user_name = Unicode(32, min_len=4, pattern='[a-z0-9.]+')
full_name = Unicode(64, pattern='\w+( \w+)+')
email = Unicode(pattern=r'[a-z0-9._%+-]+@[a-z0-9.-]+\.[A-Z]{2,4}')
permissions = Array(Permission)
class UserManagerService(ServiceBase):
@rpc(User.customize(min_occurs=1, nullable=False), _returns=UnsignedInteger32)
def put_user(ctx, user):
class SchemaBase(ComplexModelBase):
__namespace__ = xml.NS_XSD
class Import(SchemaBase):
namespace = XmlAttribute(Unicode)
class Element(SchemaBase):
name = XmlAttribute(Unicode)
type = XmlAttribute(Unicode)
ref = XmlAttribute(Unicode)
# it can be "unbounded", so it should be of type Unicode
max_occurs = XmlAttribute(Unicode(default="1", sub_name="maxOccurs"))
# Also Unicode for consistency with max_occurs
min_occurs = XmlAttribute(Unicode(default="1", sub_name="minOccurs"))
nillable = XmlAttribute(Boolean(default=False))
default = XmlAttribute(Unicode)
class IntegerAttribute(SchemaBase):
value = XmlAttribute(UnsignedInteger)
class StringAttribute(SchemaBase):
value = XmlAttribute(Unicode)
class List(SchemaBase):
_type_info = [
('item_type', XmlAttribute(Unicode(sub_name='itemType'))),
]
@srpc(Unicode,Unicode,Unicode, _returns=Unicode)
def connectionError( ticket, hresult, message ):
""" used by web connector to report errors connecting to Quickbooks
@param ticket session token sent from this service to web connector
@param hresult The HRESULT (in HEX) from the exception
@param message error message
@return string done indicating web service is finished.
"""
# need to push this error to the client. Should there be a message channel on Redis for this?
logging.debug('connectionError %s %s %s', ticket, hresult, message)
return "done"
__namespace__ = 'spyne.examples.user_manager'
__table_args__ = {"sqlite_autoincrement": True}
id = UnsignedInteger32(pk=True)
application = Unicode(values=('usermgr', 'accountmgr'))
operation = Unicode(values=('read', 'modify', 'delete'))
class User(TableModel):
__tablename__ = 'user'
__namespace__ = 'spyne.examples.user_manager'
__table_args__ = {"sqlite_autoincrement": True}
id = UnsignedInteger32(pk=True)
email = Unicode(64, pattern=r'[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}')
user_name = Unicode(32, min_len=4, pattern='[a-z0-9.]+')
full_name = Unicode(64, pattern='\w+( \w+)+')
permissions = Array(Permission).store_as('table')
class UserManagerService(Service):
@rpc(Mandatory.UnsignedInteger32, _returns=User)
def get_user(ctx, user_id):
return ctx.udc.session.query(User).filter_by(id=user_id).one()
@rpc(User, _returns=UnsignedInteger32)
def put_user(ctx, user):
if user.id is None:
ctx.udc.session.add(user)
ctx.udc.session.flush() # so that we get the user.id value
else:
class Permission(ComplexModel):
__namespace__ = 'spyne.examples.user_manager'
id = UnsignedInteger32
application = Unicode(values=('usermgr', 'accountmgr'))
operation = Unicode(values=('read', 'modify', 'delete'))
class User(ComplexModel):
__namespace__ = 'spyne.examples.user_manager'
id = UnsignedInteger32
user_name = Unicode(32, min_len=4, pattern='[a-z0-9.]+')
full_name = Unicode(64, pattern='\w+( \w+)+')
email = Unicode(pattern=r'[a-z0-9._%+-]+@[a-z0-9.-]+\.[A-Z]{2,4}')
permissions = Array(Permission)
class UserManagerService(ServiceBase):
@rpc(User.customize(min_occurs=1, nullable=False), _returns=UnsignedInteger32)
def put_user(ctx, user):
if user.id is None:
user.id = ctx.udc.get_next_user_id()
ctx.udc.users[user.id] = user
return user.id
@rpc(Mandatory.UnsignedInteger32, _returns=User)
def get_user(ctx, user_id):
return ctx.udc.users[user_id]