Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix tox.ini with latest requirements for this version, get rid of tro…

…ublesome and useless json_body test, backport the egg:pyramid#wsgiref and egg:pyramid#cherrypy server runners
  • Loading branch information...
commit 879ae2600e620617a4e05522be632f3397b19a88 1 parent 6873b16
@mcdonc mcdonc authored
View
8 CHANGES.txt
@@ -1,6 +1,14 @@
Next release (on 1.1 branch)
============================
+Features
+--------
+
+- Backport the ``egg:pyramid#wsgiref`` and ``egg:pyramid#cherrypy`` server
+ runners from the 1.3 branch. This change is to primarily allow scaffolding
+ authors to rely on the wsgiref entry point for projects that are meant to
+ work on both Pyramid 1.1.3 and 1.3.X.
+
Documentation
-------------
View
113 pyramid/paster.py
@@ -519,3 +519,116 @@ def command(self):
self.out(" Not found.")
self.out('')
+# For paste.deploy server instantiation (egg:pyramid#wsgiref)
+def wsgiref_server_runner(wsgi_app, global_conf, **kw): # pragma: no cover
+ from wsgiref.simple_server import make_server
+ host = kw.get('host', '0.0.0.0')
+ port = int(kw.get('port', 8080))
+ server = make_server(host, port, wsgi_app)
+ print('Starting HTTP server on http://%s:%s' % (host, port))
+ server.serve_forever()
+
+# For paste.deploy server instantiation (egg:pyramid#cherrypy)
+def cherrypy_server_runner(
+ app, global_conf=None, host='127.0.0.1', port=None,
+ ssl_pem=None, protocol_version=None, numthreads=None,
+ server_name=None, max=None, request_queue_size=None,
+ timeout=None
+ ): # pragma: no cover
+ """
+ Entry point for CherryPy's WSGI server
+
+ Serves the specified WSGI app via CherryPyWSGIServer.
+
+ ``app``
+
+ The WSGI 'application callable'; multiple WSGI applications
+ may be passed as (script_name, callable) pairs.
+
+ ``host``
+
+ This is the ipaddress to bind to (or a hostname if your
+ nameserver is properly configured). This defaults to
+ 127.0.0.1, which is not a public interface.
+
+ ``port``
+
+ The port to run on, defaults to 8080 for HTTP, or 4443 for
+ HTTPS. This can be a string or an integer value.
+
+ ``ssl_pem``
+
+ This an optional SSL certificate file (via OpenSSL) You can
+ generate a self-signed test PEM certificate file as follows:
+
+ $ openssl genrsa 1024 > host.key
+ $ chmod 400 host.key
+ $ openssl req -new -x509 -nodes -sha1 -days 365 \\
+ -key host.key > host.cert
+ $ cat host.cert host.key > host.pem
+ $ chmod 400 host.pem
+
+ ``protocol_version``
+
+ The protocol used by the server, by default ``HTTP/1.1``.
+
+ ``numthreads``
+
+ The number of worker threads to create.
+
+ ``server_name``
+
+ The string to set for WSGI's SERVER_NAME environ entry.
+
+ ``max``
+
+ The maximum number of queued requests. (defaults to -1 = no
+ limit).
+
+ ``request_queue_size``
+
+ The 'backlog' argument to socket.listen(); specifies the
+ maximum number of queued connections.
+
+ ``timeout``
+
+ The timeout in seconds for accepted connections.
+ """
+ is_ssl = False
+ if ssl_pem:
+ port = port or 4443
+ is_ssl = True
+
+ if not port:
+ if ':' in host:
+ host, port = host.split(':', 1)
+ else:
+ port = 8080
+ bind_addr = (host, int(port))
+
+ kwargs = {}
+ for var_name in ('numthreads', 'max', 'request_queue_size', 'timeout'):
+ var = locals()[var_name]
+ if var is not None:
+ kwargs[var_name] = int(var)
+
+ from cherrypy import wsgiserver
+
+ server = wsgiserver.CherryPyWSGIServer(bind_addr, app,
+ server_name=server_name, **kwargs)
+ server.ssl_certificate = server.ssl_private_key = ssl_pem
+ if protocol_version:
+ server.protocol = protocol_version
+
+ try:
+ protocol = is_ssl and 'https' or 'http'
+ if host == '0.0.0.0':
+ print('serving on 0.0.0.0:%s view at %s://127.0.0.1:%s' %
+ (port, protocol, port))
+ else:
+ print('serving on %s://%s:%s' % (protocol, host, port))
+ server.start()
+ except (KeyboardInterrupt, SystemExit):
+ server.stop()
+
+ return server
View
9 pyramid/tests/test_request.py
@@ -243,15 +243,6 @@ def test_json_body_valid_json(self):
request.body = '{"a":1}'
self.assertEqual(request.json_body, {'a':1})
- def test_json_body_alternate_charset(self):
- from pyramid.compat import json
- request = self._makeOne({'REQUEST_METHOD':'POST'})
- request.charset = 'latin-1'
- la = unicode('La Pe\xc3\xb1a', 'utf-8')
- body = json.dumps({'a':la}, encoding='latin-1')
- request.body = body
- self.assertEqual(request.json_body, {'a':la})
-
def test_json_body_GET_request(self):
request = self._makeOne({'REQUEST_METHOD':'GET'})
self.assertRaises(ValueError, getattr, request, 'json_body')
View
3  setup.py
@@ -88,6 +88,9 @@
pviews=pyramid.paster:PViewsCommand
[console_scripts]
bfg2pyramid = pyramid.fixers.fix_bfg_imports:main
+ [paste.server_runner]
+ wsgiref = pyramid.paster:wsgiref_server_runner
+ cherrypy = pyramid.paster:cherrypy_server_runner
"""
)
View
25 tox.ini
@@ -10,10 +10,31 @@ deps =
WebTest
repoze.sphinx.autointerface
virtualenv
+ zope.configuration<3.8.0
+
+[testenv:py25]
+commands =
+ python setup.py test -q
+deps =
+ https://github.com/Pylons/webob/zipball/1.1-branch
+ Sphinx
+ WebTest
+ repoze.sphinx.autointerface
+ virtualenv
+ zope.configuration<3.8.0
+ zope.schema<4.0.0
[testenv:jython]
commands =
- jython setup.py test -q
+ jython setup.py test -q
+deps =
+ https://github.com/Pylons/webob/zipball/1.1-branch
+ Sphinx
+ WebTest
+ repoze.sphinx.autointerface
+ virtualenv
+ zope.configuration<3.8.0
+ zope.schema<4.0.0
[testenv:cover]
basepython =
@@ -28,8 +49,8 @@ deps =
nose
coverage==3.4
nosexcover
+ zope.configuration<3.8.0
# we separate coverage into its own testenv because a) "last run wins" wrt
# cobertura jenkins reporting and b) pypy and jython can't handle any
# combination of versions of coverage and nosexcover that i can find.
-
Please sign in to comment.
Something went wrong with that request. Please try again.