Beispiel #1
0
    TTableModel, Service, ResourceNotFoundError, UnsignedInteger32

from spyne.protocol.http import HttpRpc
from spyne.protocol.yaml import YamlDocument

from spyne.util import memoize

from spyne.server.wsgi import WsgiApplication

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker


db = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=db)
TableModel = TTableModel()
TableModel.Attributes.sqla_metadata.bind = db


class Permission(TableModel):
    __tablename__ = 'permission'
    __namespace__ = 'spyne.examples.sql_crud'
    __table_args__ = {"sqlite_autoincrement": True}

    id = UnsignedInteger32(primary_key=True)
    application = Unicode(256)
    operation = Unicode(256)


class User(TableModel):
    __tablename__ = 'user'
Beispiel #2
0
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

from contextlib import closing

from spyne import TTableModel, Integer32
from spyne.store.relational import get_pk_columns

TableModel = TTableModel()


def TVersion(prefix, default_version):
    class Version(TableModel):
        __tablename__ = '%s_version' % prefix

        id = Integer32(pk=True)
        version = Integer32(default=default_version)

    return Version


def respawn(cls, ctx=None):
    has_db = ctx.app is not None and 'sql_main' in ctx.app.config.stores
Beispiel #3
0
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

from contextlib import closing

from spyne import TTableModel
from spyne.util.sqlalchemy import get_pk_columns

TableModel = TTableModel()


def respawn(cls, ctx=None):
    has_db = ctx.app is not None and 'sql_main' in ctx.app.config.stores

    if ctx is not None and ctx.in_object is not None and len(ctx.in_object) > 0 \
                       and ctx.in_object[0] is not None and has_db:
        in_object = ctx.in_object[0]

        filters = {}
        for k, v in get_pk_columns(cls):
            filters[k] = getattr(in_object, k)

        db = ctx.app.config.stores['sql_main'].itself
        with closing(db.Session()) as session:
Beispiel #4
0
from sqlalchemy.orm import sessionmaker

from spyne import MethodContext, Application, rpc, TTableModel, Integer32, \
    UnsignedInteger, ByteArray, Mandatory as M

# client stuff
from spyne import RemoteService, RemoteProcedureBase, ClientBase

# server stuff
from spyne import ServerBase, ServiceBase

from spyne.protocol.soap import Soap11


db = create_engine('sqlite:///:memory:')
TableModel = TTableModel(MetaData(bind=db))


#
# The database tables used to store tasks and worker status
#


class TaskQueue(TableModel):
    __tablename__ = 'task_queue'

    id = Integer32(primary_key=True)
    data = ByteArray(nullable=False)


class WorkerStatus(TableModel):