@@ -35,6 +35,7 @@ class SysCallError(Exception):
3535from roundup .mailer import Mailer , MessageSendError
3636from roundup .cgi import accept_language
3737from roundup import xmlrpc
38+ from roundup import rest
3839
3940from 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
0 commit comments