Skip to content

Commit 9d31ec5

Browse files
committed
Added RestInstance and calling rest from client.py
committer: Ralf Schlatterbeck <[email protected]>
1 parent 8ec68b0 commit 9d31ec5

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

roundup/cgi/client.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class SysCallError(Exception):
3535
from roundup.mailer import Mailer, MessageSendError
3636
from roundup.cgi import accept_language
3737
from roundup import xmlrpc
38+
from roundup import rest
3839

3940
from roundup.anypy.cookie_ import CookieError, BaseCookie, SimpleCookie, \
4041
get_cookie_date
@@ -428,6 +429,8 @@ def main(self):
428429
try:
429430
if self.path == 'xmlrpc':
430431
self.handle_xmlrpc()
432+
elif self.path == 'rest' or self.path[:5] == 'rest/':
433+
self.handle_rest()
431434
else:
432435
self.inner_main()
433436
finally:
@@ -484,6 +487,27 @@ def handle_xmlrpc(self):
484487
self.setHeader("Content-Length", str(len(output)))
485488
self.write(output)
486489

490+
def handle_rest(self):
491+
# Pull the parameters data out of the form. The "value" attribute
492+
# will be the raw content of the request.
493+
input = self.form.value
494+
495+
# Set the charset and language
496+
self.determine_charset()
497+
self.determine_language()
498+
# Open the database as the correct user.
499+
# TODO: add everything to RestfulDispatcher
500+
self.determine_user()
501+
self.check_anonymous_access()
502+
503+
# Call rest library to handle the request
504+
handler = rest.RestfulInstance(self.db)
505+
output = handler.dispatch(self.env['REQUEST_METHOD'], self.path, input)
506+
507+
# self.setHeader("Content-Type", "text/xml")
508+
self.setHeader("Content-Length", str(len(output)))
509+
self.write(output)
510+
487511
def add_ok_message(self, msg, escape=True):
488512
add_message(self._ok_message, msg, escape)
489513

@@ -1354,7 +1378,7 @@ def determine_context(self, dre=re.compile(r'([^\d]+)0*(\d+)')):
13541378
if int(self.nodeid) > 2**31:
13551379
# Postgres will complain with a ProgrammingError
13561380
# if we try to pass in numbers that are too large
1357-
raise NotFound ('%s/%s'%(self.classname, self.nodeid))
1381+
raise NotFound('%s/%s'%(self.classname, self.nodeid))
13581382
if not klass.hasnode(self.nodeid):
13591383
raise NotFound('%s/%s'%(self.classname, self.nodeid))
13601384
# with a designator, we default to item view

roundup/rest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Restful API for Roundup
2+
#
3+
# This module is free software, you may redistribute it
4+
# and/or modify under the same terms as Python.
5+
#
6+
7+
import json
8+
import pprint
9+
10+
11+
class RestfulInstance(object):
12+
"""Dummy Handler for REST
13+
"""
14+
15+
def __init__(self, db):
16+
# TODO: database, translator and instance.actions
17+
self.db = db
18+
19+
def dispatch(self, method, uri, input):
20+
print method
21+
print uri
22+
print type(input)
23+
pprint.pprint(input)
24+
return ' '.join([method, uri, pprint.pformat(input)])

0 commit comments

Comments
 (0)