├── spyne
├── test
│ ├── util
│ │ └── __init__.py
│ ├── interface
│ │ ├── __init__.py
│ │ └── wsdl
│ │ │ └── defult_services.py
│ ├── interop
│ │ ├── __init__.py
│ │ ├── server
│ │ │ ├── soap11
│ │ │ │ ├── __init__.py
│ │ │ │ ├── soap_zeromq.py
│ │ │ │ ├── soap_http_basic_twisted.py
│ │ │ │ ├── httprpc_soap_basic.py
│ │ │ │ ├── soap_http_static.py
│ │ │ │ └── soap_http_basic.py
│ │ │ ├── soap12
│ │ │ │ ├── __init__.py
│ │ │ │ ├── soap_zeromq.py
│ │ │ │ ├── soap_http_basic_twisted.py
│ │ │ │ ├── httprpc_soap_basic.py
│ │ │ │ ├── soap_http_basic.py
│ │ │ │ └── soap_http_static.py
│ │ │ ├── __init__.py
│ │ │ ├── httprpc_csv_basic.py
│ │ │ ├── httprpc_pod_basic_twisted.py
│ │ │ ├── httprpc_pod_basic.py
│ │ │ └── msgpackrpc_http_basic.py
│ │ ├── test_rpc.rb
│ │ ├── test_soap_client_http.py
│ │ ├── test_soap_client_zeromq.py
│ │ ├── test_msgpackrpc_client_http.py
│ │ └── test_soap_client_http_twisted.py
│ ├── transport
│ │ └── __init__.py
│ ├── multipython
│ │ ├── __init__.py
│ │ └── model
│ │ │ └── __init__.py
│ ├── model
│ │ ├── __init__.py
│ │ └── test_binary.py
│ ├── regen_wsdl.py
│ ├── protocol
│ │ ├── __init__.py
│ │ └── test_yaml.py
│ └── __init__.py
├── protocol
│ ├── html
│ │ ├── table
│ │ │ └── __init__.py
│ │ ├── __init__.py
│ │ └── addtl.py
│ ├── cloth
│ │ └── __init__.py
│ ├── soap
│ │ └── __init__.py
│ └── __init__.py
├── store
│ ├── __init__.py
│ └── relational
│ │ ├── __init__.py
│ │ └── override.py
├── server
│ ├── __init__.py
│ ├── twisted
│ │ ├── __init__.py
│ │ └── _base.py
│ └── pyramid.py
├── interface
│ ├── wsdl
│ │ └── __init__.py
│ ├── xml_schema
│ │ └── __init__.py
│ └── __init__.py
├── client
│ ├── __init__.py
│ ├── zeromq.py
│ └── http.py
├── auxproc
│ ├── sync.py
│ ├── __init__.py
│ └── thread.py
├── util
│ ├── protocol.py
│ ├── _base.py
│ ├── cherry.py
│ ├── toposort.py
│ ├── resource.py
│ ├── simple.py
│ └── cdict.py
├── model
│ ├── relational.py
│ └── __init__.py
├── _base.py
└── const
│ ├── xml_ns.py
│ └── ansi_color.py
├── examples
├── django
│ ├── rpctest
│ │ ├── core
│ │ │ ├── __init__.py
│ │ │ ├── tests.py
│ │ │ └── models.py
│ │ ├── __init__.py
│ │ └── urls.py
│ └── manage.py
├── template
│ ├── .gitignore
│ ├── template
│ │ ├── test
│ │ │ ├── __init__.py
│ │ │ └── test_sample.py
│ │ ├── entity
│ │ │ └── __init__.py
│ │ ├── __init__.py
│ │ ├── service.py
│ │ ├── context.py
│ │ └── db.py
│ └── README.rst
├── xml
│ ├── validation_error
│ │ ├── some_file
│ │ ├── validation_internal_error.sh
│ │ ├── README
│ │ ├── inst.xml
│ │ ├── validation_internal_error.py
│ │ ├── py_output
│ │ ├── sh_output
│ │ └── schema.xsd
│ ├── soap12-mtom
│ │ ├── .gitignore
│ │ ├── request.txt
│ │ ├── request.sh
│ │ └── soap12_mtom.py
│ ├── Makefile
│ ├── utils_poly.py
│ ├── polymorphic_roundtrip.py
│ └── polymorphism_soap_server.py
├── tfb
│ ├── spyne.dockerfile
│ ├── spyne-raw.dockerfile
│ ├── gunicorn_conf.py
│ ├── cloths
│ │ └── index.html
│ ├── requirements.txt
│ ├── spyne-nginx-uwsgi.dockerfile
│ ├── uwsgi.ini
│ ├── README.md
│ ├── tfb.yaml
│ ├── nginx.conf
│ └── benchmark_config.json
├── file_manager
│ ├── static
│ │ ├── index.html
│ │ └── simple
│ │ │ └── index.html
│ └── suds_client.py
├── multiple_protocols
│ └── presentation
│ │ └── Makefile
├── flask
│ ├── README.rst
│ ├── apps
│ │ ├── __init__.py
│ │ └── flasked.py
│ ├── settings.py
│ └── manage.py
├── twisted
│ └── codegen.py
├── log.py
├── zeromq
│ ├── client.py
│ ├── server.py
│ └── app.py
├── helloworld_soap_suds_client.py
├── testing
│ └── helloworld_null.py
├── authentication
│ ├── http_cookie
│ │ └── client_suds.py
│ └── client_suds.py
├── dict_skip.py
├── user_manager
│ ├── spyne_client.py
│ └── suds_client.py
└── validation.py
├── .coveragerc
├── pytest.ini
├── doc
├── source
│ ├── tests.rst
│ ├── contributing.rst
│ ├── .static
│ │ └── placeholder.txt
│ ├── .templates
│ │ └── placeholder.txt
│ ├── reference
│ │ ├── model
│ │ │ ├── enum.rst
│ │ │ ├── fault.rst
│ │ │ ├── primitive.rst
│ │ │ ├── sql.rst
│ │ │ ├── binary.rst
│ │ │ ├── complex.rst
│ │ │ └── index.rst
│ │ ├── error.rst
│ │ ├── decorator.rst
│ │ ├── service.rst
│ │ ├── protocol
│ │ │ ├── json.rst
│ │ │ ├── xml.rst
│ │ │ ├── http.rst
│ │ │ ├── msgpack.rst
│ │ │ ├── base.rst
│ │ │ ├── dictdoc.rst
│ │ │ ├── soap.rst
│ │ │ └── index.rst
│ │ ├── server
│ │ │ ├── null.rst
│ │ │ ├── wsgi.rst
│ │ │ ├── zeromq.rst
│ │ │ ├── pyramid.rst
│ │ │ ├── django.rst
│ │ │ ├── index.rst
│ │ │ └── twisted.rst
│ │ ├── application.rst
│ │ ├── index.rst
│ │ ├── client.rst
│ │ ├── base.rst
│ │ ├── auxproc.rst
│ │ ├── interface.rst
│ │ └── util.rst
│ ├── manual
│ │ ├── relational.rst
│ │ └── index.rst
│ └── index.rst
└── gendoc.sh
├── requirements
├── test_django_req.txt
├── test_requirements.txt
└── test_requirements_py27.txt
├── .landscape.yaml
├── bin
├── sort_wsdl.py
├── build_schema.py
└── _preamble.py
├── PEOPLE
├── SECURITY.md
├── .travis.yml
├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.md
├── checkout_pr.sh
└── .gitignore
/spyne/test/util/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spyne/test/interface/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spyne/test/interop/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spyne/test/transport/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spyne/test/multipython/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/django/rpctest/core/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/template/.gitignore:
--------------------------------------------------------------------------------
1 | *.egg-info
2 |
--------------------------------------------------------------------------------
/examples/template/template/test/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spyne/test/multipython/model/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.coveragerc:
--------------------------------------------------------------------------------
1 | [run]
2 | omit = spyne/test/*
3 |
--------------------------------------------------------------------------------
/examples/template/template/entity/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/pytest.ini:
--------------------------------------------------------------------------------
1 | [pytest]
2 | junit_family=xunit1
3 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap11/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap12/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/xml/validation_error/some_file:
--------------------------------------------------------------------------------
1 | some_file_contents
--------------------------------------------------------------------------------
/doc/source/tests.rst:
--------------------------------------------------------------------------------
1 |
2 | .. include:: ../../spyne/test/README.rst
3 |
--------------------------------------------------------------------------------
/examples/template/template/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | __version__ = '0.1.0'
3 |
--------------------------------------------------------------------------------
/examples/django/rpctest/core/tests.py:
--------------------------------------------------------------------------------
1 | ../../../../spyne/test/interop/test_django.py
--------------------------------------------------------------------------------
/examples/xml/soap12-mtom/.gitignore:
--------------------------------------------------------------------------------
1 | EA055406-5881-4F02-A3DC-9A5A7510D018.dat
2 |
--------------------------------------------------------------------------------
/doc/source/contributing.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _contributing:
3 |
4 | .. include:: ../../CONTRIBUTING.rst
5 |
--------------------------------------------------------------------------------
/examples/template/template/service.py:
--------------------------------------------------------------------------------
1 |
2 | # you can put your own Service class definitions here.
3 |
--------------------------------------------------------------------------------
/examples/xml/soap12-mtom/request.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/arskom/spyne/HEAD/examples/xml/soap12-mtom/request.txt
--------------------------------------------------------------------------------
/examples/xml/validation_error/validation_internal_error.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | xmllint --schema schema.xsd inst.xml
4 |
5 |
--------------------------------------------------------------------------------
/requirements/test_django_req.txt:
--------------------------------------------------------------------------------
1 | pytest
2 | pytest_django
3 | pytest_cov
4 | pytest_twisted
5 | junitxml
6 | lxml
7 | twisted
--------------------------------------------------------------------------------
/doc/source/.static/placeholder.txt:
--------------------------------------------------------------------------------
1 | placeholder file because Git won't allow an empty dir in a repo, but Sphinx expects this dir
2 |
--------------------------------------------------------------------------------
/doc/source/.templates/placeholder.txt:
--------------------------------------------------------------------------------
1 | placeholder file because Git won't allow an empty dir in a repo, but Sphinx expects this dir
2 |
--------------------------------------------------------------------------------
/doc/source/reference/model/enum.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-model-enum:
3 |
4 | Enum
5 | ----
6 |
7 | .. autofunction:: spyne.model.enum.Enum
8 |
9 |
--------------------------------------------------------------------------------
/doc/source/reference/error.rst:
--------------------------------------------------------------------------------
1 |
2 | Common Exceptions
3 | =================
4 |
5 | .. automodule:: spyne.error
6 | :members:
7 | :show-inheritance:
8 |
--------------------------------------------------------------------------------
/.landscape.yaml:
--------------------------------------------------------------------------------
1 | ignore-paths:
2 | - bin
3 | - examples
4 | ignore-patterns:
5 | - __init__.py
6 | requirements:
7 | - requirements/test_requirements.txt
8 |
--------------------------------------------------------------------------------
/doc/source/reference/decorator.rst:
--------------------------------------------------------------------------------
1 |
2 | RPC Decorators
3 | ==============
4 |
5 | .. automodule:: spyne.decorator
6 | :members:
7 | :inherited-members:
8 |
--------------------------------------------------------------------------------
/examples/xml/validation_error/README:
--------------------------------------------------------------------------------
1 |
2 | The scripts in this file illustrate how libxml's validation break when the Xml
3 | parser has resolve_entities disabled.
4 |
--------------------------------------------------------------------------------
/doc/source/reference/service.rst:
--------------------------------------------------------------------------------
1 |
2 | Service Definition
3 | ==================
4 |
5 | .. automodule:: spyne.service
6 | :members:
7 | :inherited-members:
8 |
9 |
--------------------------------------------------------------------------------
/doc/source/reference/protocol/json.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-protocol-json:
3 |
4 | Json
5 | ----
6 |
7 | .. automodule:: spyne.protocol.json
8 | :members:
9 | :show-inheritance:
10 |
--------------------------------------------------------------------------------
/doc/source/reference/model/fault.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-model-fault:
3 |
4 | Fault
5 | -----
6 |
7 | .. autoclass:: spyne.model.fault.Fault
8 | :members:
9 | :show-inheritance:
10 |
11 |
--------------------------------------------------------------------------------
/doc/source/reference/model/primitive.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-model-primitive:
3 |
4 | Primitives
5 | ----------
6 |
7 | .. automodule:: spyne.model.primitive
8 | :members:
9 | :show-inheritance:
10 |
11 |
--------------------------------------------------------------------------------
/doc/source/reference/model/sql.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-model-persistance:
3 |
4 | Persisting Objects
5 | ------------------
6 |
7 | .. automodule:: spyne.model.table
8 | :members:
9 | :show-inheritance:
10 |
--------------------------------------------------------------------------------
/doc/source/reference/protocol/xml.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-protocol-xml:
3 |
4 | Xml
5 | ---
6 |
7 | .. automodule:: spyne.protocol.xml
8 | :members:
9 | :show-inheritance:
10 | :undoc-members:
11 |
--------------------------------------------------------------------------------
/doc/source/reference/protocol/http.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-protocol-http:
3 |
4 | Http
5 | ----
6 |
7 | .. automodule:: spyne.protocol.http
8 | :members:
9 | :show-inheritance:
10 | :undoc-members:
11 |
--------------------------------------------------------------------------------
/doc/source/reference/protocol/msgpack.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-protocol-msgpack:
3 |
4 | MessagePack
5 | -----------
6 |
7 | .. automodule:: spyne.protocol.msgpack
8 | :members:
9 | :show-inheritance:
10 |
11 |
--------------------------------------------------------------------------------
/examples/tfb/spyne.dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.6.6-stretch
2 |
3 | ADD ./ /spyne
4 |
5 | WORKDIR /spyne
6 |
7 | RUN pip3 install -r /spyne/requirements.txt
8 |
9 | CMD gunicorn app:application -c gunicorn_conf.py
10 |
--------------------------------------------------------------------------------
/spyne/protocol/html/table/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | from spyne.protocol.html.table._base import HtmlTableBase
3 | from spyne.protocol.html.table.row import HtmlRowTable
4 | from spyne.protocol.html.table.column import HtmlColumnTable
5 |
--------------------------------------------------------------------------------
/bin/sort_wsdl.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import sys
3 |
4 | try:
5 | import _preamble
6 | except ImportError:
7 | sys.exc_clear()
8 |
9 | from spyne.test.sort_wsdl import main
10 |
11 | sys.exit(main())
12 |
--------------------------------------------------------------------------------
/doc/source/reference/server/null.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-server-null:
3 |
4 | NullServer
5 | ----------
6 |
7 | .. automodule:: spyne.server.null
8 | :members:
9 | :inherited-members:
10 | :undoc-members:
11 |
--------------------------------------------------------------------------------
/doc/source/reference/server/wsgi.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-server-wsgi:
3 |
4 | Http (WSGI)
5 | -----------
6 |
7 | .. automodule:: spyne.server.wsgi
8 | :members:
9 | :inherited-members:
10 | :undoc-members:
11 |
--------------------------------------------------------------------------------
/doc/source/reference/server/zeromq.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-server-zeromq:
3 |
4 | ZeroMQ
5 | ------
6 |
7 | .. automodule:: spyne.server.zeromq
8 | :members:
9 | :inherited-members:
10 | :undoc-members:
11 |
--------------------------------------------------------------------------------
/examples/tfb/spyne-raw.dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.6.6-stretch
2 |
3 | ADD ./ /spyne
4 |
5 | WORKDIR /spyne
6 |
7 | RUN pip3 install -r /spyne/requirements.txt
8 |
9 | CMD gunicorn app:application -c gunicorn_conf.py
10 |
--------------------------------------------------------------------------------
/doc/source/reference/protocol/base.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-protocol-base:
3 |
4 | Protocol Base Class
5 | --------------------
6 |
7 | .. automodule:: spyne.protocol._base
8 | :members:
9 | :show-inheritance:
10 |
11 |
--------------------------------------------------------------------------------
/doc/source/reference/protocol/dictdoc.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-protocol-dictdoc:
3 |
4 | Dictionary Document
5 | -------------------
6 |
7 | .. automodule:: spyne.protocol.dictdoc
8 | :members:
9 | :show-inheritance:
10 |
--------------------------------------------------------------------------------
/doc/source/reference/protocol/soap.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-protocol-soap:
3 |
4 | Soap 1.1
5 | --------
6 |
7 | .. automodule:: spyne.protocol.soap.soap11
8 | :members:
9 | :show-inheritance:
10 | :undoc-members:
11 |
12 |
--------------------------------------------------------------------------------
/doc/source/reference/server/pyramid.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-server-pyramid:
3 |
4 | Http (Pyramid)
5 | --------------
6 |
7 | .. automodule:: spyne.server.pyramid
8 | :members:
9 | :inherited-members:
10 | :undoc-members:
11 |
--------------------------------------------------------------------------------
/examples/tfb/gunicorn_conf.py:
--------------------------------------------------------------------------------
1 | import multiprocessing
2 | import os
3 | import sys
4 |
5 | workers = multiprocessing.cpu_count() * 3
6 |
7 | bind = "0.0.0.0:8080"
8 | keepalive = 120
9 | errorlog = '-'
10 | pidfile = 'gunicorn.pid'
11 |
--------------------------------------------------------------------------------
/examples/xml/validation_error/inst.xml:
--------------------------------------------------------------------------------
1 |
3 | ]>
4 |
5 |
6 | 2013-07-15T20:21:43.476838
7 | 5
8 | &file;
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/file_manager/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Upload Test
6 |
7 |
8 |
9 | Simple form upload test.
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/doc/source/reference/server/django.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-server-django:
3 | .. _spyne.server.django:
4 |
5 | Http (Django)
6 | -------------
7 |
8 | .. automodule:: spyne.server.django
9 | :members:
10 | :inherited-members:
11 | :undoc-members:
12 |
--------------------------------------------------------------------------------
/doc/source/reference/application.rst:
--------------------------------------------------------------------------------
1 |
2 | Application Definition
3 | ======================
4 |
5 | .. autoclass:: spyne.application.Application
6 | :members:
7 | :inherited-members:
8 |
9 | .. autofunction:: spyne.application.return_traceback_in_unhandled_exceptions
10 |
--------------------------------------------------------------------------------
/examples/multiple_protocols/presentation/Makefile:
--------------------------------------------------------------------------------
1 |
2 | all: pres.pdf
3 |
4 | pres.pdf: pres.tex get_utc_time.pdf
5 | pdflatex pres.tex
6 | pdflatex pres.tex
7 | pdflatex pres.tex
8 |
9 | get_utc_time.pdf: get_utc_time.svg
10 | inkscape --file=get_utc_time.svg --export-pdf get_utc_time.pdf
11 |
--------------------------------------------------------------------------------
/examples/django/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import os
3 | import sys
4 |
5 | if __name__ == "__main__":
6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "rpctest.settings")
7 |
8 | from django.core.management import execute_from_command_line
9 |
10 | execute_from_command_line(sys.argv)
11 |
--------------------------------------------------------------------------------
/examples/tfb/cloths/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Fortunes
5 |
6 |
7 |
8 |
9 | | id |
10 | message |
11 |
12 |
13 | |
14 | |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/bin/build_schema.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | # This can be used to debug invalid Xml Schema documents.
4 |
5 | import sys
6 |
7 | from lxml import etree
8 |
9 | if len(sys.argv) != 2:
10 | print "Usage: %s " % sys.argv[0]
11 | sys.exit(1)
12 |
13 | f = open(sys.argv[1])
14 |
15 | etree.XMLSchema(etree.parse(f))
16 |
--------------------------------------------------------------------------------
/doc/source/reference/model/binary.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-model-binary:
3 |
4 | Binary Types
5 | ------------
6 |
7 | .. automodule:: spyne.model.binary
8 |
9 | .. autoclass:: spyne.model.binary.ByteArray
10 | :members:
11 | :show-inheritance:
12 |
13 | .. autoclass:: spyne.model.binary.File
14 | :members:
15 | :show-inheritance:
16 |
--------------------------------------------------------------------------------
/requirements/test_requirements.txt:
--------------------------------------------------------------------------------
1 | pytest>=2.9
2 | pytest-twisted
3 | pytest-cov
4 | coverage
5 | junitxml
6 | werkzeug
7 | sqlalchemy
8 | lxml>=3.6
9 | pyyaml
10 | pyzmq
11 | twisted
12 | colorama
13 | msgpack>=1
14 | webtest
15 | pytest_django
16 | django
17 | python-subunit
18 | pyramid
19 | tox
20 | pyparsing>=2.0.2
21 | suds-community
22 | zeep
23 | pandas
24 |
--------------------------------------------------------------------------------
/doc/source/reference/protocol/index.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-protocol:
3 |
4 | Protocols
5 | =========
6 |
7 | The `spyne.protocol` package contains the implementations of various remote
8 | procedure call protocols.
9 |
10 | .. toctree::
11 | :maxdepth: 2
12 |
13 | base
14 | http
15 | xml
16 | soap
17 | dictdoc
18 | json
19 | msgpack
20 |
--------------------------------------------------------------------------------
/doc/source/reference/server/index.rst:
--------------------------------------------------------------------------------
1 |
2 | Server Transports
3 | =================
4 |
5 | .. toctree::
6 | :maxdepth: 2
7 |
8 | wsgi
9 | twisted
10 | django
11 | pyramid
12 | zeromq
13 | null
14 |
15 | Server Base Class
16 | -----------------
17 |
18 | .. automodule:: spyne.server._base
19 | :members:
20 | :inherited-members:
21 |
22 |
--------------------------------------------------------------------------------
/doc/source/reference/server/twisted.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-server-twisted:
3 |
4 | Http (Twisted)
5 | --------------
6 |
7 | .. automodule:: spyne.server.twisted.http
8 | :members:
9 | :inherited-members:
10 | :undoc-members:
11 |
12 | .. automodule:: spyne.server.twisted.websocket
13 | :members:
14 | :inherited-members:
15 | :undoc-members:
16 |
17 |
--------------------------------------------------------------------------------
/doc/gendoc.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -x
2 |
3 | git branch
4 | rm -rf docs;
5 | declare -A docs=( [2.10]=2_10 [2.11]=2_11 [2.12]=master );
6 |
7 | for i in ${!docs[@]}; do
8 | git checkout ${docs[$i]} || exit 1;
9 |
10 | rm -rf $i;
11 | make clean;
12 | make html || exit 1;
13 | mv build/html $i;
14 | done;
15 |
16 | mkdir docs;
17 | mv ${!docs[@]} docs
18 | make clean;
19 |
--------------------------------------------------------------------------------
/doc/source/reference/model/complex.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-model-complex:
3 |
4 | Complex
5 | -------
6 |
7 | .. automodule:: spyne.model.complex
8 | :members:
9 | :show-inheritance:
10 |
11 | .. function:: TTableModel(metadata=None)
12 |
13 | A TableModel template that generates a new TableModel class for each
14 | call. If metadata is not supplied, a new one is instantiated.
15 |
--------------------------------------------------------------------------------
/PEOPLE:
--------------------------------------------------------------------------------
1 |
2 | Contributors (chronological order):
3 |
4 | Aaron Bickell
5 | Jamie Kirkpatrick
6 | Burak Arslan
7 | Tres Seaver
8 | Chris Austin
9 | Brad Allen
10 | github.com/Konjkov (see issue 211)
11 |
12 |
13 | Also see here for a complete list: https://github.com/arskom/spyne/contributors
14 |
15 | Ohloh also keeps track of such stats: http://ohloh.net/p/spyne
16 |
--------------------------------------------------------------------------------
/examples/xml/validation_error/validation_internal_error.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from lxml.etree import XMLParser, fromstring, XMLSchema
4 |
5 | schema_doc = open('schema.xsd').read()
6 | inst_doc = open('inst.xml').read()
7 |
8 | parser = XMLParser(resolve_entities=False)
9 | elt = fromstring(inst_doc, parser)
10 | schema = XMLSchema(fromstring(schema_doc))
11 | schema.validate(elt)
12 |
--------------------------------------------------------------------------------
/requirements/test_requirements_py27.txt:
--------------------------------------------------------------------------------
1 | pytest>=2.9
2 | pytest-twisted
3 | pytest-cov
4 | coverage
5 | junitxml
6 | werkzeug
7 | sqlalchemy
8 | lxml>=3.6
9 | pyyaml
10 | pyzmq
11 | twisted
12 | colorama
13 | msgpack-python
14 | webtest
15 | pytest_django
16 | django
17 | python-subunit
18 | pyramid
19 | tox
20 | pyparsing>=2.0.2
21 | suds-jurko
22 | zeep
23 | numpy<1.16.99
24 | pandas<0.24.99
25 |
--------------------------------------------------------------------------------
/doc/source/reference/index.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-index:
3 |
4 | ====================
5 | Spyne API Reference
6 | ====================
7 |
8 | .. toctree::
9 | :maxdepth: 3
10 |
11 | base
12 | application
13 | service
14 | decorator
15 | error
16 |
17 | model/index
18 | interface
19 | protocol/index
20 | client
21 | server/index
22 | auxproc
23 |
24 | util
25 |
--------------------------------------------------------------------------------
/doc/source/manual/relational.rst:
--------------------------------------------------------------------------------
1 | column_property example:
2 |
3 | ```
4 | Invoice.append_field('cost', Decimal(
5 | exc_db=True,
6 | str_format="${:,.2f}",
7 | read_only=True,
8 | mapper_property=column_property(sql
9 | .select([sql.func.sum(InvoiceItem.cost)])
10 | .where(
11 | D91InvoiceItem.invoice_id == Invoice.id,
12 | )
13 | .as_scalar()
14 | ),
15 | ))
16 | ```
17 |
--------------------------------------------------------------------------------
/examples/xml/validation_error/py_output:
--------------------------------------------------------------------------------
1 | Traceback (most recent call last):
2 | File "validation_internal_error.py", line 31, in
3 | schema.validate(elt)
4 | File "lxml.etree.pyx", line 3252, in lxml.etree._Validator.validate (src/lxml/lxml.etree.c:143796)
5 | File "xmlschema.pxi", line 151, in lxml.etree.XMLSchema.__call__ (src/lxml/lxml.etree.c:152165)
6 | lxml.etree.XMLSchemaValidateError: Internal error in XML Schema validation.
7 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Supported Versions
4 |
5 | Use this section to tell people about which versions of your project are
6 | currently being supported with security updates.
7 |
8 | | Version | Supported |
9 | | ------- | ------------------ |
10 | | 2.13.x | :white_check_mark: |
11 | | <2.12.x | :x: |
12 |
13 | ## Reporting a Vulnerability
14 |
15 | Please send an email to the public email at the github profile address
16 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 | matrix:
3 | include:
4 | - python: "2.7"
5 | env: TEST_SUITE=test
6 | - python: "3.4"
7 | env: TEST_SUITE=test_python3
8 | - python: "3.5"
9 | env: TEST_SUITE=test_python3
10 | - python: "3.6"
11 | env: TEST_SUITE=test_python3
12 | - python: "3.7"
13 | env: TEST_SUITE=test_python3
14 | install:
15 | - pip install -r requirements/test_requirements.txt
16 | script:
17 | - python setup.py $TEST_SUITE
18 |
19 |
--------------------------------------------------------------------------------
/doc/source/reference/client.rst:
--------------------------------------------------------------------------------
1 |
2 | Client Transports
3 | =================
4 |
5 | Client Base Class
6 | --------------------
7 |
8 | .. automodule:: spyne.client._base
9 | :members:
10 | :inherited-members:
11 |
12 | HTTP
13 | ----
14 |
15 | .. automodule:: spyne.client.http
16 | :members:
17 | :inherited-members:
18 | :undoc-members:
19 |
20 | ZeroMQ
21 | ------
22 |
23 | .. automodule:: spyne.client.zeromq
24 | :members:
25 | :inherited-members:
26 | :undoc-members:
27 |
--------------------------------------------------------------------------------
/examples/file_manager/suds_client.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from suds.client import Client
4 | import base64
5 |
6 | # Suds does not support base64binary type, so we do the encoding manually.
7 | file_data = base64.b64encode('file_data')
8 |
9 | c=Client('http://localhost:9000/filemgr/?wsdl')
10 | c.service.add('x', 'y', 'file_name', file_data)
11 |
12 | print('file written.')
13 | print()
14 |
15 | print('incoming data:')
16 | return_data = c.service.get('file_name')
17 | print(repr(return_data))
18 |
--------------------------------------------------------------------------------
/doc/source/manual/index.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _manual:
3 |
4 | Spyne Manual
5 | =============
6 |
7 | The API reference is not the best resource when learning use a new software
8 | library. Here, you will find a collection of documents that show you various
9 | aspects of Spyne by examples.
10 |
11 | .. toctree::
12 | :maxdepth: 2
13 |
14 | 01_highlevel
15 | 02_helloworld
16 | 03_types
17 | 04_usermanager
18 | 05-01_sqlalchemy
19 | 05-02_validation
20 | 05-03_django
21 | 06_metadata
22 | 07_t_and_p
23 |
--------------------------------------------------------------------------------
/doc/source/reference/base.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-base:
3 |
4 | Fundamental Data Structures
5 | ===========================
6 |
7 | MethodContext
8 | -------------
9 |
10 | .. autoclass:: spyne.MethodContext
11 | :members:
12 | :show-inheritance:
13 |
14 | MethodDescriptor
15 | ----------------
16 |
17 | .. autoclass:: spyne.MethodDescriptor
18 | :members:
19 | :show-inheritance:
20 |
21 | .. _reference-eventmanager:
22 |
23 |
24 | EventManager
25 | ------------
26 |
27 | .. autoclass:: spyne.EventManager
28 | :members:
29 |
--------------------------------------------------------------------------------
/examples/tfb/requirements.txt:
--------------------------------------------------------------------------------
1 | attrs==18.2.0
2 | Automat==0.7.0
3 | colorama==0.4.1
4 | constantly==15.1.0
5 | greenlet==0.4.15
6 | gunicorn==19.9.0
7 | hyperlink==18.0.0
8 | idna==2.8
9 | incremental==17.5.0
10 | lxml==4.3.1
11 | meinheld==0.6.1
12 | msgpack-python==0.5.6
13 | neurons==0.8.4
14 | ply==3.11
15 | psycopg2==2.7.7
16 | pycrypto==2.6.1
17 | PyHamcrest==1.9.0
18 | pytz==2018.9
19 | PyYAML==4.2b4
20 | six==1.12.0
21 | slimit==0.8.1
22 | spyne==2.13.9a0
23 | SQLAlchemy==1.2.17
24 | Twisted==18.9.0
25 | txpostgres==1.6.0
26 | Werkzeug==0.14.1
27 | zope.interface==4.6.0
28 | uwsgi==2.0.18
29 |
--------------------------------------------------------------------------------
/spyne/test/interop/test_rpc.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/ruby
2 |
3 | class InteropTest
4 | require 'soap/rpc/driver'
5 |
6 | def initialize()
7 | ws_url='http://127.0.0.1:9754/'
8 | ws_ns='InteropService.InteropService'
9 | @conn = SOAP::RPC::Driver.new(ws_url, ws_ns)
10 | end
11 |
12 | def echo_int(i)
13 | @conn.add_method("echo_integer", "i")
14 | @conn.echo_integer(i)
15 | end
16 |
17 | def echo_string(s)
18 | @conn.add_method("echo_string", "s")
19 | @conn.echo_string(s)
20 | end
21 | end
22 |
23 | ws = InteropTest.new()
24 |
25 | puts ws.echo_string("OK")
26 | puts ws.echo_int(0)
27 |
--------------------------------------------------------------------------------
/examples/xml/Makefile:
--------------------------------------------------------------------------------
1 | all: wsse.xsd wsu.xsd ds.xsd xsd.xsd xml.xsd
2 |
3 | clean:
4 | -rm *.xsd
5 |
6 | wsse.xsd:
7 | wget "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" -O wsse.xsd
8 |
9 | wsu.xsd:
10 | wget "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" -O wsu.xsd
11 |
12 | ds.xsd:
13 | wget "https://raw.githubusercontent.com/arskom/pyubl/master/ubl/const/schema/common/xmldsig-core-schema.xsd" -O ds.xsd
14 |
15 | xsd.xsd:
16 | wget "https://www.w3.org/2001/XMLSchema.xsd" -O xsd.xsd
17 |
18 | xml.xsd:
19 | wget "http://www.w3.org/2001/xml.xsd" -O xml.xsd
20 |
--------------------------------------------------------------------------------
/examples/file_manager/static/simple/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Spyne Upload Test
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/doc/source/reference/auxproc.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-auxproc-base:
3 |
4 | Auxiliary Processors
5 | ====================
6 |
7 | .. automodule:: spyne.auxproc
8 |
9 | AuxProcBase
10 | -----------
11 |
12 | .. autoclass:: spyne.auxproc._base.AuxProcBase
13 | :members:
14 | :inherited-members:
15 |
16 | .. _reference-auxproc-sync:
17 |
18 | SyncAuxProc
19 | -----------
20 |
21 | .. autoclass:: spyne.auxproc.sync.SyncAuxProc
22 | :members:
23 | :show-inheritance:
24 |
25 | .. _reference-auxproc-thread:
26 |
27 | ThreadAuxProc
28 | -------------
29 |
30 | .. autoclass:: spyne.auxproc.thread.ThreadAuxProc
31 | :members:
32 | :show-inheritance:
33 |
--------------------------------------------------------------------------------
/examples/xml/soap12-mtom/request.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -x
2 |
3 | # The "boundary" string here must match with the one in the request body
4 | # (typically the first line of the request body)
5 |
6 | # The "start" string is similarly the content id of the first mime part
7 | # it is currently ignored by the MtoM parser
8 |
9 | curl -X POST \
10 | -H 'Content-Type: multipart/related; type="application/xop+xml"; '`
11 | `'boundary="uuid:2e53e161-b47f-444a-b594-eb6b72e76997"; '`
12 | `'start=""; '`
13 | `'start-info="application/soap+xml"; '`
14 | `'action="sendDocument"' \
15 | --data-binary @request.txt \
16 | http://localhost:8000
17 |
--------------------------------------------------------------------------------
/examples/tfb/spyne-nginx-uwsgi.dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.6.6-stretch
2 |
3 | RUN curl -s http://nginx.org/keys/nginx_signing.key | apt-key add -
4 | RUN echo "deb http://nginx.org/packages/debian/ stretch nginx" >> /etc/apt/sources.list
5 | RUN echo "deb-src http://nginx.org/packages/debian/ stretch nginx" >> /etc/apt/sources.list
6 |
7 | RUN apt update -yqq && apt install -yqq nginx
8 |
9 | ADD ./ /spyne
10 |
11 | WORKDIR /spyne
12 |
13 | RUN pip3 install -r /spyne/requirements.txt
14 |
15 | RUN sed -i 's|include .*/conf/uwsgi_params;|include /etc/nginx/uwsgi_params;|g' /spyne/nginx.conf
16 |
17 | CMD nginx -c /spyne/nginx.conf && uwsgi --ini /spyne/uwsgi.ini --processes $(($(nproc)*3)) --wsgi app:application
18 |
--------------------------------------------------------------------------------
/examples/xml/validation_error/sh_output:
--------------------------------------------------------------------------------
1 | inst.xml:5: namespace warning : xmlns: URI some_ns is not absolute
2 |
3 | ^
4 |
5 |
7 | ]>
8 |
9 | 2013-07-15T20:21:43.476838
10 | 5
11 | &file;
12 |
13 | inst.xml:8: element s: Schemas validity error : Internal error: xmlSchemaVDocWalk, there is at least one entity reference in the node-tree currently being validated. Processing of entities with this XML Schema processor is not supported (yet). Please substitute entities before validation..
14 | inst.xml validation generated an internal error
15 |
--------------------------------------------------------------------------------
/doc/source/reference/interface.rst:
--------------------------------------------------------------------------------
1 |
2 | Interfaces
3 | ==========
4 |
5 | The `spyne.interface` package contains the implementations of various interface
6 | document standards.
7 |
8 | Interface Class
9 | --------------------
10 |
11 | .. autoclass:: spyne.interface.Interface
12 | :members:
13 | :show-inheritance:
14 |
15 | Interface Document Base Class
16 | -----------------------------
17 |
18 | .. autoclass:: spyne.interface.InterfaceDocumentBase
19 | :members:
20 | :show-inheritance:
21 |
22 | XML Schema
23 | ----------
24 |
25 | .. automodule:: spyne.interface.xml_schema._base
26 | :members:
27 | :inherited-members:
28 |
29 | Wsdl 1.1
30 | --------
31 |
32 | .. automodule:: spyne.interface.wsdl.wsdl11
33 | :members:
34 | :inherited-members:
35 |
--------------------------------------------------------------------------------
/bin/_preamble.py:
--------------------------------------------------------------------------------
1 | # Copyright (c) Twisted Matrix Laboratories.
2 | # See LICENSE for details.
3 |
4 | # This makes sure that users don't have to set up their environment
5 | # specially in order to run these programs from bin/.
6 |
7 | # This helper is shared by many different actual scripts. It is not intended to
8 | # be packaged or installed, it is only a developer convenience. By the time
9 | # Spyne is actually installed somewhere, the environment should already be set
10 | # up properly without the help of this tool.
11 |
12 | import os
13 | import sys
14 |
15 | path = os.path.abspath(sys.argv[0])
16 | while os.path.dirname(path) != path:
17 | if os.path.exists(os.path.join(path, 'spyne', '__init__.py')):
18 | sys.path.insert(0, path)
19 | break
20 | path = os.path.dirname(path)
21 |
--------------------------------------------------------------------------------
/examples/flask/README.rst:
--------------------------------------------------------------------------------
1 | This is an example for using Flask and Spyne together. It is very simple,
2 | and does nothing useful.
3 |
4 | Create virtualenv and install requirements: ::
5 |
6 | pip install Flask
7 | pip install -e . # install Spyne from working directory
8 |
9 | Run Flask web server: ::
10 |
11 | ./examples/flask/manage.py
12 |
13 | Try Flask views to make sure it works: ::
14 |
15 | curl -s http://127.0.0.1:5000/hello | python -m json.tool
16 |
17 | Here is a Spyne views call example: ::
18 |
19 | curl -s http://localhost:5000/soap/hello?name=Anton\×=3 | python -m json.tool
20 |
21 | The same view call, but without explicit name argument, to read default from
22 | Flask config: ::
23 |
24 | curl -s http://localhost:5000/soap/hello?times=3 | python -m json.tool
25 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: It's a bug report
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | !!! Please close this window if you came here to ask a question !!!
11 |
12 | See the readme file for more information.
13 |
14 | If you are here to report a proper issue, please delete this bit and go on. Sorry about the inconvenience.
15 |
16 | If you are not sure, just start a discussion. We will happily convert it to an issue if it turns out to be necessary.
17 |
18 | Thanks!
19 |
20 | ================================
21 |
22 | **Describe the bug**
23 | Is it a stack trace or just unexpected behavior?
24 |
25 | **To Reproduce**
26 | Paste here the code that reproduces the bug
27 |
28 | **Additional context**
29 | Add any other context about the problem here.
30 |
--------------------------------------------------------------------------------
/checkout_pr.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 |
3 | if ! which jq > /dev/null; then exit $?; fi
4 |
5 | ME=$0
6 | usage() {
7 | echo Usage: $ME ""
8 | echo
9 | exit 1
10 | }
11 |
12 | [ -z "$PRID" ] && PRID=$1
13 | [ -z "$PRID" ] && usage
14 |
15 | echo Fetching info for "PR#$PRID"...
16 | JSON=$(curl -s https://api.github.com/repos/arskom/spyne/pulls/$PRID)
17 | #JSON=$(cat pull.json)
18 | BRANCH=$(jq -r .head.ref <<< "$JSON")
19 | UPSTREAM=$(jq -r .head.repo.ssh_url <<< "$JSON")
20 | NAME=$(jq -r .head.user.login <<< "$JSON")
21 |
22 | # add remote
23 | if ! git remote get-url $NAME > /dev/null; then
24 | echo Add remote $NAME url: $UPSTREAM
25 | git remote add $NAME $UPSTREAM
26 | fi
27 |
28 | set -x
29 | git fetch -u $NAME $BRANCH:pr/$PRID
30 | git checkout pr/$PRID
31 | git branch -u $NAME/$BRANCH
32 |
--------------------------------------------------------------------------------
/spyne/test/model/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
--------------------------------------------------------------------------------
/examples/tfb/uwsgi.ini:
--------------------------------------------------------------------------------
1 | [uwsgi]
2 | master
3 | ; Increase listen queue used for nginx connecting to uWSGI. This matches
4 | ; net.ipv4.tcp_max_syn_backlog and net.core.somaxconn.
5 | listen = 16384
6 | ; for performance
7 | disable-logging
8 | ; use UNIX sockets instead of TCP loopback for performance
9 | socket = /var/tmp/uwsgi.sock
10 | ; allow nginx to access the UNIX socket
11 | chmod-socket = 666
12 | ; Avoid thundering herd problem http://uwsgi-docs.readthedocs.org/en/latest/articles/SerializingAccept.html .
13 | ; This is currently disabled because when I tried it with flask, it caused a
14 | ; 20% performance hit. The CPU cores could not be saturated with thunder-lock.
15 | ; I'm not yet sure the full story, so this is presently disabled. Also,
16 | ; disabling this caused bottle to get ~13% faster.
17 | ;thunder-lock
18 | ; used by uwsgi_stop.ini
19 | pidfile = /var/tmp/uwsgi.pid
20 |
--------------------------------------------------------------------------------
/spyne/store/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """This is the spyne storage package."""
21 |
--------------------------------------------------------------------------------
/examples/xml/utils_poly.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from __future__ import print_function
4 |
5 | import sys
6 |
7 | from lxml import etree
8 | from spyne.util import six
9 |
10 | from spyne import ComplexModel, Unicode
11 | from spyne.util.xml import get_object_as_xml_polymorphic
12 |
13 |
14 | class B(ComplexModel):
15 | _type_info = [
16 | ('_b', Unicode(default="b")),
17 | ]
18 |
19 |
20 | class C(B):
21 | _type_info = [
22 | ('_c', Unicode(default="c")),
23 | ]
24 |
25 |
26 | class A(ComplexModel):
27 | _type_info = [
28 | ('a', Unicode(subname="_a")),
29 | ('b', B.customize(subname="_b")),
30 | ]
31 |
32 |
33 | a = A(b=C())
34 | elt = get_object_as_xml_polymorphic(a, A, no_namespace=True)
35 | xml_string = etree.tostring(elt, pretty_print=True)
36 | if six.PY2:
37 | print(xml_string, end="")
38 | else:
39 | sys.stdout.buffer.write(xml_string)
40 |
--------------------------------------------------------------------------------
/examples/tfb/README.md:
--------------------------------------------------------------------------------
1 | # [Spyne](http://spyne.io/) Benchmark Test
2 |
3 | This is the Python Spyne portion of a [benchmarking tests suite](../../)
4 | comparing a variety of frameworks.
5 |
6 | The latest version is at https://github.com/arskom/spyne/tree/master/examples/tfb
7 |
8 | All test implementations are located within ([app.py](app.py))
9 |
10 | ## Description
11 |
12 | Spyne + SQLAlchemy
13 |
14 | ### Database
15 |
16 | PostgreSQL (psycopg2 on CPython)
17 |
18 | ### Server
19 |
20 | * gunicorn+wsgi on CPython
21 |
22 | ## Test URLs
23 | ### JSON Encoding
24 |
25 | http://localhost:8080/json
26 |
27 | ### Single Row Random Query
28 |
29 | With ORM:
30 | http://localhost:8080/dbs
31 |
32 | Without ORM (raw):
33 | http://localhost:8080/dbsraw
34 |
35 | ### Variable Row Query Test
36 |
37 | With ORM:
38 | http://localhost:8080/db?queries=2
39 |
40 | Without ORM (raw):
41 | http://localhost:8080/dbraw?queries=2
42 |
--------------------------------------------------------------------------------
/spyne/test/regen_wsdl.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from lxml import etree
4 | from spyne.test.sort_wsdl import sort_wsdl
5 | from spyne.interface.wsdl import Wsdl11
6 |
7 | from spyne.test.interop.server._service import services
8 | from spyne.application import Application
9 |
10 | app = Application(services, 'spyne.test.interop.server')
11 | app.transport = 'http://schemas.xmlsoap.org/soap/http'
12 | wsdl = Wsdl11(app.interface)
13 | wsdl.build_interface_document('http://localhost:9754/')
14 | elt = etree.ElementTree(etree.fromstring(wsdl.get_interface_document()))
15 | sort_wsdl(elt)
16 | s = etree.tostring(elt)
17 |
18 | # minidom's serialization seems to put attributes in alphabetic order.
19 | # this is exactly what we want here.
20 | from xml.dom.minidom import parseString
21 | doc = parseString(s)
22 | s = doc.toprettyxml(indent=' ', newl='\n', encoding='utf8')
23 | s = s.replace(" xmlns:","\n xmlns:")
24 |
25 | open('wsdl.xml', 'w').write(s)
26 | print('wsdl.xml written')
27 |
--------------------------------------------------------------------------------
/spyne/server/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The ``spyne.server`` package contains the server transports."""
21 |
22 | from spyne.server._base import ServerBase
23 | from spyne.server.null import NullServer
24 |
--------------------------------------------------------------------------------
/doc/source/reference/util.rst:
--------------------------------------------------------------------------------
1 |
2 | Miscellanous Spyne Utilities
3 | =============================
4 |
5 | Class Dictionary
6 | ----------------
7 |
8 | .. automodule:: spyne.util.cdict
9 | :members:
10 |
11 |
12 | .. _spyne.util.django:
13 |
14 | Django Integration Utils
15 | ------------------------
16 |
17 | .. automodule:: spyne.util.django
18 | :members:
19 |
20 | Element Tree Conversion
21 | -----------------------
22 |
23 | .. automodule:: spyne.util.etreeconv
24 | :members:
25 |
26 | Simple Wrappers
27 | ---------------
28 |
29 | .. automodule:: spyne.util.simple
30 | :members:
31 |
32 | Xml Utilities
33 | -------------
34 |
35 | .. automodule:: spyne.util.xml
36 | :members:
37 |
38 | Ordered Dictionary
39 | ------------------
40 |
41 | .. automodule:: spyne.util.odict
42 | :members:
43 |
44 | Ordered Set
45 | -----------
46 |
47 | .. automodule:: spyne.util.oset
48 | :members:
49 |
50 | Protocol Helpers
51 | ----------------
52 |
53 | .. automodule:: spyne.util.protocol
54 | :members:
55 |
--------------------------------------------------------------------------------
/examples/twisted/codegen.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import logging
4 | logging.basicConfig(level=logging.DEBUG)
5 |
6 | from spyne import Application, rpc, ServiceBase, \
7 | Integer, Unicode
8 |
9 | from spyne import Iterable
10 |
11 | from spyne.protocol.soap import Soap11
12 |
13 | from spyne.server.twisted import TwistedWebResource
14 |
15 | from twisted.internet import reactor
16 | from twisted.web.server import Site
17 |
18 | class HelloWorldService(ServiceBase):
19 | @rpc(Unicode, Integer, _returns=Iterable(Unicode))
20 | def say_hello(ctx, name, times):
21 | for i in range(times):
22 | yield 'Hello, %s' % name
23 |
24 | application = Application([HelloWorldService],
25 | tns='spyne.examples.hello',
26 | in_protocol=Soap11(validator='lxml'),
27 | out_protocol=Soap11()
28 | )
29 |
30 | if __name__ == '__main__':
31 | resource = TwistedWebResource(application)
32 | site = Site(resource)
33 |
34 | reactor.listenTCP(8000, site, interface='0.0.0.0')
35 | reactor.run()
36 |
37 |
38 |
--------------------------------------------------------------------------------
/spyne/test/protocol/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """This is Spyne's test package.
21 |
22 | You are not supposed to import test package from production code because tests
23 | fiddle with global state of Spyne classes.
24 | """
25 |
--------------------------------------------------------------------------------
/spyne/server/twisted/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 |
21 | def log_and_let_go(err, logger):
22 | logger.error(err.getTraceback())
23 | return err
24 |
25 |
26 | from spyne.server.twisted.http import TwistedWebResource
27 | from spyne.server.twisted.websocket import TwistedWebSocketResource
28 |
--------------------------------------------------------------------------------
/spyne/interface/wsdl/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The ``spyne.interface.wsdl`` package contains an implementation of the subset
21 | Wsdl 1.1 standard, and awaits for volunteers for implementing the brand new
22 | Wsdl 2.0 standard.
23 | """
24 |
25 | from spyne.interface.wsdl.wsdl11 import Wsdl11
26 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 |
21 | import socket
22 |
23 |
24 | def get_open_port():
25 | s = socket.socket()
26 | s.bind(('', 0)) # Bind to a free port provided by the host.
27 | retval = s.getsockname()[1]
28 | s.close()
29 | return retval
30 |
--------------------------------------------------------------------------------
/spyne/client/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The ``spyne.client`` package contains the client transports."""
21 |
22 | from spyne.client._base import Factory
23 | from spyne.client._base import RemoteService
24 | from spyne.client._base import ClientBase
25 | from spyne.client._base import RemoteProcedureBase
26 |
--------------------------------------------------------------------------------
/examples/xml/validation_error/schema.xsd:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/spyne/protocol/cloth/__init__.py:
--------------------------------------------------------------------------------
1 | # encoding: utf8
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The ``spyne.protocol.cloth`` package contains an EXPERIMENTAL protocol
21 | for clothing otherwise boring data.
22 | """
23 |
24 | from spyne.protocol.cloth._base import XmlCloth
25 | # huge hack to have the last line of microformat.py execute
26 | import spyne.protocol.html
27 |
--------------------------------------------------------------------------------
/spyne/interface/xml_schema/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The spyne.interface.xml_schema package contains an implementation of a subset
21 | of the Xml Schema 1.0 standard. Volunteers are needed to see whether the brand
22 | new Xml Schema 1.1 standard is worth the trouble, and patch as necessary.
23 | """
24 |
25 | from spyne.interface.xml_schema._base import XmlSchema
26 |
--------------------------------------------------------------------------------
/spyne/test/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | class FakeApp(object):
21 | transport = 'transport'
22 | tns = 'tns'
23 | name = 'name'
24 | services = []
25 | classes = ()
26 |
27 | import logging
28 | logging.basicConfig(level=logging.DEBUG)
29 | logging.getLogger('spyne.util.appreg').setLevel(logging.INFO)
30 |
31 | from spyne.context import FakeContext
32 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .data
2 | .cache
3 | .eggs
4 |
5 | # python cruft
6 | *.pyc
7 | *.pyo
8 | *$py.class
9 | *.egg
10 | *.egg-info
11 | __pycache__
12 | dist
13 | build
14 | pip-log.txt
15 | MANIFEST
16 |
17 | # test cruft
18 | .tox
19 | .noseids
20 | .coverage
21 | .coverage.*
22 | coverage.xml
23 | htmlcov
24 | test_html
25 | test_file_storage
26 | virt-*
27 | .pytest_cache
28 |
29 | ## test output
30 | spyne/test/*.html
31 | spyne/test/store
32 | test_result*
33 | Test*.html
34 |
35 | ## run_tests.sh
36 | jython-installer-*
37 | Python-2.*.*
38 | Python-3.*.*
39 |
40 | ## wsi-test
41 | wsi-test-tools
42 | WSI_Test_Java_Final_1.1.zip
43 | spyne/test/interop/config.xml
44 | spyne/test/config.xml
45 |
46 | # sphinx cruft
47 | .buildinfo
48 | doc/docs
49 |
50 | # latex cruft
51 | get_utc_time.pdf
52 | pres.pdf
53 | *.aux
54 | *.log
55 | *.nav
56 | *.out
57 | *.snm
58 | *.toc
59 | *.vrb
60 | *.backup
61 |
62 | # 2to3 cruft
63 | *.bak
64 |
65 | # output from examples
66 | examples/file_manager/files/
67 | examples/xml/*.xsd
68 |
69 | # nuitka cruft
70 | *.build
71 |
72 | # cruft produced by non-spyne code need to go to your global ignores file. see
73 | # https://help.github.com/articles/ignoring-files/#create-a-global-gitignore
74 |
--------------------------------------------------------------------------------
/spyne/auxproc/sync.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logger = logging.getLogger(__name__)
22 |
23 | from spyne.auxproc import AuxProcBase
24 |
25 |
26 | class SyncAuxProc(AuxProcBase):
27 | """SyncAuxProc processes auxiliary methods synchronously. It's useful for
28 | testing purposes.
29 | """
30 |
31 | def process_context(self, server, ctx):
32 | self.process(server, ctx)
33 |
--------------------------------------------------------------------------------
/doc/source/reference/model/index.rst:
--------------------------------------------------------------------------------
1 |
2 | .. _reference-model:
3 |
4 | Models
5 | ======
6 |
7 | The `spyne.model` package contains the Spyne type markers to denote primitive
8 | and complex types in object and method definitions.
9 |
10 | Spyne has built-in support for most common data types and provides an API for
11 | those who'd like to implement their own.
12 |
13 | There are five types of models in Spyne:
14 |
15 | .. toctree::
16 | :maxdepth: 2
17 |
18 | primitive
19 | binary
20 | enum
21 | complex
22 | fault
23 | sql
24 |
25 | Base Classes
26 | ------------
27 |
28 | .. autoclass:: spyne.model.ModelBase
29 | :members:
30 | :special-members:
31 | :exclude-members: __dict__,__weakref__
32 |
33 | .. autoattribute:: spyne.model.ModelBase.__orig__
34 |
35 | .. autoattribute:: spyne.model.ModelBase.__extends__
36 |
37 | .. autoattribute:: spyne.model.ModelBase.__namespace__
38 |
39 | .. autoattribute:: spyne.model.ModelBase.__type_name__
40 |
41 | .. autoclass:: spyne.model.SimpleModel
42 | :members:
43 | :show-inheritance:
44 | :special-members:
45 | :exclude-members: __dict__,__weakref__
46 |
47 | Modifiers
48 | ---------
49 |
50 | .. autofunction:: spyne.model.Mandatory
51 |
--------------------------------------------------------------------------------
/spyne/protocol/soap/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The ``spyne.protocol.soap`` package contains an implementation of a subset
21 | of the Soap 1.1 standard and awaits for volunteers for implementing the
22 | brand new Soap 1.2 standard.
23 |
24 | Patches are welcome.
25 | """
26 |
27 | from spyne.protocol.soap.soap11 import Soap11
28 | from spyne.protocol.soap.soap11 import _from_soap
29 | from spyne.protocol.soap.soap11 import _parse_xml_string
30 | from spyne.protocol.soap.soap12 import Soap12
--------------------------------------------------------------------------------
/spyne/util/protocol.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """Helpers for protocol boilerplate."""
21 |
22 | from spyne import MethodContext
23 | from spyne.server import ServerBase
24 |
25 |
26 | def deserialize_request_string(string, app):
27 | """Deserialize request string using in_protocol in application definition.
28 | Returns the corresponding native python object.
29 | """
30 |
31 | server = ServerBase(app)
32 | initial_ctx = MethodContext(server, MethodContext.SERVER)
33 | initial_ctx.in_string = [string]
34 |
35 | ctx = server.generate_contexts(initial_ctx)[0]
36 | server.get_in_object(ctx)
37 |
38 | return ctx.in_object
39 |
--------------------------------------------------------------------------------
/spyne/model/relational.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | from spyne.model.complex import ComplexModel
21 | from spyne.model.primitive import Unicode
22 |
23 |
24 | class FileData(ComplexModel):
25 | _type_info = [
26 | ('name', Unicode),
27 | ('type', Unicode),
28 | ('path', Unicode),
29 | ]
30 |
31 | @property
32 | def data(self):
33 | return self._data
34 |
35 | @data.setter
36 | def data(self, data):
37 | self._data = data
38 |
39 | @property
40 | def handle(self):
41 | return self._handle
42 |
43 | @handle.setter
44 | def handle(self, handle):
45 | self._handle = handle
46 |
47 |
--------------------------------------------------------------------------------
/spyne/util/_base.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | from time import mktime
21 | from datetime import datetime
22 |
23 | from spyne.util import memoize, six
24 |
25 |
26 | def utctime():
27 | return mktime(datetime.utcnow().timetuple())
28 |
29 |
30 | @memoize
31 | def get_version(package):
32 | if isinstance(package, (six.text_type, six.binary_type)):
33 | package = __import__(package)
34 |
35 | verstr = getattr(package, '__version__')
36 | retval = []
37 |
38 | for f in verstr.split("."):
39 | try:
40 | retval.append(int(f))
41 | except ValueError:
42 | retval.append(f)
43 |
44 | return tuple(retval)
45 |
--------------------------------------------------------------------------------
/examples/log.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from __future__ import absolute_import
4 |
5 | from spyne import Service, rpc, Application, Fault
6 | from spyne.server.null import NullServer
7 | from spyne.util.color import G
8 |
9 |
10 | class SomeService(Service):
11 | @rpc()
12 | def server_exception(ctx):
13 | raise Exception("boo!")
14 |
15 | @rpc()
16 | def server_fault(ctx):
17 | raise Fault("Server", "boo and you know it!")
18 |
19 | @rpc()
20 | def client_fault(ctx):
21 | raise Fault("Client", "zzzz...")
22 |
23 |
24 | server = NullServer(Application([SomeService], 'spyne.examples.logging'))
25 |
26 |
27 | if __name__ == "__main__":
28 | import logging
29 | logging.basicConfig(level=logging.DEBUG)
30 |
31 | logging.info(G("all fault tracebacks are logged"))
32 | logging.getLogger('spyne.application').setLevel(logging.DEBUG)
33 |
34 | try:
35 | server.service.server_exception()
36 | except:
37 | pass
38 | try:
39 | server.service.server_fault()
40 | except:
41 | pass
42 | try:
43 | server.service.client_fault()
44 | except:
45 | pass
46 |
47 | logging.info(G("client fault tracebacks are hidden"))
48 | logging.getLogger('spyne.application.client').setLevel(logging.CRITICAL)
49 | try:
50 | server.service.server_fault()
51 | except:
52 | pass
53 | try:
54 | server.service.client_fault()
55 | except:
56 | pass
57 |
--------------------------------------------------------------------------------
/spyne/util/cherry.py:
--------------------------------------------------------------------------------
1 | # Use Cherrypy as wsgi server.
2 | # Source: https://www.digitalocean.com/community/tutorials/how-to-deploy-python-wsgi-applications-using-a-cherrypy-web-server-behind-nginx
3 |
4 | import logging
5 | import cherrypy
6 |
7 |
8 | def cherry_graft_and_start(wsgi_application, host="0.0.0.0", port=8080,
9 | num_threads=30, ssl_module=None, cert=None, key=None, cacert=None):
10 |
11 | logging.basicConfig(level=logging.DEBUG)
12 | logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
13 |
14 | # Mount the application
15 | cherrypy.tree.graft(wsgi_application, "/")
16 |
17 | # Unsubscribe the default server
18 | cherrypy.server.unsubscribe()
19 |
20 | # Instantiate a new server object
21 | server = cherrypy._cpserver.Server()
22 |
23 | # Configure the server object
24 | server.socket_host = host
25 | server.socket_port = port
26 | server.thread_pool = num_threads
27 |
28 | # For SSL Support
29 | if ssl_module is not None:
30 | server.ssl_module = ssl_module # eg. 'pyopenssl'
31 | server.ssl_certificate = cert # eg. 'ssl/certificate.crt'
32 | server.ssl_private_key = key # eg. 'ssl/private.key'
33 | server.ssl_certificate_chain = cacert # eg. 'ssl/bundle.crt'
34 |
35 | # Subscribe this server
36 | server.subscribe()
37 |
38 | # Start the server engine (Option 1 *and* 2)
39 | cherrypy.engine.start()
40 |
41 | return cherrypy.engine.block()
42 |
--------------------------------------------------------------------------------
/spyne/store/relational/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """A Postgresql serializer for Spyne objects.
21 |
22 | Uses SQLAlchemy for mapping objects to relations.
23 | """
24 |
25 | from spyne.store.relational._base import add_column
26 | from spyne.store.relational._base import gen_sqla_info
27 | from spyne.store.relational._base import gen_spyne_info
28 | from spyne.store.relational._base import get_pk_columns
29 |
30 | from spyne.store.relational.document import PGXml, PGObjectXml, PGHtml, \
31 | PGJson, PGJsonB, PGObjectJson, PGFileJson
32 | from spyne.store.relational.simple import PGLTree, PGLQuery, PGLTxtQuery
33 | from spyne.store.relational.spatial import PGGeometry
34 |
35 | from spyne.store.relational import override
36 |
--------------------------------------------------------------------------------
/examples/template/README.rst:
--------------------------------------------------------------------------------
1 |
2 | About
3 | =====
4 |
5 | Spyne projects do not have to adhere to any specific file layout. However, the
6 | file layout in this example project seems to be quite tidy and comfortable to
7 | work with as most of the boilerplate for a propery Python project is already
8 | here.
9 |
10 | To start hacking on this project:
11 |
12 | #. Copy the template directory to a different folder.
13 |
14 | #. Do: ::
15 |
16 | find -name "*.py" | xargs sed -i s/template/your_project/g
17 | mv template your_project
18 |
19 | #. Tweak the requirements in setup.py according to the protocols and transports
20 | you choose to work with. You can look at Spyne's own README to see which
21 | protocol or transport requires which package.
22 |
23 | #. Tweak the database credentials and exception handling.
24 |
25 | #. Hack away!
26 |
27 | Installation
28 | ============
29 |
30 | 1. Bootstrap distribute if needed: ::
31 |
32 | wget http://python-distribute.org/distribute_setup.py
33 |
34 | (yes, wget, not ``curl | python`` because setup script tries to import it)
35 |
36 | 2. Run: ::
37 |
38 | python setup.py develop --user
39 |
40 | The template_daemon executable is now installed at $HOME/.local/bin. You
41 | may need to add that path to your $PATH.
42 |
43 | Usage
44 | =====
45 |
46 | 1. Run: ::
47 |
48 | template_deamon
49 |
50 | 2. In a separate console, run: ::
51 |
52 | curl "http://localhost:8000/put_user?user_user_name=jack&user_full_name=jack%20brown&user_email=jack@spyne.io"
53 | curl "http://localhost:8000/get_all_user"
54 |
--------------------------------------------------------------------------------
/examples/tfb/tfb.yaml:
--------------------------------------------------------------------------------
1 | ServiceDaemon:
2 | alert_dests: []
3 | autoreload: false
4 | daemonize: false
5 | debug: true
6 | debug_reactor: false
7 | file_version: 2
8 | log_cloth: false
9 | log_dbconn: false
10 | log_interface: false
11 | log_model: false
12 | log_orm: false
13 | log_protocol: false
14 | log_queries: false
15 | log_results: false
16 | log_rss: false
17 | log_sqlalchemy: false
18 | logger_dest_rotation_compression: gzip
19 | logger_dest_rotation_period: WEEKLY
20 | loggers:
21 | - Logger:
22 | level: ERROR
23 | path: .
24 | main_store: sql_main
25 | name: tfb
26 | services:
27 | - HttpServer:
28 | backlog: 50
29 | disabled: true
30 | host: 127.0.0.1
31 | name: root
32 | port: 8080
33 | subapps:
34 | - HttpApplication:
35 | url: ''
36 | type: tcp4
37 | stores:
38 | - RelationalStore:
39 | async_pool: true
40 | backend: sqlalchemy
41 | conn_str: postgresql://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world
42 | echo_pool: false
43 | max_overflow: 3
44 | name: sql_main
45 | pool_pre_ping: true
46 | pool_recycle: 3600
47 | pool_size: 10
48 | pool_timeout: 30
49 | pool_use_lifo: false
50 | sync_case_sensitive: false
51 | sync_pool: true
52 | sync_pool_type: QueuePool
53 | uuid: fef52ff8-3103-11e9-b0e1-5453edabe249
54 |
--------------------------------------------------------------------------------
/spyne/test/interop/test_soap_client_http.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import unittest
21 |
22 | from spyne.client.http import HttpClient
23 | from spyne.test.interop._test_soap_client_base import SpyneClientTestBase, \
24 | server_started
25 | from spyne.test.interop.server.soap11.soap_http_basic import soap11_application
26 |
27 | class TestSpyneHttpClient(SpyneClientTestBase, unittest.TestCase):
28 | def setUp(self):
29 | SpyneClientTestBase.setUp(self, 'http')
30 |
31 | port, = server_started.keys()
32 |
33 | self.client = HttpClient('http://localhost:%d/' % port,
34 | soap11_application)
35 | self.ns = "spyne.test.interop.server"
36 |
37 |
38 | if __name__ == '__main__':
39 | unittest.main()
40 |
--------------------------------------------------------------------------------
/spyne/test/interop/test_soap_client_zeromq.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import unittest
21 |
22 | from spyne.client.zeromq import ZeroMQClient
23 |
24 | from spyne.test.interop._test_soap_client_base import SpyneClientTestBase, \
25 | server_started
26 | from spyne.test.interop.server.soap11.soap_http_basic import soap11_application
27 |
28 |
29 | class TestSpyneZmqClient(SpyneClientTestBase, unittest.TestCase):
30 | def setUp(self):
31 | SpyneClientTestBase.setUp(self, 'zeromq')
32 |
33 | port, = server_started.keys()
34 |
35 | self.client = ZeroMQClient('tcp://localhost:%d' % port,
36 | soap11_application)
37 | self.ns = "spyne.test.interop.server._service"
38 |
39 |
40 | if __name__ == '__main__':
41 | unittest.main()
42 |
--------------------------------------------------------------------------------
/examples/flask/apps/__init__.py:
--------------------------------------------------------------------------------
1 | # encoding: utf8
2 | #
3 | # Copyright © Anton Egorov
4 | # All rights reserved.
5 | #
6 | # Redistribution and use in source and binary forms, with or without
7 | # modification, are permitted provided that the following conditions are met:
8 | #
9 | # 1. Redistributions of source code must retain the above copyright notice,
10 | # this list of conditions and the following disclaimer.
11 | # 2. Redistributions in binary form must reproduce the above copyright
12 | # notice, this list of conditions and the following disclaimer in the
13 | # documentation and/or other materials provided with the distribution.
14 | # 3. Neither the name of the owner nor the names of its contributors may be
15 | # used to endorse or promote products derived from this software without
16 | # specific prior written permission.
17 | #
18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
22 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | #
29 |
--------------------------------------------------------------------------------
/spyne/protocol/html/__init__.py:
--------------------------------------------------------------------------------
1 | # encoding: utf8
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """
21 | This package contains some basic html output protocols.
22 | """
23 |
24 | from spyne.protocol.html._base import HtmlBase
25 | from spyne.protocol.html._base import HtmlCloth
26 | from spyne.protocol.html._base import parse_html_fragment_file
27 | from spyne.protocol.html.table import HtmlColumnTable
28 | from spyne.protocol.html.table import HtmlRowTable
29 | from spyne.protocol.html.microformat import HtmlMicroFormat
30 | from spyne.protocol.html.addtl import PrettyFormat
31 | from spyne.protocol.html.addtl import BooleanListProtocol
32 |
33 |
34 | # FIXME: REMOVE ME
35 | def translate(cls, locale, default):
36 | retval = None
37 | if cls.Attributes.translations is not None:
38 | retval = cls.Attributes.translations.get(locale, None)
39 | if retval is None:
40 | return default
41 | return retval
42 |
--------------------------------------------------------------------------------
/doc/source/index.rst:
--------------------------------------------------------------------------------
1 |
2 | ###################
3 | Spyne Documentation
4 | ###################
5 |
6 | Actually, Spyne 2.11 docs are not quite done yet.
7 |
8 | Spyne 2.11 has been in the making for more than a year and received around 1400
9 | commits on top of the 2.10 branch.
10 |
11 | So the documentation is a huge TBD at the moment. There's the migration guide,
12 | the changelog and that's that.
13 |
14 | Yet, we tried very hard to keep backwards compatibility. Which means your
15 | existing (correct) code should work without any changes with 2.11. Which in turn
16 | means you can safely refer to the 2.10 docs, they're still quite relevant.
17 |
18 | Don't forget to read the migration guide first if you're migrating from 2.10 to
19 | 2.11 though, there were still some changes that can break existing code.
20 |
21 | But most important of it all, Have fun!
22 |
23 | PS: Feedback about the docs are pure gold to us, simply because the most
24 | important thing the Spyne committers lack is an outside perspective to the
25 | project. Please do not hesitate to get in touch with us via people@spyne.io
26 |
27 | PPS: Why did we not publish 2.11 docs verbatim and update it along the way?
28 | Because we *hate* broken documentation links.
29 |
30 | ###############
31 | Getting Started
32 | ###############
33 |
34 | .. include:: ../../README.rst
35 |
36 | #####################
37 | Library Documentation
38 | #####################
39 |
40 | TBD. In the mean time, check out the 2.10 docs:
41 | http://spyne.io/docs/2.10/#library-documentation
42 |
43 | #############
44 | Other Goodies
45 | #############
46 |
47 | .. toctree::
48 | :maxdepth: 2
49 |
50 | tests
51 | faq
52 | history
53 | migration
54 | contributing
55 |
--------------------------------------------------------------------------------
/examples/django/rpctest/__init__.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © BJ Cardon ,
5 | # All rights reserved.
6 | #
7 | # Redistribution and use in source and binary forms, with or without
8 | # modification, are permitted provided that the following conditions are met:
9 | #
10 | # 1. Redistributions of source code must retain the above copyright notice,
11 | # this list of conditions and the following disclaimer.
12 | # 2. Redistributions in binary form must reproduce the above copyright
13 | # notice, this list of conditions and the following disclaimer in the
14 | # documentation and/or other materials provided with the distribution.
15 | # 3. Neither the name of the owner nor the names of its contributors may be
16 | # used to endorse or promote products derived from this software without
17 | # specific prior written permission.
18 | #
19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
23 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | #
30 |
--------------------------------------------------------------------------------
/examples/flask/settings.py:
--------------------------------------------------------------------------------
1 | # encoding: utf8
2 | #
3 | # Copyright © Anton Egorov
4 | # All rights reserved.
5 | #
6 | # Redistribution and use in source and binary forms, with or without
7 | # modification, are permitted provided that the following conditions are met:
8 | #
9 | # 1. Redistributions of source code must retain the above copyright notice,
10 | # this list of conditions and the following disclaimer.
11 | # 2. Redistributions in binary form must reproduce the above copyright
12 | # notice, this list of conditions and the following disclaimer in the
13 | # documentation and/or other materials provided with the distribution.
14 | # 3. Neither the name of the owner nor the names of its contributors may be
15 | # used to endorse or promote products derived from this software without
16 | # specific prior written permission.
17 | #
18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
22 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | #
29 |
30 | DEBUG = True
31 | HELLO = 'World'
32 |
--------------------------------------------------------------------------------
/spyne/interface/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 |
21 | """The ``spyne.interface`` package contains implementations of various interface
22 | definition document standards along with the
23 | :class:`spyne.interface.Interface` class which holds all the information needed
24 | to generate those documents.
25 | """
26 |
27 |
28 | from __future__ import print_function
29 |
30 | from spyne.interface._base import Interface
31 | from spyne.interface._base import InterfaceDocumentBase
32 | from spyne.interface._base import InterfaceDocumentsBase
33 | from spyne.interface._base import InterfaceDocuments
34 |
35 |
36 | try:
37 | from spyne.interface.xml_schema import XmlSchema
38 | from spyne.interface.wsdl.wsdl11 import Wsdl11
39 | HAS_WSDL = True
40 |
41 | except ImportError as e:
42 | if 'No module named lxml' in e.args or "No module named 'lxml'" in e.args:
43 | HAS_WSDL = False
44 | else:
45 | raise
46 |
--------------------------------------------------------------------------------
/spyne/test/model/test_binary.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import unittest
21 | from lxml import etree
22 |
23 | from spyne.protocol.soap import Soap11
24 | from spyne.model.binary import ByteArray
25 | from spyne.model.binary import _bytes_join
26 | import spyne.const.xml
27 |
28 | ns_xsd = spyne.const.xml.NS_XSD
29 | ns_test = 'test_namespace'
30 |
31 |
32 | class TestBinary(unittest.TestCase):
33 | def setUp(self):
34 | self.data = bytes(bytearray(range(0xff)))
35 |
36 | def test_data(self):
37 | element = etree.Element('test')
38 | Soap11().to_parent(None, ByteArray, [self.data], element, ns_test)
39 | print(etree.tostring(element, pretty_print=True))
40 | element = element[0]
41 |
42 | a2 = Soap11().from_element(None, ByteArray, element)
43 | self.assertEqual(self.data, _bytes_join(a2))
44 |
45 | if __name__ == '__main__':
46 | unittest.main()
47 |
--------------------------------------------------------------------------------
/spyne/_base.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logger = logging.getLogger('spyne')
22 |
23 | from collections import namedtuple
24 |
25 | # When spyne.server.twisted gets imported, this type gets a static method named
26 | # `from_twisted_address`. Dark magic.
27 | Address = namedtuple("Address", ["type", "host", "port"])
28 |
29 |
30 | class _add_address_types():
31 | Address.TCP4 = 'TCP4'
32 | Address.TCP6 = 'TCP6'
33 | Address.UDP4 = 'UDP4'
34 | Address.UDP6 = 'UDP6'
35 |
36 | def address_str(self):
37 | return ":".join((self.type, self.host, str(self.port)))
38 |
39 | Address.__str__ = address_str
40 |
41 | # this gets overwritten once spyne.server.twisted is imported
42 | @staticmethod
43 | def _fta(*a, **kw):
44 | from spyne.server.twisted._base import _address_from_twisted_address
45 | return _address_from_twisted_address(*a, **kw)
46 |
47 | Address.from_twisted_address = _fta
48 |
--------------------------------------------------------------------------------
/spyne/test/interface/wsdl/defult_services.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 |
21 | from spyne.model.primitive import String
22 | from spyne.service import Service
23 | from spyne.decorator import rpc
24 |
25 |
26 | def TDefaultPortService():
27 | class DefaultPortService(Service):
28 | @rpc(String, _returns=String)
29 | def echo_default_port_service(self, string):
30 | return string
31 |
32 | return DefaultPortService
33 |
34 |
35 | def TDefaultPortServiceMultipleMethods():
36 | class DefaultPortServiceMultipleMethods(Service):
37 | @rpc(String, _returns=String)
38 | def echo_one(self, string):
39 | return string
40 |
41 | @rpc(String, _returns=String)
42 | def echo_two(self, string):
43 | return string
44 |
45 | @rpc(String, _returns=String)
46 | def echo_three(self, string):
47 | return string
48 |
49 | return DefaultPortServiceMultipleMethods
50 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap12/soap_zeromq.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 |
22 | from spyne.test.interop.server.soap12.soap_http_basic import soap12_application
23 |
24 | from spyne.server.zeromq import ZeroMQServer
25 |
26 | host = '127.0.0.1'
27 | port = 55555
28 |
29 | def main():
30 | url = "tcp://%s:%d" % (host,port)
31 |
32 | logging.basicConfig(level=logging.DEBUG)
33 | logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
34 |
35 | server = ZeroMQServer(soap12_application, url)
36 | logging.info("************************")
37 | logging.info("Use Ctrl+\\ to exit if Ctrl-C does not work.")
38 | logging.info("See the 'I can't Ctrl-C my Python/Ruby application. Help!' "
39 | "question in http://www.zeromq.org/area:faq for more info.")
40 | logging.info("listening on %r" % url)
41 | logging.info("************************")
42 |
43 | server.serve_forever()
44 |
45 | if __name__ == '__main__':
46 | main()
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap12/soap_http_basic_twisted.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logging.basicConfig(level=logging.DEBUG)
22 | logger = logging.getLogger('spyne.wsgi')
23 | logger.setLevel(logging.DEBUG)
24 |
25 | from spyne.test.interop.server.soap12.soap_http_basic import soap12_application
26 | from spyne.server.twisted import TwistedWebResource
27 |
28 | host = '127.0.0.1'
29 | port = 9755
30 |
31 | def main(argv):
32 | from twisted.web.server import Site
33 | from twisted.internet import reactor
34 | from twisted.python import log
35 |
36 | observer = log.PythonLoggingObserver('twisted')
37 | log.startLoggingWithObserver(observer.emit, setStdout=False)
38 |
39 | wr = TwistedWebResource(soap12_application)
40 | site = Site(wr)
41 |
42 | reactor.listenTCP(port, site)
43 | logging.info("listening on: %s:%d" % (host,port))
44 |
45 | return reactor.run()
46 |
47 | if __name__ == '__main__':
48 | import sys
49 | sys.exit(main(sys.argv))
50 |
--------------------------------------------------------------------------------
/examples/tfb/nginx.conf:
--------------------------------------------------------------------------------
1 | # This file is based on /usr/local/nginx/conf/nginx.conf.default.
2 |
3 | # One worker process per core
4 | error_log stderr error;
5 |
6 | events {
7 | # This needed to be increased because the nginx error log said so.
8 | # http://nginx.org/en/docs/ngx_core_module.html#worker_connections
9 | worker_connections 65535;
10 | multi_accept on;
11 | }
12 |
13 | http {
14 | default_type application/octet-stream;
15 | client_body_temp_path /tmp;
16 |
17 | # turn off request logging for performance
18 | access_log off;
19 |
20 | # I think these only options affect static file serving
21 | sendfile on;
22 | tcp_nopush on;
23 |
24 | # Allow many HTTP Keep-Alive requests in a single TCP connection before
25 | # closing it (the default is 100). This will minimize the total number
26 | # of TCP connections opened/closed. The problem is that this may cause
27 | # some worker processes to be handling too connections relative to the
28 | # other workers based on an initial imbalance, so this is disabled for
29 | # now.
30 | # keepalive_requests 1000;
31 |
32 | #keepalive_timeout 0;
33 | keepalive_timeout 65;
34 |
35 | server {
36 | # For information on deferred, see:
37 | # http://nginx.org/en/docs/http/ngx_http_core_module.html#listen
38 | # http://www.techrepublic.com/article/take-advantage-of-tcp-ip-options-to-optimize-data-transmission/
39 | # The backlog argument to listen() is set to match net.ipv4.tcp_max_syn_backlog and net.core.somaxconn
40 | listen 8080 default_server deferred reuseport backlog=65535;
41 | server_name localhost;
42 |
43 | location / {
44 | uwsgi_pass unix:/var/tmp/uwsgi.sock;
45 | include /usr/local/nginx/conf/uwsgi_params;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/spyne/auxproc/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The ``spyne.auxproc`` package contains backends to process auxiliary method
21 | contexts.
22 |
23 | "Auxiliary Methods" are methods that run asyncronously once the
24 | primary method returns (either successfully or not). There can be only one
25 | primary method for a given method identifier but zero or more auxiliary methods.
26 |
27 | To define multiple auxiliary methods for a given main method, you must use
28 | separate :class:`Service` subclasses that you pass to the
29 | :class:`spyne.application.Application` constructor.
30 |
31 | Auxiliary methods are a useful abstraction for a variety of asyncronous
32 | execution methods like persistent or non-persistent queueing, async execution
33 | in another thread, process or node.
34 |
35 | Classes from this package will have the ``AuxProc`` suffix, short for
36 | "Auxiliary Processor".
37 |
38 | This package is DEPRECATED. Get rid of this ASAP.
39 | """
40 |
41 | from spyne.auxproc._base import process_contexts
42 | from spyne.auxproc._base import AuxProcBase
43 |
--------------------------------------------------------------------------------
/spyne/test/interop/test_msgpackrpc_client_http.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import unittest
21 |
22 | from spyne.client.http import HttpClient
23 | from spyne.test.interop._test_soap_client_base import SpyneClientTestBase
24 | from spyne.test.interop.server.msgpackrpc_http_basic import msgpackrpc_application, port
25 | from spyne.util.etreeconv import root_dict_to_etree
26 |
27 | class TestSpyneHttpClient(SpyneClientTestBase, unittest.TestCase):
28 | def setUp(self):
29 | SpyneClientTestBase.setUp(self, 'msgpack_rpc_http')
30 |
31 | self.client = HttpClient('http://localhost:%d/' % port[0],
32 | msgpackrpc_application)
33 | self.ns = "spyne.test.interop.server"
34 |
35 | @unittest.skip("MessagePackRpc does not support header")
36 | def test_echo_in_header(self):
37 | pass
38 |
39 | @unittest.skip("MessagePackRpc does not support header")
40 | def test_send_out_header(self):
41 | pass
42 |
43 |
44 | if __name__ == '__main__':
45 | unittest.main()
46 |
--------------------------------------------------------------------------------
/examples/xml/polymorphic_roundtrip.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | from __future__ import print_function, unicode_literals
4 |
5 | import sys
6 |
7 | from lxml import etree
8 | from spyne.interface.xml_schema.parser import hier_repr
9 |
10 | from spyne.util import six
11 | from spyne import ComplexModel, Unicode
12 | from spyne.util.xml import get_object_as_xml_polymorphic, \
13 | get_xml_as_object_polymorphic
14 |
15 |
16 | # uncomment to see what's going on under the hood
17 | # import logging
18 | # logging.basicConfig(level=logging.DEBUG,
19 | # format='%(levelname)-7s %(module)12s:%(lineno)-4d | %(message)s')
20 |
21 |
22 | class B(ComplexModel):
23 | __namespace__ = 'some_ns'
24 | _type_info = {
25 | '_b': Unicode,
26 | }
27 |
28 | def __init__(self):
29 | super(B, self).__init__()
30 | self._b = "b"
31 |
32 |
33 | class C(B):
34 | __namespace__ = 'some_ns'
35 | _type_info = {
36 | '_c': Unicode,
37 | }
38 |
39 | def __init__(self):
40 | super(C, self).__init__()
41 | self._c = "c"
42 |
43 |
44 | class A(ComplexModel):
45 | __namespace__ = 'some_ns'
46 | _type_info = {
47 | '_a': Unicode,
48 | '_b': B,
49 | }
50 |
51 | def __init__(self, b=None):
52 | super(A, self).__init__()
53 | self._a = 'a'
54 | self._b = b
55 |
56 |
57 | a = A(b=C())
58 | elt = get_object_as_xml_polymorphic(a, A)
59 | xml_string = etree.tostring(elt, pretty_print=True)
60 | if six.PY2:
61 | print(xml_string, end="")
62 | else:
63 | sys.stdout.buffer.write(xml_string)
64 |
65 | element_tree = etree.fromstring(xml_string)
66 | new_a = get_xml_as_object_polymorphic(elt, A)
67 |
68 | assert new_a._a == a._a, (a._a, new_a._a)
69 | assert new_a._b._b == a._b._b, (a._b._b, new_a._b._b)
70 | assert new_a._b._c == a._b._c, (a._b._c, new_a._b._c)
71 |
72 | print(hier_repr(new_a))
73 |
--------------------------------------------------------------------------------
/examples/template/template/context.py:
--------------------------------------------------------------------------------
1 | # encoding: utf8
2 | #
3 | # Copyright © Burak Arslan ,
4 | # Arskom Ltd. http://www.arskom.com.tr
5 | # All rights reserved.
6 | #
7 | # Redistribution and use in source and binary forms, with or without
8 | # modification, are permitted provided that the following conditions are met:
9 | #
10 | # 1. Redistributions of source code must retain the above copyright notice,
11 | # this list of conditions and the following disclaimer.
12 | # 2. Redistributions in binary form must reproduce the above copyright
13 | # notice, this list of conditions and the following disclaimer in the
14 | # documentation and/or other materials provided with the distribution.
15 | # 3. Neither the name of the owner nor the names of its contributors may be
16 | # used to endorse or promote products derived from this software without
17 | # specific prior written permission.
18 | #
19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
23 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | #
30 |
31 | from template.db import Session
32 |
33 | class UserDefinedContext(object):
34 | def __init__(self):
35 | self.session = Session()
36 |
--------------------------------------------------------------------------------
/spyne/client/zeromq.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The ZeroMQ (zmq.REQ) client transport."""
21 |
22 | import zmq
23 |
24 | from spyne import RemoteService, ClientBase, RemoteProcedureBase
25 |
26 | context = zmq.Context()
27 |
28 |
29 | class _RemoteProcedure(RemoteProcedureBase):
30 | def __call__(self, *args, **kwargs):
31 | self.ctx = self.contexts[0]
32 |
33 | self.get_out_object(self.ctx, args, kwargs)
34 | self.get_out_string(self.ctx)
35 | out_string = b''.join(self.ctx.out_string)
36 |
37 | socket = context.socket(zmq.REQ)
38 | socket.connect(self.url)
39 | socket.send(out_string)
40 |
41 | self.ctx.in_string = [socket.recv()]
42 | self.get_in_object(self.ctx)
43 |
44 | if not (self.ctx.in_error is None):
45 | raise self.ctx.in_error
46 | else:
47 | return self.ctx.in_object
48 |
49 |
50 | class ZeroMQClient(ClientBase):
51 | def __init__(self, url, app):
52 | super(ZeroMQClient, self).__init__(url, app)
53 |
54 | self.service = RemoteService(_RemoteProcedure, url, app)
55 |
--------------------------------------------------------------------------------
/examples/zeromq/client.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | from app import app
33 | from spyne.client.zeromq import ZeroMQClient
34 |
35 | c = ZeroMQClient('tcp://localhost:5001', app)
36 | print c.service.whoami()
37 |
--------------------------------------------------------------------------------
/examples/helloworld_soap_suds_client.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | from suds.client import Client
33 |
34 | client = Client('http://localhost:8000/?wsdl', cache=None)
35 |
36 | print(client.service.say_hello(u'Jérôme', 5))
37 |
--------------------------------------------------------------------------------
/examples/testing/helloworld_null.py:
--------------------------------------------------------------------------------
1 |
2 | '''
3 | This is a simple HelloWorld example showing how the NullServer works. The
4 | NullServer is meant to be used mainly for testing.
5 | '''
6 |
7 | import logging
8 | logging.basicConfig(level=logging.INFO)
9 |
10 | from pprint import pprint
11 |
12 | from spyne.application import Application
13 | from spyne.protocol.soap import Soap11
14 | from spyne.server.null import NullServer
15 |
16 | from spyne.decorator import rpc
17 | from spyne.service import Service
18 | from spyne.model.complex import Iterable
19 | from spyne.model.primitive import Integer
20 | from spyne.model.primitive import Unicode
21 |
22 |
23 | class HelloWorldService(Service):
24 | @rpc(Unicode, Integer, _returns=Iterable(Unicode))
25 | def say_hello(ctx, name, times):
26 | for i in range(times):
27 | yield u'Hello, %s' % name
28 |
29 |
30 | if __name__=='__main__':
31 | application = Application([HelloWorldService], 'spyne.examples.hello.soap',
32 | in_protocol=Soap11(validator='lxml'),
33 | out_protocol=Soap11(pretty_print=True),
34 | )
35 |
36 | # disables context markers. set logging level to logging.INFO to enable
37 | # them.
38 | logging.getLogger('spyne.server.null').setLevel(logging.CRITICAL)
39 |
40 | print("With serialization")
41 | print("==================")
42 | print()
43 |
44 | null = NullServer(application, ostr=True)
45 | ret_stream = null.service.say_hello('Dave', 5)
46 | ret_string = ''.join(i.decode() for i in ret_stream)
47 | print(ret_string)
48 | print()
49 |
50 | print("Without serialization")
51 | print("=====================")
52 | print()
53 |
54 | null = NullServer(application, ostr=False)
55 | ret = null.service.say_hello('Dave', 5)
56 | # because the return value is a generator, we need to iterate over it to
57 | # see the actual return values.
58 | pprint(list(ret))
59 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap11/soap_zeromq.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 |
22 | from spyne.test.interop.server import get_open_port
23 | from spyne.test.interop.server.soap11.soap_http_basic import soap11_application
24 |
25 | from spyne.server.zeromq import ZeroMQServer
26 |
27 |
28 | host = '127.0.0.1'
29 | port = [0]
30 |
31 |
32 | def main():
33 | if port[0] == 0:
34 | port[0] = get_open_port()
35 | url = "tcp://%s:%d" % (host, port[0])
36 |
37 | logging.basicConfig(level=logging.DEBUG)
38 | logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
39 |
40 | server = ZeroMQServer(soap11_application, url)
41 | logging.info("************************")
42 | logging.info("Use Ctrl+\\ to exit if Ctrl-C does not work.")
43 | logging.info("See the 'I can't Ctrl-C my Python/Ruby application. Help!' "
44 | "question in http://www.zeromq.org/area:faq for more info.")
45 | logging.info("listening on %r" % url)
46 | logging.info("************************")
47 |
48 | server.serve_forever()
49 |
50 |
51 | if __name__ == '__main__':
52 | main()
--------------------------------------------------------------------------------
/spyne/protocol/html/addtl.py:
--------------------------------------------------------------------------------
1 | # encoding: utf8
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | from lxml.builder import E
21 | from pprint import pformat
22 |
23 | from spyne import Boolean
24 | from spyne.protocol.html import HtmlBase
25 |
26 |
27 | class PrettyFormat(HtmlBase):
28 | def to_parent(self, ctx, cls, inst, parent, name, **kwargs):
29 | parent.write(E.pre(pformat(inst)))
30 |
31 |
32 | class BooleanListProtocol(HtmlBase):
33 | def __init__(self, nothing=None):
34 | super(BooleanListProtocol, self).__init__()
35 |
36 | self.nothing = nothing
37 |
38 | def to_parent(self, ctx, cls, inst, parent, name, nosubprot=False, **kwargs):
39 | if inst is None:
40 | return
41 |
42 | wrote_nothing = True
43 | for k, v in cls.get_flat_type_info(cls).items():
44 | if not issubclass(v, Boolean):
45 | continue
46 |
47 | if getattr(inst, k, False):
48 | parent.write(E.p(self.trc(cls, ctx.locale, k)))
49 | wrote_nothing = False
50 |
51 | if wrote_nothing and self.nothing is not None:
52 | parent.write(E.p(self.nothing))
53 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap11/soap_http_basic_twisted.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logging.basicConfig(level=logging.DEBUG)
22 | logger = logging.getLogger('spyne.wsgi')
23 | logger.setLevel(logging.DEBUG)
24 |
25 | from spyne.test.interop.server import get_open_port
26 | from spyne.test.interop.server.soap_http_basic import soap11_application
27 | from spyne.server.twisted import TwistedWebResource
28 |
29 |
30 | host = '127.0.0.1'
31 | port = [0]
32 |
33 |
34 | def main(argv):
35 | from twisted.web.server import Site
36 | from twisted.internet import reactor
37 | from twisted.python import log
38 |
39 | observer = log.PythonLoggingObserver('twisted')
40 | log.startLoggingWithObserver(observer.emit, setStdout=False)
41 |
42 | wr = TwistedWebResource(soap11_application)
43 | site = Site(wr)
44 |
45 | if port[0] == 0:
46 | port[0] = get_open_port()
47 | reactor.listenTCP(port[0], site)
48 | logging.info("listening on: %s:%d" % (host,port[0]))
49 |
50 | return reactor.run()
51 |
52 | if __name__ == '__main__':
53 | import sys
54 | sys.exit(main(sys.argv))
55 |
--------------------------------------------------------------------------------
/examples/template/template/test/test_sample.py:
--------------------------------------------------------------------------------
1 | # encoding: utf8
2 | #
3 | # Copyright © Burak Arslan ,
4 | # Arskom Ltd. http://www.arskom.com.tr
5 | # All rights reserved.
6 | #
7 | # Redistribution and use in source and binary forms, with or without
8 | # modification, are permitted provided that the following conditions are met:
9 | #
10 | # 1. Redistributions of source code must retain the above copyright notice,
11 | # this list of conditions and the following disclaimer.
12 | # 2. Redistributions in binary form must reproduce the above copyright
13 | # notice, this list of conditions and the following disclaimer in the
14 | # documentation and/or other materials provided with the distribution.
15 | # 3. Neither the name of the owner nor the names of its contributors may be
16 | # used to endorse or promote products derived from this software without
17 | # specific prior written permission.
18 | #
19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
23 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | #
30 |
31 |
32 | import unittest
33 |
34 | class TestSample(unittest.TestCase):
35 | def test_sample(self):
36 | assert False
37 |
38 |
39 | if __name__ == '__main__':
40 | unittest.main()
41 |
--------------------------------------------------------------------------------
/spyne/auxproc/thread.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logger = logging.getLogger(__name__)
22 |
23 | from multiprocessing.pool import ThreadPool
24 |
25 | from spyne.auxproc import AuxProcBase
26 |
27 |
28 | class ThreadAuxProc(AuxProcBase):
29 | """ThreadAuxProc processes auxiliary methods asynchronously in another
30 | thread using the undocumented ``multiprocessing.pool.ThreadPool`` class.
31 | This is available in Python 2.7. It's possibly there since 2.6 as well but
32 | it's hard to tell since it's not documented.
33 |
34 | :param pool_size: Max. number of threads that can be used to process
35 | methods in auxiliary queue in parallel.
36 | """
37 |
38 | def __init__(self, pool_size=1):
39 | super(ThreadAuxProc, self).__init__()
40 |
41 | self.pool = None
42 | self.__pool_size = pool_size
43 |
44 | @property
45 | def pool_size(self):
46 | return self.__pool_size
47 |
48 | def process_context(self, server, ctx, *args, **kwargs):
49 | self.pool.apply_async(self.process, (server, ctx) + args, kwargs)
50 |
51 | def initialize(self, server):
52 | self.pool = ThreadPool(self.__pool_size)
53 |
--------------------------------------------------------------------------------
/examples/xml/soap12-mtom/soap12_mtom.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import logging
4 | logger = logging.getLogger(__name__)
5 |
6 | import os
7 | logging.basicConfig(level=logging.DEBUG)
8 | logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
9 |
10 | from spyne.application import Application
11 | from spyne.decorator import rpc
12 | from spyne.service import ServiceBase
13 | from spyne.model.complex import ComplexModel
14 | from spyne.model.binary import ByteArray
15 | from spyne.model.primitive import Unicode
16 | from spyne.server.wsgi import WsgiApplication
17 | from spyne.protocol.soap import Soap12
18 |
19 |
20 | tns = 'http://gib.gov.tr/vedop3/eFatura'
21 |
22 |
23 | class documentResponse(ComplexModel):
24 | msg = Unicode
25 | hash = ByteArray
26 |
27 |
28 | class GIBSoapService(ServiceBase):
29 | @rpc(Unicode(sub_name="fileName"), ByteArray(sub_name='binaryData'),
30 | ByteArray(sub_name="hash"), _returns=documentResponse)
31 | def documentRequest(ctx, file_name, file_data, data_hash):
32 | incoming_invoice_dir = os.getcwd()
33 |
34 | logger.info("file_name %r" % file_name)
35 | logger.info("file_hash: %r" % data_hash)
36 |
37 | path = os.path.join(incoming_invoice_dir, file_name)
38 |
39 | f = open(path, 'wb')
40 | for data in file_data:
41 | f.write(data)
42 | logger.info("File written: %r" % file_name)
43 | f.close()
44 |
45 | resp = documentResponse()
46 | resp.msg = "Document was written successfully"
47 | resp.hash = data_hash
48 |
49 | return resp
50 |
51 |
52 | application = Application([GIBSoapService], tns=tns,
53 | in_protocol=Soap12(),
54 | out_protocol=Soap12())
55 |
56 |
57 | gib_application = WsgiApplication(application)
58 |
59 |
60 | from wsgiref.simple_server import make_server
61 |
62 |
63 | server = make_server('0.0.0.0', 8000, gib_application)
64 | server.serve_forever()
65 |
--------------------------------------------------------------------------------
/examples/zeromq/server.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | import logging
33 |
34 | from app import app
35 | from spyne.server.zeromq import ZeroMQServer
36 |
37 | URL = "tcp://127.0.0.1:5001"
38 | logging.info("Listening to %r", URL)
39 |
40 | s = ZeroMQServer(app, URL)
41 | s.serve_forever()
42 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap12/httprpc_soap_basic.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logging.basicConfig(level=logging.DEBUG)
22 | logger = logging.getLogger('spyne.protocol.xml')
23 | logger.setLevel(logging.DEBUG)
24 |
25 | from spyne.application import Application
26 | from spyne.test.interop.server._service import services
27 | from spyne.protocol.http import HttpRpc
28 | from spyne.protocol.soap import Soap12
29 | from spyne.server.wsgi import WsgiApplication
30 |
31 | httprpc_soap_application = Application(services,
32 | 'spyne.test.interop.server.httprpc.soap', in_protocol=HttpRpc(), out_protocol=Soap12())
33 |
34 | host = '127.0.0.1'
35 | port = 9753
36 |
37 | if __name__ == '__main__':
38 | try:
39 | from wsgiref.simple_server import make_server
40 | from wsgiref.validate import validator
41 |
42 | wsgi_application = WsgiApplication(httprpc_soap_application)
43 | server = make_server(host, port, validator(wsgi_application))
44 |
45 | logger.info('Starting interop server at %s:%s.' % ('0.0.0.0', 9753))
46 | logger.info('WSDL is at: /?wsdl')
47 | server.serve_forever()
48 |
49 | except ImportError:
50 | print("Error: example server code requires Python >= 2.5")
51 |
--------------------------------------------------------------------------------
/spyne/protocol/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The ``spyne.protocol`` package contains the
21 | :class:`spyne.protocol.ProtocolBase`` abstract base class. Every protocol
22 | implementation is a subclass of ``ProtocolBase``.
23 | """
24 |
25 | from spyne.protocol._base import ProtocolMixin
26 | from spyne.protocol._inbase import InProtocolBase
27 | from spyne.protocol._outbase import OutProtocolBase
28 |
29 |
30 | class ProtocolBase(InProtocolBase, OutProtocolBase):
31 | def __init__(self, app=None, validator=None, mime_type=None,
32 | ignore_uncap=False, ignore_wrappers=False, binary_encoding=None,
33 | string_encoding='utf8'):
34 |
35 | InProtocolBase.__init__(self, app=app, validator=validator,
36 | mime_type=mime_type, ignore_wrappers=ignore_wrappers,
37 | binary_encoding=binary_encoding)
38 |
39 | OutProtocolBase.__init__(self, app=app, mime_type=mime_type,
40 | ignore_wrappers=ignore_wrappers, ignore_uncap=ignore_uncap,
41 | binary_encoding=binary_encoding)
42 |
43 | self.default_string_encoding = string_encoding
44 | self.ignore_empty_faultactor = True
45 |
--------------------------------------------------------------------------------
/spyne/test/protocol/test_yaml.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import unittest
21 |
22 | from spyne.test.protocol._test_dictdoc import TDictDocumentTest
23 | from spyne.protocol.yaml import YamlDocument
24 |
25 | from spyne import MethodContext
26 | from spyne.application import Application
27 | from spyne.decorator import srpc
28 | from spyne.service import Service
29 | from spyne.server import ServerBase
30 |
31 | from spyne.protocol.yaml import yaml
32 | yaml.dumps = yaml.dump
33 | yaml.loads = yaml.load
34 |
35 | TestYamlDocument = TDictDocumentTest(yaml, YamlDocument, YamlDocument().out_kwargs)
36 |
37 |
38 | class Test(unittest.TestCase):
39 | def test_invalid_input(self):
40 | class SomeService(Service):
41 | @srpc()
42 | def yay():
43 | pass
44 |
45 | app = Application([SomeService], 'tns',
46 | in_protocol=YamlDocument(),
47 | out_protocol=YamlDocument())
48 |
49 | server = ServerBase(app)
50 |
51 | initial_ctx = MethodContext(server, MethodContext.SERVER)
52 | initial_ctx.in_string = [b'{']
53 | ctx, = server.generate_contexts(initial_ctx)
54 | assert ctx.in_error.faultcode == 'Client.YamlDecodeError'
55 |
56 |
57 | if __name__ == '__main__':
58 | unittest.main()
59 |
--------------------------------------------------------------------------------
/examples/tfb/benchmark_config.json:
--------------------------------------------------------------------------------
1 | {
2 | "framework": "spyne",
3 | "tests": [{
4 | "default": {
5 | "json_url": "/json",
6 | "db_url": "/db",
7 | "query_url": "/dbs?queries=",
8 | "fortune_url": "/fortunes",
9 | "update_url": "/updates?queries=",
10 | "plaintext_url": "/plaintext",
11 | "port": 8080,
12 | "approach": "Realistic",
13 | "classification": "Micro",
14 | "database": "postgres",
15 | "framework": "spyne",
16 | "language": "Python",
17 | "flavor": "Python3",
18 | "orm": "Full",
19 | "platform": "Spyne",
20 | "webserver": "None",
21 | "os": "Linux",
22 | "database_os": "Linux",
23 | "display_name": "Spyne",
24 | "notes": "",
25 | "versus": "wsgi"
26 | },
27 | "raw": {
28 | "db_url": "/dbraw",
29 | "query_url": "/dbsraw?queries=",
30 | "fortune_url": "/fortunesraw",
31 | "update_url": "/updatesraw?queries=",
32 | "port": 8080,
33 | "approach": "Realistic",
34 | "classification": "Micro",
35 | "database": "postgres",
36 | "framework": "spyne",
37 | "language": "Python",
38 | "flavor": "Python3",
39 | "orm": "Raw",
40 | "platform": "Spyne",
41 | "webserver": "None",
42 | "os": "Linux",
43 | "database_os": "Linux",
44 | "display_name": "Spyne-raw",
45 | "notes": "",
46 | "versus": "wsgi"
47 | },
48 | "nginx-uwsgi": {
49 | "json_url": "/json",
50 | "db_url": "/db",
51 | "query_url": "/dbs?queries=",
52 | "fortune_url": "/fortunes",
53 | "update_url": "/updates?queries=",
54 | "plaintext_url": "/plaintext",
55 | "port": 8080,
56 | "approach": "Realistic",
57 | "classification": "Micro",
58 | "database": "postgres",
59 | "framework": "spyne",
60 | "language": "Python",
61 | "flavor": "Python3",
62 | "orm": "Full",
63 | "platform": "None",
64 | "webserver": "nginx",
65 | "os": "Linux",
66 | "database_os": "Linux",
67 | "display_name": "Spyne",
68 | "notes": "",
69 | "versus": "wsgi"
70 | }
71 | }]
72 | }
73 |
--------------------------------------------------------------------------------
/examples/flask/apps/flasked.py:
--------------------------------------------------------------------------------
1 | # encoding: utf8
2 | #
3 | # Copyright © Anton Egorov
4 | # All rights reserved.
5 | #
6 | # Redistribution and use in source and binary forms, with or without
7 | # modification, are permitted provided that the following conditions are met:
8 | #
9 | # 1. Redistributions of source code must retain the above copyright notice,
10 | # this list of conditions and the following disclaimer.
11 | # 2. Redistributions in binary form must reproduce the above copyright
12 | # notice, this list of conditions and the following disclaimer in the
13 | # documentation and/or other materials provided with the distribution.
14 | # 3. Neither the name of the owner nor the names of its contributors may be
15 | # used to endorse or promote products derived from this software without
16 | # specific prior written permission.
17 | #
18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
22 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 | #
29 |
30 | import json
31 | from flask import Flask, make_response, current_app
32 |
33 |
34 | app = Flask(__name__)
35 | app.config.from_object('settings')
36 |
37 |
38 | @app.route('/hello')
39 | def hello():
40 | '''Sample Flask API view that ruturns JSON with some data from config.
41 | '''
42 | response = make_response(json.dumps({
43 | 'hello': current_app.config['HELLO'],
44 | }))
45 | response.headers['Content-Type'] = 'application/json'
46 | return response
47 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap12/soap_http_basic.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 |
22 | logging.basicConfig(level=logging.DEBUG)
23 | logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
24 | logger = logging.getLogger('spyne.test.interop.server.soap_http_basic')
25 |
26 | from spyne.server.wsgi import WsgiApplication
27 | from spyne.test.interop.server._service import services
28 | from spyne.application import Application
29 | from spyne.protocol.soap import Soap12
30 |
31 |
32 | soap12_application = Application(services, 'spyne.test.interop.server',
33 | in_protocol=Soap12(validator='lxml', cleanup_namespaces=True),
34 | out_protocol=Soap12())
35 |
36 | host = '127.0.0.1'
37 | port = 9754
38 |
39 | def main():
40 | try:
41 | from wsgiref.simple_server import make_server
42 | from wsgiref.validate import validator
43 |
44 | wsgi_application = WsgiApplication(soap12_application)
45 | server = make_server(host, port, validator(wsgi_application))
46 |
47 | logger.info('Starting interop server at %s:%s.' % ('0.0.0.0', 9754))
48 | logger.info('WSDL is at: /?wsdl')
49 | server.serve_forever()
50 |
51 | except ImportError:
52 | print("Error: example server code requires Python >= 2.5")
53 |
54 | if __name__ == '__main__':
55 | main()
56 |
--------------------------------------------------------------------------------
/spyne/server/pyramid.py:
--------------------------------------------------------------------------------
1 | # encoding: utf-8
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The ``spyne.server.pyramid`` module contains a Pyramid-compatible Http
21 | transport. It's a thin wrapper around
22 | :class:`spyne.server.wsgi.WsgiApplication`.
23 | """
24 |
25 | from __future__ import absolute_import
26 |
27 | from pyramid.response import Response
28 | from spyne.server.wsgi import WsgiApplication
29 |
30 |
31 | class PyramidApplication(WsgiApplication):
32 | """Pyramid View Wrapper. Use this for regular RPC"""
33 |
34 | def __call__(self, request):
35 | retval = Response()
36 |
37 | def start_response(status, headers):
38 | status, reason = status.split(' ', 1)
39 |
40 | retval.status_int = int(status)
41 | for header, value in headers:
42 | retval.headers[header] = value
43 |
44 | response = WsgiApplication.__call__(self, request.environ,
45 | start_response)
46 | retval.body = b"".join(response)
47 |
48 | return retval
49 |
50 | def set_response(self, retval, response):
51 | retval.body = b"".join(response)
52 |
53 |
54 | class StreamingPyramidApplication(WsgiApplication):
55 | """You should use this when you're generating HUGE data as response."""
56 |
57 | def set_response(self, retval, response):
58 | retval.app_iter = response
59 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap12/soap_http_static.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logging.basicConfig(level=logging.DEBUG)
22 | logger = logging.getLogger('spyne.wsgi')
23 | logger.setLevel(logging.DEBUG)
24 |
25 | import os
26 |
27 | from spyne.test.interop.server.soap12.soap_http_basic import soap12_application
28 | from spyne.server.twisted import TwistedWebResource
29 |
30 | host = '127.0.0.1'
31 | port = 9756
32 | url = 'app'
33 |
34 | def main(argv):
35 | from twisted.python import log
36 | from twisted.web.server import Site
37 | from twisted.web.static import File
38 | from twisted.internet import reactor
39 | from twisted.python import log
40 |
41 | observer = log.PythonLoggingObserver('twisted')
42 | log.startLoggingWithObserver(observer.emit, setStdout=False)
43 |
44 | static_dir = os.path.abspath('.')
45 | logging.info("registering static folder %r on /" % static_dir)
46 | root = File(static_dir)
47 |
48 | wr = TwistedWebResource(soap12_application)
49 | logging.info("registering %r on /%s" % (wr, url))
50 | root.putChild(url, wr)
51 |
52 | site = Site(root)
53 |
54 | reactor.listenTCP(port, site)
55 | logging.info("listening on: %s:%d" % (host,port))
56 |
57 | return reactor.run()
58 |
59 |
60 | if __name__ == '__main__':
61 | import sys
62 | sys.exit(main(sys.argv))
63 |
--------------------------------------------------------------------------------
/examples/flask/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © Anton Egorov
5 | # All rights reserved.
6 | #
7 | # Redistribution and use in source and binary forms, with or without
8 | # modification, are permitted provided that the following conditions are met:
9 | #
10 | # 1. Redistributions of source code must retain the above copyright notice,
11 | # this list of conditions and the following disclaimer.
12 | # 2. Redistributions in binary form must reproduce the above copyright
13 | # notice, this list of conditions and the following disclaimer in the
14 | # documentation and/or other materials provided with the distribution.
15 | # 3. Neither the name of the owner nor the names of its contributors may be
16 | # used to endorse or promote products derived from this software without
17 | # specific prior written permission.
18 | #
19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
23 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | #
30 |
31 | from werkzeug.middleware.dispatcher import DispatcherMiddleware
32 |
33 | from spyne.server.wsgi import WsgiApplication
34 |
35 | from apps import spyned
36 | from apps.flasked import app
37 |
38 |
39 | # SOAP services are distinct wsgi applications, we should use dispatcher
40 | # middleware to bring all aps together
41 | app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {
42 | '/soap': WsgiApplication(spyned.create_app(app))
43 | })
44 |
45 |
46 | if __name__ == '__main__':
47 | app.run()
48 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap11/httprpc_soap_basic.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logging.basicConfig(level=logging.DEBUG)
22 | logger = logging.getLogger('spyne.protocol.xml')
23 | logger.setLevel(logging.DEBUG)
24 |
25 | from spyne.application import Application
26 | from spyne.test.interop.server._service import services
27 | from spyne.protocol.http import HttpRpc
28 | from spyne.protocol.soap import Soap11
29 | from spyne.server.wsgi import WsgiApplication
30 | from spyne.test.interop.server import get_open_port
31 |
32 |
33 | httprpc_soap_application = Application(services,
34 | 'spyne.test.interop.server.httprpc.soap', in_protocol=HttpRpc(), out_protocol=Soap11())
35 |
36 |
37 | host = '127.0.0.1'
38 | port = [0]
39 |
40 |
41 | if __name__ == '__main__':
42 | try:
43 | from wsgiref.simple_server import make_server
44 | from wsgiref.validate import validator
45 | if port[0] == 0:
46 | port[0] = get_open_port()
47 |
48 | wsgi_application = WsgiApplication(httprpc_soap_application)
49 | server = make_server(host, port[0], validator(wsgi_application))
50 |
51 | logger.info('Starting interop server at %s:%s.' % ('0.0.0.0', port[0]))
52 | logger.info('WSDL is at: /?wsdl')
53 | server.serve_forever()
54 |
55 | except ImportError:
56 | print("Error: example server code requires Python >= 2.5")
57 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/httprpc_csv_basic.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logging.basicConfig(level=logging.DEBUG)
22 | logger = logging.getLogger('spyne.protocol.xml')
23 | logger.setLevel(logging.DEBUG)
24 |
25 | from spyne.test.interop.server import get_open_port
26 | from spyne.application import Application
27 | from spyne.interface.wsdl import Wsdl11
28 | from spyne.protocol.csv import OutCsv
29 | from spyne.protocol.http import HttpRpc
30 | from spyne.server.wsgi import WsgiApplication
31 | from spyne.test.interop.server._service import services
32 |
33 | httprpc_csv_application = Application(services,
34 | 'spyne.test.interop.server.httprpc.csv', in_protocol=HttpRpc(), out_protocol=OutCsv())
35 |
36 |
37 | host = '127.0.0.1'
38 | port = [0]
39 |
40 |
41 | if __name__ == '__main__':
42 | try:
43 | from wsgiref.simple_server import make_server
44 | from wsgiref.validate import validator
45 |
46 | if port[0] == 0:
47 | port[0] = get_open_port()
48 |
49 | wsgi_application = WsgiApplication(httprpc_csv_application)
50 | server = make_server(host, port[0], validator(wsgi_application))
51 |
52 | logger.info('Starting interop server at %s:%s.' % ('0.0.0.0', port[0]))
53 | logger.info('WSDL is at: /?wsdl')
54 | server.serve_forever()
55 |
56 | except ImportError:
57 | print("Error: example server code requires Python >= 2.5")
58 |
--------------------------------------------------------------------------------
/spyne/const/xml_ns.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | # This module is DEPRECATED. Use ``spyne.const.xml``.
21 |
22 | xml = 'http://www.w3.org/XML/1998/namespace'
23 | xsd = 'http://www.w3.org/2001/XMLSchema'
24 | xsi = 'http://www.w3.org/2001/XMLSchema-instance'
25 | wsa = 'http://schemas.xmlsoap.org/ws/2003/03/addressing'
26 | xop = 'http://www.w3.org/2004/08/xop/include'
27 | soap = 'http://schemas.xmlsoap.org/wsdl/soap/'
28 | wsdl = 'http://schemas.xmlsoap.org/wsdl/'
29 | xhtml = 'http://www.w3.org/1999/xhtml'
30 | plink = 'http://schemas.xmlsoap.org/ws/2003/05/partner-link/'
31 | soap11_enc = 'http://schemas.xmlsoap.org/soap/encoding/'
32 | soap11_env = 'http://schemas.xmlsoap.org/soap/envelope/'
33 | soap12_env = 'http://www.w3.org/2003/05/soap-envelope'
34 | soap12_enc = 'http://www.w3.org/2003/05/soap-encoding'
35 |
36 | const_nsmap = {
37 | 'xml': xml,
38 | 'xs': xsd,
39 | 'xsi': xsi,
40 | 'plink': plink,
41 | 'soap': soap,
42 | 'wsdl': wsdl,
43 | 'soap11enc': soap11_enc,
44 | 'soap11env': soap11_env,
45 | 'soap12env': soap12_env,
46 | 'soap12enc': soap12_enc,
47 | 'wsa': wsa,
48 | 'xop': xop,
49 | }
50 |
51 | const_prefmap = None
52 | def regen_prefmap():
53 | global const_prefmap
54 | const_prefmap = dict([(b, a) for a, b in const_nsmap.items()])
55 |
56 | regen_prefmap()
57 |
58 | schema_location = {
59 | xsd: 'http://www.w3.org/2001/XMLSchema.xsd',
60 | }
61 |
62 | class DEFAULT_NS(object):
63 | pass
64 |
--------------------------------------------------------------------------------
/spyne/util/toposort.py:
--------------------------------------------------------------------------------
1 | # http://code.activestate.com/recipes/577413-topological-sort/
2 | #
3 | # The MIT License (MIT)
4 | #
5 | # Copyright (c) ActiveState.com
6 | #
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 |
25 |
26 | from pprint import pformat
27 |
28 | try:
29 | # Python 3
30 | from functools import reduce
31 | except:
32 | pass
33 |
34 |
35 | def toposort2(data):
36 | if len(data) == 0:
37 | return
38 |
39 | for k, v in data.items():
40 | v.discard(k) # Ignore self dependencies
41 |
42 | # add items that are listed as dependencies but not as dependents to data
43 | extra_items_in_deps = reduce(set.union, data.values()) - set(data.keys())
44 | data.update(dict([(item,set()) for item in extra_items_in_deps]))
45 |
46 | while True:
47 | ordered = set(item for item,dep in data.items() if len(dep) == 0)
48 | if len(ordered) == 0:
49 | break
50 | yield sorted(ordered, key=lambda x:repr(x))
51 | data = dict([(item, (dep - ordered)) for item,dep in data.items()
52 | if item not in ordered])
53 |
54 | assert not data, "A cyclic dependency exists amongst\n%s" % pformat(data)
55 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/httprpc_pod_basic_twisted.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """pod being plain old data"""
21 |
22 | import logging
23 | logging.basicConfig(level=logging.DEBUG)
24 | logger = logging.getLogger('spyne.protocol.xml')
25 | logger.setLevel(logging.DEBUG)
26 |
27 | from spyne.test.interop.server import get_open_port
28 | from spyne.application import Application
29 | from spyne.test.interop.server._service import services
30 | from spyne.protocol.http import HttpRpc
31 | from spyne.server.twisted import TwistedWebResource
32 |
33 | httprpc_soap_application = Application(services,
34 | 'spyne.test.interop.server.httprpc.pod',
35 | in_protocol=HttpRpc(), out_protocol=HttpRpc())
36 |
37 | host = '127.0.0.1'
38 | port = [0]
39 |
40 | def main(argv):
41 | from twisted.web.server import Site
42 | from twisted.internet import reactor
43 | from twisted.python import log
44 | observer = log.PythonLoggingObserver('twisted')
45 | log.startLoggingWithObserver(observer.emit, setStdout=False)
46 |
47 | if port[0] == 0:
48 | port[0] = get_open_port()
49 |
50 | wr = TwistedWebResource(httprpc_soap_application)
51 | site = Site(wr)
52 |
53 | reactor.listenTCP(port[0], site)
54 | logging.info("listening on: %s:%d" % (host,port[0]))
55 |
56 | return reactor.run()
57 |
58 |
59 | if __name__ == '__main__':
60 | import sys
61 | sys.exit(main(sys.argv))
62 |
--------------------------------------------------------------------------------
/examples/authentication/http_cookie/client_suds.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2
2 | #encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | # TODO: python3 port
33 |
34 | from suds import WebFault
35 | from suds.client import Client
36 |
37 | c = Client('http://localhost:8000/app/?wsdl')
38 |
39 | user_name = 'neo'
40 |
41 | c.service.authenticate(user_name, 'Wh1teR@bbit')
42 | print ('Authentication for %r successful.' % user_name)
43 |
44 | print('Preferences for %r:' % user_name)
45 | print(c.service.get_preferences(user_name))
46 |
47 | try:
48 | print(c.service.get_preferences('smith'))
49 | except WebFault, e:
50 | print(e)
51 |
--------------------------------------------------------------------------------
/spyne/util/resource.py:
--------------------------------------------------------------------------------
1 | # encoding: utf8
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import os.path
21 |
22 | import spyne.util.autorel
23 |
24 |
25 | def get_resource_path(ns, fn):
26 | try:
27 | from spyne._deploymentinfo import resource_filename
28 | except ImportError:
29 | from pkg_resources import resource_filename
30 |
31 | resfn = resource_filename(ns, fn)
32 | spyne.util.autorel.AutoReloader.FILES.add(resfn)
33 | path = os.path.abspath(resfn)
34 | return path
35 |
36 |
37 | def get_resource_file(ns, fn):
38 | return open(get_resource_path(ns, fn), 'rb')
39 |
40 |
41 | def get_resource_file_contents(ns, fn, enc=None):
42 | resfn = get_resource_path(ns, fn)
43 |
44 | if enc is None:
45 | return open(resfn, 'rb').read()
46 | else:
47 | return open(resfn, 'rb').read().decode(enc)
48 |
49 |
50 | def parse_xml_resource(ns, fn):
51 | from lxml import etree
52 |
53 | retval = etree.parse(get_resource_file(ns, fn))
54 |
55 | return retval.getroot()
56 |
57 |
58 | def parse_html_resource(ns, fn):
59 | from lxml import html
60 |
61 | retval = html.parse(get_resource_file(ns, fn))
62 |
63 | return retval.getroot()
64 |
65 |
66 | def parse_cloth_resource(ns, fn):
67 | from lxml import html
68 |
69 | retval = html.fragment_fromstring(get_resource_file_contents(ns, fn),
70 | create_parent='spyne-root')
71 | retval.attrib['spyne-tagbag'] = ''
72 | return retval
73 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/httprpc_pod_basic.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """pod being plain old data"""
21 |
22 | import logging
23 |
24 |
25 | logging.basicConfig(level=logging.DEBUG)
26 | logger = logging.getLogger('spyne.protocol.xml')
27 | logger.setLevel(logging.DEBUG)
28 |
29 | from spyne.test.interop.server import get_open_port
30 | from spyne.application import Application
31 | from spyne.test.interop.server._service import services
32 | from spyne.protocol.http import HttpRpc
33 | from spyne.server.wsgi import WsgiApplication
34 |
35 | httprpc_soap_application = Application(services,
36 | 'spyne.test.interop.server.httprpc.pod', in_protocol=HttpRpc(),
37 | out_protocol=HttpRpc())
38 | host = "127.0.0.1"
39 | port = [0]
40 |
41 |
42 | def main():
43 | try:
44 | from wsgiref.simple_server import make_server
45 | from wsgiref.validate import validator
46 | if port[0] == 0:
47 | port[0] = get_open_port()
48 |
49 | wsgi_application = WsgiApplication(httprpc_soap_application)
50 | server = make_server(host, port[0], validator(wsgi_application))
51 |
52 | logger.info('Starting interop server at %s:%s.' % ('0.0.0.0', port[0]))
53 | logger.info('WSDL is at: /?wsdl')
54 | server.serve_forever()
55 |
56 | except ImportError:
57 | print("Error: example server code requires Python >= 2.5")
58 |
59 |
60 | if __name__ == '__main__':
61 | main()
62 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/msgpackrpc_http_basic.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logging.basicConfig(level=logging.DEBUG)
22 | logging.getLogger('spyne.protocol.msgpack').setLevel(logging.DEBUG)
23 | logger = logging.getLogger('spyne.test.interop.server.msgpackrpc_http_basic')
24 |
25 | from spyne.test.interop.server import get_open_port
26 | from spyne.server.wsgi import WsgiApplication
27 | from spyne.test.interop.server._service import services
28 | from spyne.application import Application
29 | from spyne.protocol.msgpack import MessagePackRpc
30 |
31 | msgpackrpc_application = Application(services, 'spyne.test.interop.server',
32 | in_protocol=MessagePackRpc(validator='soft'),
33 | out_protocol=MessagePackRpc())
34 |
35 | host = '127.0.0.1'
36 | port = [0]
37 |
38 | def main():
39 | try:
40 | from wsgiref.simple_server import make_server
41 | from wsgiref.validate import validator
42 | if port[0] == 0:
43 | port[0] = get_open_port()
44 |
45 | wsgi_application = WsgiApplication(msgpackrpc_application)
46 | server = make_server(host, port[0], validator(wsgi_application))
47 |
48 | logger.info('Starting interop server at %s:%s.' % (host, port[0]))
49 | logger.info('WSDL is at: /?wsdl')
50 | server.serve_forever()
51 |
52 | except ImportError:
53 | print("Error: example server code requires Python >= 2.5")
54 |
55 | if __name__ == '__main__':
56 | main()
57 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap11/soap_http_static.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 | logging.basicConfig(level=logging.DEBUG)
22 | logger = logging.getLogger('spyne.wsgi')
23 | logger.setLevel(logging.DEBUG)
24 |
25 | import os
26 |
27 | from spyne.test.interop.server import get_open_port
28 | from spyne.test.interop.server.soap_http_basic import soap11_application
29 | from spyne.server.twisted import TwistedWebResource
30 |
31 |
32 | host = '127.0.0.1'
33 | port = [0]
34 | url = 'app'
35 |
36 |
37 | def main(argv):
38 | from twisted.python import log
39 | from twisted.web.server import Site
40 | from twisted.web.static import File
41 | from twisted.internet import reactor
42 | from twisted.python import log
43 |
44 | observer = log.PythonLoggingObserver('twisted')
45 | log.startLoggingWithObserver(observer.emit, setStdout=False)
46 |
47 | static_dir = os.path.abspath('.')
48 | logging.info("registering static folder %r on /" % static_dir)
49 | root = File(static_dir)
50 |
51 | wr = TwistedWebResource(soap11_application)
52 | logging.info("registering %r on /%s" % (wr, url))
53 | root.putChild(url, wr)
54 |
55 | site = Site(root)
56 |
57 | if port[0] == 0:
58 | port[0] = get_open_port()
59 | reactor.listenTCP(port[0], site)
60 | logging.info("listening on: %s:%d" % (host,port))
61 |
62 | return reactor.run()
63 |
64 |
65 | if __name__ == '__main__':
66 | import sys
67 | sys.exit(main(sys.argv))
68 |
--------------------------------------------------------------------------------
/spyne/test/interop/server/soap11/soap_http_basic.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | import logging
21 |
22 | logging.basicConfig(level=logging.DEBUG)
23 | logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
24 | logger = logging.getLogger('spyne.test.interop.server.soap_http_basic')
25 |
26 |
27 | from spyne.test.interop.server import get_open_port
28 | from spyne.server.wsgi import WsgiApplication
29 | from spyne.test.interop.server._service import services
30 | from spyne.application import Application
31 | from spyne.protocol.soap import Soap11
32 |
33 |
34 | soap11_application = Application(services, 'spyne.test.interop.server',
35 | in_protocol=Soap11(validator='lxml', cleanup_namespaces=True),
36 | out_protocol=Soap11())
37 |
38 |
39 | host = '127.0.0.1'
40 | port = [0]
41 |
42 |
43 | def main():
44 | try:
45 | from wsgiref.simple_server import make_server
46 | from wsgiref.validate import validator
47 | if port[0] == 0:
48 | port[0] = get_open_port()
49 |
50 | wsgi_application = WsgiApplication(soap11_application)
51 | server = make_server(host, port[0], validator(wsgi_application))
52 |
53 | logger.info('Starting interop server at %s:%s.' % ('0.0.0.0', port[0]))
54 | logger.info('WSDL is at: /?wsdl')
55 | server.serve_forever()
56 |
57 | except ImportError:
58 | print("Error: example server code requires Python >= 2.5")
59 |
60 |
61 | if __name__ == '__main__':
62 | main()
63 |
--------------------------------------------------------------------------------
/spyne/util/simple.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """Contains functions that implement the most common protocol and transport
21 | combinations"""
22 |
23 |
24 | from spyne.application import Application
25 |
26 |
27 | def wsgi_soap11_application(services, tns='spyne.simple.soap', validator=None,
28 | name=None):
29 | """Wraps `services` argument inside a WsgiApplication that uses Soap 1.1 for
30 | both input and output protocols.
31 | """
32 |
33 | from spyne.protocol.soap import Soap11
34 | from spyne.server.wsgi import WsgiApplication
35 |
36 | application = Application(services, tns, name=name,
37 | in_protocol=Soap11(validator=validator), out_protocol=Soap11())
38 |
39 | return WsgiApplication(application)
40 |
41 | wsgi_soap_application = wsgi_soap11_application
42 | """DEPRECATED! Use :func:`wsgi_soap11_application` instead."""
43 |
44 |
45 | def pyramid_soap11_application(services, tns='spyne.simple.soap',
46 | validator=None, name=None):
47 | """Wraps `services` argument inside a PyramidApplication that uses Soap 1.1
48 | for both input and output protocols.
49 | """
50 |
51 | from spyne.protocol.soap import Soap11
52 | from spyne.server.pyramid import PyramidApplication
53 |
54 | application = Application(services, tns, name=name,
55 | in_protocol=Soap11(validator=validator), out_protocol=Soap11())
56 |
57 | return PyramidApplication(application)
58 |
--------------------------------------------------------------------------------
/examples/zeromq/app.py:
--------------------------------------------------------------------------------
1 | #
2 | # encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | from spyne.application import Application
33 | from spyne.protocol.msgpack import MessagePackRpc
34 | from spyne.service import Service
35 | from spyne.decorator import rpc
36 | from spyne.model.primitive import Unicode
37 |
38 |
39 | class RadianteRPC(Service):
40 | @rpc(_returns=Unicode)
41 | def whoami(ctx):
42 | return "Hello I am Seldon!"
43 |
44 |
45 | app = Application(
46 | [RadianteRPC],
47 | tns="radiante.rpc",
48 | in_protocol=MessagePackRpc(validator="soft"),
49 | out_protocol=MessagePackRpc()
50 | )
51 |
52 | import logging
53 | logging.basicConfig(level=logging.DEBUG)
54 |
--------------------------------------------------------------------------------
/spyne/const/ansi_color.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """You can use the constants in this package to add colour to your logs. You can
21 | use the "colorama" package to get ANSI colors working on windows.
22 | """
23 |
24 | DARK_RED = ""
25 | """ANSI colour value for dark red if colours are enabled, empty string
26 | otherwise."""
27 |
28 | LIGHT_GREEN = ""
29 | """ANSI colour value for light green if colours are enabled, empty string
30 | otherwise."""
31 |
32 | LIGHT_RED = ""
33 | """ANSI colour value for light red if colours are enabled, empty string
34 | otherwise."""
35 |
36 | LIGHT_BLUE = ""
37 | """ANSI colour value for light blue if colours are enabled, empty string
38 | otherwise."""
39 |
40 | END_COLOR = ""
41 | """ANSI colour value for end color marker if colours are enabled, empty string
42 | otherwise."""
43 |
44 | def enable_color():
45 | """Enable colors by setting colour code constants to ANSI color codes."""
46 |
47 | global LIGHT_GREEN
48 | LIGHT_GREEN = "\033[1;32m"
49 |
50 | global LIGHT_RED
51 | LIGHT_RED = "\033[1;31m"
52 |
53 | global LIGHT_BLUE
54 | LIGHT_BLUE = "\033[1;34m"
55 |
56 | global DARK_RED
57 | DARK_RED = "\033[0;31m"
58 |
59 | global END_COLOR
60 | END_COLOR = "\033[0m"
61 |
62 |
63 | def disable_color():
64 | """Disable colours by setting colour code constants to empty strings."""
65 |
66 | global LIGHT_GREEN
67 | LIGHT_GREEN = ""
68 |
69 | global LIGHT_RED
70 | LIGHT_RED = ""
71 |
72 | global LIGHT_BLUE
73 | LIGHT_BLUE = ""
74 |
75 | global DARK_RED
76 | DARK_RED = ""
77 |
78 | global END_COLOR
79 | END_COLOR = ""
80 |
81 | enable_color()
82 |
--------------------------------------------------------------------------------
/examples/dict_skip.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 |
33 | from spyne import Boolean, String, ComplexModel
34 |
35 | from spyne.util.dictdoc import get_object_as_dict
36 |
37 |
38 | class SomeMapping(ComplexModel):
39 | compact = Boolean
40 | solid = Boolean
41 | object_name = String
42 | attached = Boolean
43 | is_published = Boolean
44 | is_owner = Boolean
45 | can_delete = Boolean
46 | can_insert= Boolean
47 | can_update = Boolean
48 |
49 |
50 | print(list(get_object_as_dict(SomeMapping(
51 | compact=True,
52 | solid=True,
53 | object_name="Cat",
54 | attached=False,
55 | is_published=True,
56 | is_owner=False,
57 | can_delete=False,
58 | can_insert= True,
59 | can_update=True
60 | ), SomeMapping, ignore_wrappers=True, complex_as=list)))
61 |
62 |
--------------------------------------------------------------------------------
/spyne/model/__init__.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The ``spyne.model`` package contains data types that Spyne is able to
21 | distinguish. These are just type markers, they are not of much use without
22 | protocols.
23 | """
24 |
25 | from spyne.model._base import Ignored
26 | from spyne.model._base import ModelBase
27 | from spyne.model._base import PushBase
28 | from spyne.model._base import Null
29 | from spyne.model._base import SimpleModel
30 |
31 | # Primitives
32 | from spyne.model.primitive import *
33 |
34 | # store_as values
35 | # it's sad that xml the pssm and xml the module conflict. that's why we need
36 | # this after import of primitive package
37 | from spyne.model._base import xml
38 | from spyne.model._base import json
39 | from spyne.model._base import jsonb
40 | from spyne.model._base import table
41 | from spyne.model._base import msgpack
42 |
43 | # Classes
44 | from spyne.model.complex import ComplexModelMeta
45 | from spyne.model.complex import ComplexModelBase
46 | from spyne.model.complex import ComplexModel
47 | from spyne.model.complex import TTableModelBase
48 | from spyne.model.complex import TTableModel
49 |
50 | # Iterables
51 | from spyne.model.complex import Array
52 | from spyne.model.complex import Iterable
53 | from spyne.model.complex import PushBase
54 |
55 | # Modifiers
56 | from spyne.model.complex import Mandatory
57 | from spyne.model.complex import XmlAttribute
58 | from spyne.model.complex import XmlData
59 |
60 | # Markers
61 | from spyne.model.complex import SelfReference
62 |
63 | # Binary
64 | from spyne.model.binary import File
65 | from spyne.model.binary import ByteArray
66 |
67 | # Enum
68 | from spyne.model.enum import Enum
69 |
70 | # Fault
71 | from spyne.model.fault import Fault
72 |
--------------------------------------------------------------------------------
/examples/template/template/db.py:
--------------------------------------------------------------------------------
1 | # encoding: utf8
2 | #
3 | # Copyright © Burak Arslan ,
4 | # Arskom Ltd. http://www.arskom.com.tr
5 | # All rights reserved.
6 | #
7 | # Redistribution and use in source and binary forms, with or without
8 | # modification, are permitted provided that the following conditions are met:
9 | #
10 | # 1. Redistributions of source code must retain the above copyright notice,
11 | # this list of conditions and the following disclaimer.
12 | # 2. Redistributions in binary form must reproduce the above copyright
13 | # notice, this list of conditions and the following disclaimer in the
14 | # documentation and/or other materials provided with the distribution.
15 | # 3. Neither the name of the owner nor the names of its contributors may be
16 | # used to endorse or promote products derived from this software without
17 | # specific prior written permission.
18 | #
19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
23 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | #
30 |
31 | from spyne.model.complex import TTableModel
32 | from spyne.model.primitive import UnsignedInteger32
33 | from spyne.model.primitive import Unicode
34 |
35 | from sqlalchemy import create_engine
36 | from sqlalchemy import MetaData
37 | from sqlalchemy.orm import sessionmaker
38 |
39 | db = create_engine('sqlite:///:memory:')
40 | Session = sessionmaker(bind=db)
41 | TableModel = TTableModel(MetaData(bind=db))
42 |
43 |
44 | class User(TableModel):
45 | __tablename__ = 'spyne_user'
46 |
47 | # This is only needed for sqlite
48 | __table_args__ = {"sqlite_autoincrement": True}
49 |
50 | id = UnsignedInteger32(pk=True)
51 | user_name = Unicode(32, min_len=4, pattern='[a-z0-9.]+')
52 | full_name = Unicode(64, pattern='\w+( \w+)+')
53 | email = Unicode(64, pattern=r'[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}')
54 |
--------------------------------------------------------------------------------
/examples/django/rpctest/urls.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © BJ Cardon ,
5 | # Burak ARrslan ,
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | from django.conf.urls import url
33 |
34 | from spyne.protocol.soap import Soap11
35 | from spyne.server.django import DjangoView
36 |
37 | from rpctest.core.views import hello_world_service, app, HelloWorldService
38 |
39 |
40 | urlpatterns = [
41 | url(r'^hello_world/', hello_world_service),
42 | url(r'^say_hello/', DjangoView.as_view(
43 | services=[HelloWorldService], tns='spyne.examples.django',
44 | in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())),
45 | url(r'^say_hello_not_cached/', DjangoView.as_view(
46 | services=[HelloWorldService], tns='spyne.examples.django',
47 | in_protocol=Soap11(validator='lxml'), out_protocol=Soap11(),
48 | cache_wsdl=False)),
49 | url(r'^api/', DjangoView.as_view(application=app)),
50 | ]
51 |
--------------------------------------------------------------------------------
/spyne/test/interop/test_soap_client_http_twisted.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | from twisted.trial import unittest
21 | from spyne.test.interop._test_soap_client_base import run_server, server_started
22 |
23 | from spyne.client.twisted import TwistedHttpClient
24 | from spyne.test.interop.server.soap11.soap_http_basic import soap11_application
25 |
26 | class TestSpyneHttpClient(unittest.TestCase):
27 | def setUp(self):
28 | run_server('http')
29 |
30 | port, = server_started.keys()
31 |
32 | self.ns = b"spyne.test.interop.server._service"
33 | self.client = TwistedHttpClient(b'http://localhost:%d/' % port,
34 | soap11_application)
35 |
36 | def test_echo_boolean(self):
37 | def eb(ret):
38 | raise ret
39 |
40 | def cb(ret):
41 | assert ret == True
42 |
43 | return self.client.service.echo_boolean(True).addCallbacks(cb, eb)
44 |
45 | def test_python_exception(self):
46 | def eb(ret):
47 | print(ret)
48 |
49 | def cb(ret):
50 | assert False, "must fail: %r" % ret
51 |
52 | return self.client.service.python_exception().addCallbacks(cb, eb)
53 |
54 | def test_soap_exception(self):
55 | def eb(ret):
56 | print(type(ret))
57 |
58 | def cb(ret):
59 | assert False, "must fail: %r" % ret
60 |
61 | return self.client.service.soap_exception().addCallbacks(cb, eb)
62 |
63 | def test_documented_exception(self):
64 | def eb(ret):
65 | print(ret)
66 |
67 | def cb(ret):
68 | assert False, "must fail: %r" % ret
69 |
70 | return self.client.service.python_exception().addCallbacks(cb, eb)
71 |
--------------------------------------------------------------------------------
/examples/user_manager/spyne_client.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | from pprint import pprint
33 |
34 | from spyne.client.http import HttpClient
35 |
36 | from server_basic import application
37 |
38 | c = HttpClient('http://localhost:8000/', application)
39 |
40 | u = c.factory.create("User")
41 |
42 | u.user_name = 'dave'
43 | u.first_name = 'david'
44 | u.last_name = 'smith'
45 | u.email = 'david.smith@example.com'
46 | u.permissions = []
47 |
48 | permission = c.factory.create("Permission")
49 | permission.application = 'table'
50 | permission.operation = 'write'
51 | u.permissions.append(permission)
52 |
53 | permission = c.factory.create("Permission")
54 | permission.application = 'table'
55 | permission.operation = 'read'
56 | u.permissions.append(permission)
57 |
58 | retval = c.service.add_user(u)
59 | print(retval)
60 |
61 | pprint(c.service.get_user(retval))
62 | pprint(list(c.service.get_all_user()))
63 |
--------------------------------------------------------------------------------
/examples/user_manager/suds_client.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | from suds import TypeNotFound
33 | from suds.client import Client
34 |
35 | has_permissions = True
36 | c = Client('http://localhost:8000?wsdl')
37 | u = c.factory.create("User")
38 |
39 | u.user_name = 'dave'
40 | u.full_name = 'david smith'
41 | u.email = 'dave@email.com'
42 |
43 | u.permissions = c.factory.create("PermissionArray")
44 |
45 | permission = c.factory.create("Permission")
46 | permission.application = 'usermgr'
47 | permission.operation = 'modify'
48 | u.permissions.Permission.append(permission)
49 |
50 | permission = c.factory.create("Permission")
51 | permission.application = 'accountmgr'
52 | permission.operation = 'read'
53 | u.permissions.Permission.append(permission)
54 |
55 | print(u)
56 |
57 | retval = c.service.put_user(u)
58 | print(retval)
59 |
60 | print(c.service.get_user(retval))
61 | print(c.service.get_all_user())
62 |
--------------------------------------------------------------------------------
/examples/authentication/client_suds.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | from suds import WebFault
33 | from suds.client import Client
34 |
35 | c = Client('http://localhost:8000/app/?wsdl')
36 |
37 | user_name = 'neo'
38 |
39 | session_id = c.service.authenticate(user_name, 'Wh1teR@bbit')
40 |
41 | print ('Authentication for %r successful. Session id: %r' %
42 | (user_name, session_id))
43 |
44 |
45 | request_header = c.factory.create('RequestHeader')
46 | request_header.session_id = session_id
47 | request_header.user_name = user_name
48 | c.set_options(soapheaders=request_header)
49 |
50 | print('Preferences for %r:' % user_name)
51 | print(c.service.get_preferences(user_name))
52 |
53 | try:
54 | print(c.service.get_preferences('trinity'))
55 | except WebFault, e:
56 | print(e)
57 |
58 | try:
59 | print(c.service.get_preferences('smith'))
60 | except WebFault, e:
61 | print(e)
62 |
--------------------------------------------------------------------------------
/spyne/server/twisted/_base.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | from twisted.internet.defer import Deferred
21 | from twisted.internet.interfaces import IPullProducer
22 | from twisted.web.iweb import UNKNOWN_LENGTH
23 |
24 | from zope.interface import implementer
25 |
26 |
27 | @implementer(IPullProducer)
28 | class Producer(object):
29 | deferred = None
30 |
31 | def __init__(self, body, consumer):
32 | """:param body: an iterable of strings"""
33 |
34 | # check to see if we can determine the length
35 | try:
36 | len(body) # iterator?
37 | self.length = sum([len(fragment) for fragment in body])
38 | self.body = iter(body)
39 |
40 | except TypeError:
41 | self.length = UNKNOWN_LENGTH
42 | self.body = body
43 |
44 | self.deferred = Deferred()
45 |
46 | self.consumer = consumer
47 |
48 | def resumeProducing(self):
49 | try:
50 | chunk = next(self.body)
51 |
52 | except StopIteration as e:
53 | self.consumer.unregisterProducer()
54 | if self.deferred is not None:
55 | self.deferred.callback(self.consumer)
56 | self.deferred = None
57 | return
58 |
59 | self.consumer.write(chunk)
60 |
61 | def pauseProducing(self):
62 | pass
63 |
64 | def stopProducing(self):
65 | if self.deferred is not None:
66 | self.deferred.errback(
67 | Exception("Consumer asked us to stop producing"))
68 | self.deferred = None
69 |
70 |
71 | from spyne import Address
72 | _TYPE_MAP = {'TCP': Address.TCP4, 'TCP6': Address.TCP6,
73 | 'UDP': Address.UDP4, 'UDP6': Address.UDP6}
74 |
75 | def _address_from_twisted_address(peer):
76 | return Address(
77 | type=_TYPE_MAP.get(peer.type, None), host=peer.host, port=peer.port)
78 |
79 | Address.from_twisted_address = staticmethod(_address_from_twisted_address)
80 |
--------------------------------------------------------------------------------
/spyne/client/http.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """The HTTP (urllib2) client transport."""
21 |
22 | from spyne import RemoteService, ClientBase, RemoteProcedureBase
23 |
24 | from spyne.util.six.moves.urllib.request import Request, urlopen
25 | from spyne.util.six.moves.urllib.error import HTTPError
26 |
27 |
28 | class _RemoteProcedure(RemoteProcedureBase):
29 | def __call__(self, *args, **kwargs):
30 | # there's no point in having a client making the same request more than
31 | # once, so if there's more than just one context, it is a bug.
32 | # the comma-in-assignment trick is a general way of getting the first
33 | # and the only variable from an iterable. so if there's more than one
34 | # element in the iterable, it'll fail miserably.
35 | self.ctx, = self.contexts
36 |
37 | # sets ctx.out_object
38 | self.get_out_object(self.ctx, args, kwargs)
39 |
40 | # sets ctx.out_string
41 | self.get_out_string(self.ctx)
42 |
43 | out_string = b''.join(self.ctx.out_string) # FIXME: just send the iterable to the http stream.
44 | request = Request(self.url, out_string)
45 | code = 200
46 | try:
47 | response = urlopen(request)
48 | self.ctx.in_string = [response.read()]
49 |
50 | except HTTPError as e:
51 | code = e.code
52 | self.ctx.in_string = [e.read()]
53 |
54 | # this sets ctx.in_error if there's an error, and ctx.in_object if
55 | # there's none.
56 | self.get_in_object(self.ctx)
57 |
58 | if not (self.ctx.in_error is None):
59 | raise self.ctx.in_error
60 | elif code >= 400:
61 | raise self.ctx.in_error
62 | else:
63 | return self.ctx.in_object
64 |
65 |
66 | class HttpClient(ClientBase):
67 | def __init__(self, url, app):
68 | super(HttpClient, self).__init__(url, app)
69 |
70 | self.service = RemoteService(_RemoteProcedure, url, app)
71 |
--------------------------------------------------------------------------------
/spyne/store/relational/override.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 |
21 | from sqlalchemy.ext.compiler import compiles
22 |
23 | from sqlalchemy.dialects.postgresql import INET
24 | from spyne.store.relational import PGXml, PGJson, PGHtml, PGJsonB, \
25 | PGObjectJson, PGFileJson
26 |
27 |
28 | @compiles(PGXml)
29 | def compile_xml(type_, compiler, **kw):
30 | return "xml"
31 |
32 |
33 | @compiles(PGHtml)
34 | def compile_html(type_, compiler, **kw):
35 | return "text"
36 |
37 |
38 | @compiles(PGJson)
39 | def compile_json(type_, compiler, **kw):
40 | return type_.get_col_spec()
41 |
42 |
43 | @compiles(PGJsonB)
44 | def compile_jsonb(type_, compiler, **kw):
45 | return type_.get_col_spec()
46 |
47 |
48 | @compiles(PGObjectJson)
49 | def compile_ojson(type_, compiler, **kw):
50 | return type_.get_col_spec()
51 |
52 |
53 | @compiles(PGFileJson)
54 | def compile_fjson(type_, compiler, **kw):
55 | return type_.get_col_spec()
56 |
57 |
58 | @compiles(INET)
59 | def compile_inet(type_, compiler, **kw):
60 | return "inet"
61 |
62 |
63 |
64 | @compiles(PGXml, "firebird")
65 | def compile_xml_firebird(type_, compiler, **kw):
66 | return "blob"
67 |
68 |
69 | @compiles(PGHtml, "firebird")
70 | def compile_html_firebird(type_, compiler, **kw):
71 | return "blob"
72 |
73 |
74 | @compiles(PGJson, "firebird")
75 | def compile_json_firebird(type_, compiler, **kw):
76 | return "blob"
77 |
78 |
79 | @compiles(PGJsonB, "firebird")
80 | def compile_jsonb_firebird(type_, compiler, **kw):
81 | return "blob"
82 |
83 |
84 | @compiles(PGObjectJson, "firebird")
85 | def compile_ojson_firebird(type_, compiler, **kw):
86 | return "blob"
87 |
88 |
89 | @compiles(PGFileJson, "firebird")
90 | def compile_fjson_firebird(type_, compiler, **kw):
91 | return "blob"
92 |
93 |
94 | @compiles(INET, "firebird")
95 | def compile_inet_firebird(type_, compiler, **kw):
96 | # http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html
97 | # INET6_ADDRSTRLEN
98 | return "varchar(45)"
99 |
--------------------------------------------------------------------------------
/examples/django/rpctest/core/models.py:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 |
3 | """Rpc test models."""
4 |
5 | from django.core.validators import MinLengthValidator, MaxLengthValidator
6 | from django.db import models
7 |
8 |
9 | class FieldContainer(models.Model):
10 |
11 | """Test model for ``DjangoMapper``."""
12 |
13 | char_field = models.CharField(max_length=32, default='test')
14 | char_field_nullable = models.CharField(max_length=32, null=True)
15 | slug_field = models.SlugField(max_length=32, unique=True)
16 | text_field = models.TextField(default='text_field')
17 | email_field = models.EmailField()
18 | boolean_field = models.BooleanField(default=True)
19 | integer_field = models.IntegerField(default=1)
20 | positive_integer_field = models.PositiveIntegerField(default=1)
21 | float_field = models.FloatField(default=1)
22 | decimal_field = models.DecimalField(max_digits=10, decimal_places=4,
23 | default=1)
24 | time_field = models.TimeField(auto_now_add=True)
25 | date_field = models.DateField(auto_now_add=True)
26 | datetime_field = models.DateTimeField(auto_now_add=True)
27 |
28 | foreign_key = models.ForeignKey('self', null=True,
29 | related_name='related_containers', on_delete=models.CASCADE)
30 | one_to_one_field = models.OneToOneField('self', null=True,
31 | on_delete=models.CASCADE)
32 |
33 | custom_foreign_key = models.ForeignKey('RelatedFieldContainer', null=True,
34 | related_name='related_fieldcontainers', on_delete=models.CASCADE)
35 | custom_one_to_one_field = models.OneToOneField('RelatedFieldContainer',
36 | null=True, on_delete=models.CASCADE)
37 |
38 | url_field = models.URLField(default='http://example.com')
39 | file_field = models.FileField(upload_to='test_file', null=True)
40 | excluded_field = models.CharField(max_length=32, default='excluded')
41 | blank_field = models.CharField(max_length=32, blank=True)
42 | length_validators_field = models.CharField(
43 | max_length=32, null=True, validators=[MinLengthValidator(3),
44 | MaxLengthValidator(10)])
45 |
46 |
47 | class RelatedFieldContainer(models.Model):
48 |
49 | """Related container model to test related fields."""
50 |
51 | id = models.CharField(max_length=30, primary_key=True)
52 |
53 |
54 | class User(models.Model):
55 |
56 | """Model for tests of relation field mapper."""
57 |
58 | name = models.CharField(max_length=50)
59 |
60 |
61 | class UserProfile(models.Model):
62 |
63 | """Related model for tests of relation field mapper."""
64 |
65 | user = models.ForeignKey(User, on_delete=models.CASCADE)
66 | data = models.CharField(max_length=50)
67 |
--------------------------------------------------------------------------------
/spyne/util/cdict.py:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # spyne - Copyright (C) Spyne contributors.
4 | #
5 | # This library is free software; you can redistribute it and/or
6 | # modify it under the terms of the GNU Lesser General Public
7 | # License as published by the Free Software Foundation; either
8 | # version 2.1 of the License, or (at your option) any later version.
9 | #
10 | # This library is distributed in the hope that it will be useful,
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # Lesser General Public License for more details.
14 | #
15 | # You should have received a copy of the GNU Lesser General Public
16 | # License along with this library; if not, write to the Free Software
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18 | #
19 |
20 | """cdict (ClassDict) is a funny kind of dict that tries to return the values for
21 | the base classes of a key when the entry for the key is not found. It is not a
22 | generalized dictionary that can handle any type of key -- it relies on
23 | spyne.model api to look for classes. It also assumes cdict never changes after
24 | the first lookup.
25 |
26 | >>> from spyne.util.cdict import cdict
27 | >>> class A(object):
28 | ... pass
29 | ...
30 | >>> class B(A):
31 | ... pass
32 | ...
33 | >>> class C(object):
34 | ... pass
35 | ...
36 | >>> class D:
37 | ... pass
38 | ...
39 | >>> d=cdict({A: "fun", object: "base"})
40 | >>> print d[A]
41 | fun
42 | >>> print d
43 | {: 'fun', : 'base'}
44 | >>> print d[B]
45 | fun
46 | >>> print d
47 | {: 'fun', : 'fun', : 'base'}
48 | >>> print d[C]
49 | base
50 | >>> print d
51 | {: 'fun', : 'fun', : 'base', : 'base'}
52 | >>> print d[D]
53 | *** KeyError:
54 | >>>
55 | """
56 |
57 | import logging
58 | logger = logging.getLogger(__name__)
59 |
60 | class cdict(dict):
61 | def __getitem__(self, cls):
62 | try:
63 | return dict.__getitem__(self, cls)
64 |
65 | except KeyError as e:
66 | if not hasattr(cls, '__bases__'):
67 | cls = cls.__class__
68 |
69 | for b in reversed(cls.__bases__):
70 | try:
71 | retval = self[b]
72 | # this is why a cdict instance must never be modified after
73 | # the first lookup
74 | self[cls] = retval
75 | return retval
76 | except KeyError:
77 | pass
78 | raise e
79 |
80 | def get(self, k, d=None):
81 | try:
82 | return self[k]
83 |
84 | except KeyError:
85 | return d
86 |
--------------------------------------------------------------------------------
/examples/xml/polymorphism_soap_server.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | import sys
33 |
34 | from datetime import datetime
35 | from spyne.protocol.soap import Soap11
36 | from spyne.server.wsgi import WsgiApplication
37 |
38 | from spyne.util.cherry import cherry_graft_and_start
39 | from spyne import DateTime, Unicode, Integer, ComplexModel, rpc, Application, \
40 | Service
41 |
42 |
43 | class A(ComplexModel):
44 | i = Integer
45 |
46 |
47 | class B(A):
48 | s = Unicode
49 |
50 |
51 | class C(A):
52 | d = DateTime
53 |
54 |
55 | class SomeService(Service):
56 | @rpc(Unicode(values=['A', 'B', 'C']), _returns=A)
57 | def get_some_a(self, type_name):
58 | if type_name == 'A':
59 | return A(i=1)
60 |
61 | if type_name == 'B':
62 | return B(i=2, s='s')
63 |
64 | if type_name == 'C':
65 | return C(i=3, d=datetime.utcnow())
66 |
67 |
68 | application = Application([SomeService], 'tns',
69 | in_protocol=Soap11(validator='lxml'),
70 | out_protocol=Soap11(polymorphic=True)
71 | )
72 |
73 | sys.exit(cherry_graft_and_start(WsgiApplication(application)))
74 |
--------------------------------------------------------------------------------
/examples/validation.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # encoding: utf8
3 | #
4 | # Copyright © Burak Arslan ,
5 | # Arskom Ltd. http://www.arskom.com.tr
6 | # All rights reserved.
7 | #
8 | # Redistribution and use in source and binary forms, with or without
9 | # modification, are permitted provided that the following conditions are met:
10 | #
11 | # 1. Redistributions of source code must retain the above copyright notice,
12 | # this list of conditions and the following disclaimer.
13 | # 2. Redistributions in binary form must reproduce the above copyright
14 | # notice, this list of conditions and the following disclaimer in the
15 | # documentation and/or other materials provided with the distribution.
16 | # 3. Neither the name of the owner nor the names of its contributors may be
17 | # used to endorse or promote products derived from this software without
18 | # specific prior written permission.
19 | #
20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT,
24 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 | # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | #
31 |
32 | """Use:
33 |
34 | curl http://localhost:9912/get_name_of_month?month=12
35 |
36 | to use this service.
37 | """
38 |
39 | host = '127.0.0.1'
40 | port = 8000
41 |
42 | import logging
43 |
44 | from datetime import datetime
45 |
46 | from spyne import Integer, Unicode, rpc, Service
47 |
48 |
49 | class NameOfMonthService(Service):
50 | @rpc(Integer(ge=1, le=12), _returns=Unicode)
51 | def get_name_of_month(ctx, month):
52 | return datetime(2000, month, 1).strftime("%B")
53 |
54 |
55 | from spyne.application import Application
56 | from spyne.protocol.http import HttpRpc
57 |
58 | rest = Application([NameOfMonthService],
59 | tns='spyne.examples.multiprot',
60 | in_protocol=HttpRpc(validator='soft'),
61 | out_protocol=HttpRpc()
62 | )
63 |
64 | from spyne.server.wsgi import WsgiApplication
65 | from wsgiref.simple_server import make_server
66 |
67 | server = make_server(host, port, WsgiApplication(rest))
68 |
69 | logging.basicConfig(level=logging.DEBUG)
70 | logging.info("listening to http://%s:%d" % (host, port))
71 |
72 | server.serve_forever()
73 |
--------------------------------------------------------------------------------