Ejemplo n.º 1
0
    def _search(self, url, show=None):
        bottle.request.environ['REQUEST_URI'] = url
        search_result = self.resource.get_matching_items(url)
        bottle.request = bottle.LocalRequest()

        show = self._default_show if show is None else show
        if show is None:
            return search_result[u'resources']
        else:
            return [x[show] for x in search_result[u'resources']]
Ejemplo n.º 2
0
	def POST(self, pdata, callback, *args):
		self.response = None
		post = self.__postData(pdata)
		data = json.dumps(post['data']).encode('utf-8')
		headers = json.dumps(post['headers'])
		try:
			self.request(body = data, headers = headers)
			resp = callback(*args)
			self.response = resp.strip()
		finally:
			del bottle.request
			bottle.request = bottle.LocalRequest()
Ejemplo n.º 3
0
 def request(self, method='GET', path='/', qs='', body=None, post=None):
     if post is not None:
         method = 'POST'
     blen = 0
     if body is not None:
         blen = len(body)
     env = {
         'REQUEST_METHOD': method,
         'PATH_INFO': path,
         'QUERY_STRING': qs,
         'CONTENT_LENGTH': str(blen),
     }
     req = bottle.LocalRequest(environ=env)
     req.environ['wsgi.input'] = BytesIO()
     if blen > 0:
         req.environ['wsgi.input'].write(body)
         req.environ['wsgi.input'].seek(0, 0)
     if post is not None:
         for k, v in post.items():
             req.forms.replace(k, v)
     assert req.method == method
     assert req.path == path
     return req
Ejemplo n.º 4
0
 def tearDown(self):
     # Reset bottle request.
     bottle.request = bottle.LocalRequest()