Skip to content

Commit

Permalink
psycopg2 does not work on pypy, fixed content types when no header av…
Browse files Browse the repository at this point in the history
…ailable
  • Loading branch information
lsbardel committed Jul 17, 2014
1 parent 539c3ad commit 2b1fc89
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:

install:
- if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install -r requirements_dev_27.txt; fi
- if [[ $TRAVIS_PYTHON_VERSION == 'pypy' ]]; then pip install -r requirements_dev_27.txt; fi
- if [[ $TRAVIS_PYTHON_VERSION == 'pypy' ]]; then pip install -r requirements_dev_pypy.txt; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.3' ]]; then pip install -r requirements_dev_33.txt; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then pip install -r requirements_dev.txt; fi
- python setup.py install
Expand Down
4 changes: 3 additions & 1 deletion examples/chat/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from pulsar.apps.ws import WS, WebSocket
from pulsar.apps.rpc import PulsarServerCommands
from pulsar.apps.data import create_store, PubSubClient
from pulsar.utils.httpurl import JSON_CONTENT_TYPES
from pulsar.apps.ds import pulsards_url
from pulsar.utils.system import json
from pulsar.utils.pep import to_string
Expand Down Expand Up @@ -148,7 +149,8 @@ def setup(self, environ):
pubsub.subscribe(channel)
return WsgiHandler([Router('/', get=self.home_page),
WebSocket('/message', Chat(pubsub, channel)),
Router('/rpc', post=Rpc(pubsub, channel))])
Router('/rpc', post=Rpc(pubsub, channel),
response_content_types=JSON_CONTENT_TYPES)])

def home_page(self, request):
data = open(os.path.join(CHAT_DIR, 'chat.html')).read()
Expand Down
25 changes: 25 additions & 0 deletions pulsar/apps/rpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
:ref:`json-rpc tutorial <tutorials-calculator>` if you want to get started
quickly with a working example.
To quickly setup a server::
class MyRpc(rpc.JSONRPC):
def rpc_ping(self, request):
return 'pong'
class Wsgi(wsgi.LazyWsgi):
def handler(self, environ=None):
app = wsgi.Router('/',
post=MyRpc(),
response_content_types=['application/json'])
return wsgi.wsgiHandler([app])
if __name__ == '__main__':
wsgi.WsgiServer(Wsgi()).start()
* The ``MyRpc`` handles the requests
* Routing is delegated to the :class:`.Router` which handle only ``post``
requests with content type ``application/json``.
API
===========
Expand Down
4 changes: 2 additions & 2 deletions pulsar/apps/ws/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def register_transport(klass):

@register_transport
class WebSocket(wsgi.Router):
"""A :ref:`Router <wsgi-router>` for a websocket handshake.
"""A specialised :class:`.Router` for a websocket handshake.
Once the handshake is succesful, the protocol consumer
Once the handshake is successful, the protocol consumer
is upgraded to :class:`WebSocketProtocol` and messages are handled by
the :attr:`handle` attribute, an instance of :class:`.WS`.
Expand Down
12 changes: 6 additions & 6 deletions pulsar/apps/wsgi/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ def content_type(self, request):
accepted content types and the content types accepted by the client
and figure out the best match.
'''
return request.content_types.best_match(self.response_content_types)
content_types = self.response_content_types
ct = request.content_types.best_match(content_types)
if not ct and content_types:
raise HttpException(status=415, msg=request.content_types)
return ct

def accept_content_type(self, content_type):
'''Check if ``content_type`` is accepted by this :class:`Router`.
Expand Down Expand Up @@ -398,11 +402,7 @@ def response(self, environ, args):
this method to produce the WSGI response.
'''
request = wsgi_request(environ, self, args)
# Set the response content type
content_type = self.content_type(request)
if not content_type:
raise HttpException(status=415, msg=request.content_types)
request.response.content_type = content_type
request.response.content_type = self.content_type(request)
method = request.method.lower()
callable = getattr(self, method, None)
if callable is None:
Expand Down
4 changes: 2 additions & 2 deletions requirements_dev_27.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
trollius
coverage
cython
django
Expand All @@ -6,5 +7,4 @@ setproctitle
psutil
greenlet
sqlalchemy
psycopg2
trollius
psycopg2
2 changes: 1 addition & 1 deletion requirements_dev_33.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
asyncio
coverage
cython
django
Expand All @@ -7,4 +8,3 @@ psutil
greenlet
sqlalchemy
psycopg2
asyncio
9 changes: 9 additions & 0 deletions requirements_dev_pypy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trollius
coverage
cython
django
pep8
setproctitle
psutil
greenlet
sqlalchemy
1 change: 0 additions & 1 deletion tests/wsgi/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,3 @@ def test_child_methods(self):
# It has both get and post methods
self.assertTrue(async.get)
self.assertTrue(async.post)

0 comments on commit 2b1fc89

Please sign in to comment.