예제 #1
0
 def do_GET(self):
     path, args = parse_url(self.path)
     if not path:
         path = ["index"]
     name_path = path[0].replace(".", "_")
     if len(path) > 1:
         rest = os.path.sep.join(path[1:])
     else:
         rest = None
     method_to_call = getattr(self, name_path, None)
     if method_to_call is None or not getattr(method_to_call, "exposed", None):
         exec_meth = getattr(self.exported_methods, name_path, None)
         if exec_meth is None:
             self.send_error(404, "File %s not found" % path)
         else:
             self.serve_data("text/json", json.write(exec_meth(**args)), True)
     else:
         if rest:
             outp = method_to_call(rest, **args)
         else:
             outp = method_to_call(**args)
         if isinstance(outp, (str, unicode)):
             self.serve_data("text/html", outp)
         elif isinstance(outp, tuple):
             self.serve_data(*outp)
         else:
             raise ValueError("Don't know how to serve %s" % (outp,))
예제 #2
0
 def do_GET(self):
     path, args = parse_url(self.path)
     if not path:
         path = ["index"]
     name_path = path[0].replace(".", "_")
     if len(path) > 1:
         rest = os.path.sep.join(path[1:])
     else:
         rest = None
     method_to_call = getattr(self, name_path, None)
     if method_to_call is None or not getattr(method_to_call, 'exposed',
                                              None):
         exec_meth = getattr(self.exported_methods, name_path, None)
         if exec_meth is None:
             self.send_error(404, "File %s not found" % path)
         else:
             self.serve_data('text/json', json.write(exec_meth(**args)),
                             True)
     else:
         if rest:
             outp = method_to_call(rest, **args)
         else:
             outp = method_to_call(**args)
         if isinstance(outp, (str, unicode)):
             self.serve_data('text/html', outp)
         elif isinstance(outp, tuple):
             self.serve_data(*outp)
         else:
             raise ValueError("Don't know how to serve %s" % (outp, ))
예제 #3
0
def test_url():
    assert parse_url("path") == (["path"], {})
    assert parse_url("a/b/c/d") == (["a", "b", "c", "d"], {})
    assert parse_url("/a/b") == (["a", "b"], {})
    assert parse_url("/a/b/c/") == (["a", "b", "c"], {})
    assert parse_url("a/b?q=a&c=z") == (["a", "b"], {"q": "a", "c": "z"})
    got = parse_url('/get_message?sid=2ed&pid=-1')
    assert got == (["get_message"], {'pid': '-1', 'sid': '2ed'})
예제 #4
0
def test_url():
    assert parse_url("path") == (["path"], {})
    assert parse_url("a/b/c/d") == (["a", "b", "c", "d"], {})
    assert parse_url("/a/b") == (["a", "b"], {})
    assert parse_url("/a/b/c/") == (["a", "b", "c"], {})
    assert parse_url("a/b?q=a&c=z") == (["a","b"], {"q":"a", "c":"z"})
    got = parse_url('/get_message?sid=2ed&pid=-1')
    assert got == (["get_message"], {'pid':'-1', 'sid':'2ed'})
예제 #5
0
 def do_GET(self, send_body=True):
     """ perform a request """
     path, query = self.process_path(self.path)
     _, args = parse_url("?" + query)
     try:
         resource = self.find_resource(path)
         # XXX strange hack
         if hasattr(resource, "im_self"):
             resource.im_self.server = self.server
         retval = resource(**args)
         if isinstance(retval, str):
             headers = {"Content-Type": "text/html"}
             data = retval
         else:
             headers, data = retval
             if isinstance(headers, str):
                 headers = {"Content-Type": headers}
     except HTTPError, e:
         status = e.status
         headers, data = self.process_http_error(e)
예제 #6
0
 def do_GET(self, send_body=True):
     """ perform a request """
     path, query = self.process_path(self.path)
     _, args = parse_url("?" + query)
     try:
         resource = self.find_resource(path)
         # XXX strange hack
         if hasattr(resource, 'im_self'):
             resource.im_self.server = self.server
         retval = resource(**args)
         if isinstance(retval, str):
             headers = {'Content-Type': 'text/html'}
             data = retval
         else:
             headers, data = retval
             if isinstance(headers, str):
                 headers = {'Content-Type': headers}
     except HTTPError, e:
         status = e.status
         headers, data = self.process_http_error(e)