示例#1
0
 def serve_request(self, path):
     """Given an URL path, return response.
     """
     request = Request(uri=path)
     request.website = self
     response = self.handle_safely(request)
     return response
示例#2
0
文件: website.py 项目: joonas/aspen
 def serve_request(self, path):
     """Given an URL path, return response.
     """
     request = Request(uri=path)
     request.website = self
     response = self.handle_safely(request)
     return response
示例#3
0
文件: website.py 项目: joonas/aspen
 def load_simplate(self, path, request=None, return_request_too=False):
     """Given an URL path, return a simplate (Resource) object.
     """
     if request is None:
         request = Request(uri=path)
     if not hasattr(request, 'website'):
         request.website = self
     self.do_inbound(request)
     resource = resources.get(request)
     if return_request_too:
         return resource, request
     else:
         return resource
示例#4
0
 def load_simplate(self, path, request=None, return_request_too=False):
     """Given an URL path, return a simplate (Resource) object.
     """
     if request is None:
         request = Request(uri=path)
     if not hasattr(request, 'website'):
         request.website = self
     self.do_inbound(request)
     resource = resources.get(request)
     if return_request_too:
         return resource, request
     else:
         return resource
def test_transport_handles_roundtrip(make_transport):
    transport = make_transport(state=1, content="socket.send(socket.recv())")

    request = Request('POST',
                      '/echo.sock',
                      body=StringIO(b"3::/echo.sock:ping"))
    transport.respond(request)
    transport.socket.tick()  # do it manually

    request = Request('GET', '/echo.sock')
    response = transport.respond(request)

    expected = FFFD + b"18" + FFFD + b"3::/echo.sock:ping"
    actual = response.body.next()
    assert actual == expected
def test_transport_can_minimally_respond(make_transport):
    transport = make_transport()
    request = Request()

    expected = Response
    actual = transport.respond(request).__class__
    assert actual is expected
示例#7
0
 def get_request(self, path, method="GET", body=None, **extra):
     env = StubWSGIRequest(path)
     env['REQUEST_METHOD'] = method
     env['wsgi.input'] = StringIO(body)
     env['HTTP_COOKIE'] = self.cookies.output(header='', sep='; ')
     env.update(extra)
     return Request.from_wsgi(env)
示例#8
0
 def get_request(self, path, method="GET", body=None, **extra):
     env = StubWSGIRequest(path)
     env["REQUEST_METHOD"] = method
     env["wsgi.input"] = StringIO(body)
     env["HTTP_COOKIE"] = self.cookies.output(header="", sep="; ")
     env.update(extra)
     return Request.from_wsgi(env)
示例#9
0
def test_intercept_socket_intercepts_transported():
    request = Request(uri="/foo.sock/1/websocket/46327hfjew3?foo=bar")
    gauntlet.intercept_socket(request)

    expected = ('/foo.sock', '1/websocket/46327hfjew3')
    actual = (request.line.uri.path.decoded, request.socket)
    assert actual == expected, actual
示例#10
0
def test_intercept_socket_intercepts_handshake():
    request = Request(uri="/foo.sock/1")
    gauntlet.intercept_socket(request)

    expected = ('/foo.sock', '1')
    actual = (request.line.uri.path.decoded, request.socket)
    assert actual == expected, actual
def test_transport_starts_in_state_0(make_transport):
    transport = make_transport()
    request = Request()

    expected = 0
    actual = transport.state
    assert actual == expected
def test_transport_goes_to_state_1_after_first_request(make_transport):
    transport = make_transport()
    request = Request()
    transport.respond(request)

    expected = 1
    actual = transport.state
    assert actual == expected
示例#13
0
 def __call__(self, environ, start_response):
     """WSGI interface.
     """
     request = Request.from_wsgi(environ)  # too big to fail :-/
     response = self.handle_safely(request)
     response.request = request  # Stick this on here at the last minute
     # in order to support close hooks.
     return response(environ, start_response)
 def make_transport(content='', state=0):
     mk(('echo.sock.spt', content))
     socket = make_socket()
     transport = XHRPollingTransport(socket)
     transport.timeout = 0.05  # for testing, could screw up the test
     if state == 1:
         transport.respond(Request(uri='/echo.sock'))
     return transport
示例#15
0
 def __call__(self, environ, start_response):
     """WSGI interface.
     """
     request = Request.from_wsgi(environ) # too big to fail :-/
     response = self.handle_safely(request)
     response.request = request # Stick this on here at the last minute
                                # in order to support close hooks.
     return response(environ, start_response)
示例#16
0
 def get_request(self, path, method="GET", body=None,
                 **extra):
     env = StubWSGIRequest(path)
     env['REQUEST_METHOD'] = method
     env['wsgi.input'] = StringIO(body)
     env['HTTP_COOKIE'] = self.cookies.output(header='', sep='; ')
     env.update(extra)
     return Request.from_wsgi(env)
示例#17
0
 def get_request(self, path, method="GET", body=None,
                 **extra):
     env = StubWSGIRequest(path.encode('utf8'))
     env[b'REQUEST_METHOD'] = method.encode('utf8')
     env[b'wsgi.input'] = StringIO(body)
     env[b'HTTP_COOKIE'] = self.cookies.output(header='', sep='; ').encode('utf8')
     for k,v in extra.items():
         env[k.encode('utf8')] = v.encode('utf8')
     return Request.from_wsgi(env)
示例#18
0
 def get_request(self, path, method="GET", body=None, **extra):
     env = StubWSGIRequest(path.encode('utf8'))
     env[b'REQUEST_METHOD'] = method.encode('utf8')
     env[b'wsgi.input'] = StringIO(body)
     env[b'HTTP_COOKIE'] = self.cookies.output(header='',
                                               sep='; ').encode('utf8')
     for k, v in extra.items():
         env[k.encode('utf8')] = v.encode('utf8')
     return Request.from_wsgi(env)
def test_transport_GET_gets_data_from_socket(make_transport):
    transport = make_transport(state=1)
    message = Message.from_bytes(b"3:::Greetings, program!")
    transport.socket.outgoing.put(message)

    request = Request('GET')
    response = transport.respond(request)

    expected = FFFD + b'23' + FFFD + b'3:::Greetings, program!'
    actual = response.body.next()
    assert actual == expected
def test_transport_POST_gives_data_to_socket(make_transport):
    transport = make_transport(state=1)

    request = Request('POST',
                      '/echo.sock',
                      body=StringIO(b'3::/echo.sock:Greetings, program!'))
    transport.respond(request)

    expected = deque(['Greetings, program!'])
    actual = transport.socket.incoming.queue
    assert actual == expected
示例#21
0
 def from_fs(cls, fs):
     """Takes a path under ./fsfix using / as the path separator.
     """
     fs = os.sep.join(fs.split('/'))
     request = Request.from_wsgi(StubWSGIRequest(fs))
     c = Configurable.from_argv(['fsfix'])
     c.copy_configuration_to(request)
     request.fs = fs
     request.namespace = {}
     request.website = Stub()
     request.website.template_loader = Stub()
     return request
示例#22
0
文件: __init__.py 项目: jatr/aspen
 def from_fs(cls, fs):
     """Takes a path under ./fsfix using / as the path separator.
     """
     fs = os.sep.join(fs.split(os.sep))
     request = Request.from_wsgi(StubWSGIRequest(fs))
     website = Configurable.from_argv(['--root', 'fsfix'])
     website.copy_configuration_to(request)
     request.root = join(dirname(__file__), 'fsfix')
     request.fs = fs
     request.namespace = {}
     request.website = website 
     request.website.template_loader = Stub()
     return request
示例#23
0
 def from_fs(cls, fs, *a):
     """Takes a path under FSFIX using / as the path separator.
     """
     fs = os.sep.join(fs.split(os.sep))
     request = Request.from_wsgi(StubWSGIRequest(fs))
     website = Website([ '--www_root', FSFIX
                       , '--project_root', '.aspen'
                        ] + list(a))
     request.www_root = os.path.join(os.path.dirname(__file__), FSFIX)
     request.fs = fs
     request.context = {}
     request.website = website
     request._media_type = None
     return request
示例#24
0
 def from_fs(cls, fs, *a):
     """Takes a path under FSFIX using / as the path separator.
     """
     fs = os.sep.join(fs.split(os.sep))
     request = Request.from_wsgi(StubWSGIRequest(fs))
     website = Configurable.from_argv([ '--www_root', FSFIX
                                      , '--project_root', '.aspen'
                                       ] + list(a))
     request.www_root = os.path.join(os.path.dirname(__file__), FSFIX)
     request.fs = fs
     request.context = {}
     request.website = website 
     request._media_type = None
     return request
示例#25
0
    def wsgi_app(self, environ, start_response):
        """WSGI interface.

        Wrap this method instead of the website object itself
        when to use WSGI middleware::

            website = Website()
            website.wsgi_app = WSGIMiddleware(website.wsgi_app)

        """
        request = Request.from_wsgi(environ) # too big to fail :-/
        request.website = self
        response = self.handle_safely(request)
        response.request = request # Stick this on here at the last minute
                                   # in order to support close hooks.
        return response(environ, start_response)
示例#26
0
    def wsgi_app(self, environ, start_response):
        """WSGI interface.

        Wrap this method instead of the website object itself
        when to use WSGI middleware::

            website = Website()
            website.wsgi_app = WSGIMiddleware(website.wsgi_app)

        """
        request = Request.from_wsgi(environ) # too big to fail :-/
        request.website = self
        response = self.handle_safely(request)
        response.request = request # Stick this on here at the last minute
                                   # in order to support close hooks.
        return response(environ, start_response)
示例#27
0
 def from_fs(cls, fs, *a):
     """Takes a path under FSFIX using / as the path separator.
     """
     fs = os.sep.join(fs.split(os.sep))
     uri_path = fs
     if fs.endswith('.spt'):
         uri_path = fs[:-4]
     request = Request.from_wsgi(StubWSGIRequest(uri_path))
     website = Website([ '--www_root', FSFIX
                       , '--project_root', os.path.join(FSFIX, '.aspen')
                        ] + list(a))
     request.www_root = os.path.join(os.path.dirname(__file__), FSFIX)
     request.fs = fs
     request.context = {}
     request.website = website
     request._media_type = None
     return request
示例#28
0
def make_request():
    return Request.from_diesel(DieselReq())
示例#29
0
def test_blank_by_default():
    assert_raises(AttributeError, lambda: Request().version)
示例#30
0
文件: __init__.py 项目: dowski/aspen
def handle(path):
    website = Website(Configuration(['fsfix']))
    return website.handle(Request.from_diesel(DieselReq(path)))
示例#31
0
 def __call__(cls, path='/'):
     return Request.from_wsgi(StubWSGIRequest(path))
示例#32
0
 def test_allows_certain_methods(self):
     for allowed in ('GEt', 'HEaD', 'PosT'):
         request = Request(allowed)
         assert security.only_allow_certain_methods(request) is None
示例#33
0
 def __call__(cls, uripath=b'/'):
     typecheck(uripath, str)
     return Request.from_wsgi(StubWSGIRequest(uripath))
示例#34
0
文件: sockets.py 项目: gunshor/aspen
def make_request(filename='echo.sock'):
    request = Request(uri='/echo.sock')
    request.website = Website([])
    request.fs = fix(filename)
    return request
示例#35
0
文件: sockets.py 项目: buchuki/aspen
def make_request(filename='echo.sock'):
    request = Request(url='/echo.sock')
    request.website = Website([])
    request.website.copy_configuration_to(request)
    request.fs = fix(filename)
    return request
示例#36
0
 def __call__(cls, uripath='/'):
     return Request.from_wsgi(StubWSGIRequest(uripath))
示例#37
0
def make_request(filename='echo.sock'):
    request = Request(url='/echo.sock')
    request.website = Website([])
    request.website.copy_configuration_to(request)
    request.fs = os.sep.join([os.path.dirname(__file__), 'fsfix', filename])
    return request
示例#38
0
def make_request(filename="echo.sock.spt"):
    request = Request(uri="/echo.sock")
    request.website = Website([])
    request.fs = fix(filename)
    return request
示例#39
0
def get_simplate_context(website, fs):
    request = Request()
    request.fs = fs
    request.website = website
    resource = resources.get(request)
    return {} if isinstance(resource, StaticResource) else resource.pages[0]
示例#40
0
 def make_socket_request(self, filename="echo.sock.spt"):
     request = Request(uri="/echo.sock")
     request.website = self.client.website
     request.fs = self.fs.www.resolve(filename)
     return request
示例#41
0
def test_sockets_get_nonsock_returns_None():
    request = Request()
    request.socket = None
    expected = None
    actual = sockets.get(request)
    assert actual is expected, actual
示例#42
0
def test_raw_is_raw():
    request = Request()
    expected = b"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"
    actual = request
    assert actual == expected
示例#43
0
def test_request_redirect_works_on_instance():
    request = Request()
    actual = raises(Response, request.redirect, '/').value.code
    assert actual == 302
示例#44
0
def get_simplate_context(website, fs):
    request = Request()
    request.fs = fs
    request.website = website
    resource = resources.get(request)
    return {} if isinstance(resource, StaticResource) else resource.pages[0]
示例#45
0
def test_intercept_socket_intercepts_transported():
    request = Request(uri="/foo.sock/1/websocket/46327hfjew3?foo=bar")
    actual = dispatcher.extract_socket_info(request.line.uri.path.decoded)
    expected = ('/foo.sock', '1/websocket/46327hfjew3')
    assert actual == expected
示例#46
0
def test_intercept_socket_intercepts_handshake():
    request = Request(uri="/foo.sock/1")
    actual = dispatcher.extract_socket_info(request.line.uri.path.decoded)
    expected = ('/foo.sock', '1')
    assert actual == expected
示例#47
0
 def __call__(self, environ, start_response):
     """WSGI interface.
     """
     request = Request.from_wsgi(environ) # too big to fail :-/
     response = self.handle(request)
     return response(environ, start_response)
示例#48
0
def test_intercept_socket_protects_direct_access():
    request = Request(uri="/foo.sock")
    raises(Response, dispatcher.dispatch, request)
示例#49
0
 def test_disallows_a_bunch_of_other_stuff(self):
     for disallowed in ('OPTIONS', 'TRACE', 'TRACK', 'PUT', 'DELETE'):
         request = Request(disallowed)
         response = raises(Response, security.only_allow_certain_methods,
                           request).value
         assert response.code == 405
示例#50
0
文件: website.py 项目: dowski/aspen
 def __call__(self, diesel_request):
     """Given a Diesel request, return a Diesel response.
     """
     request = Request.from_diesel(diesel_request) # too big to fail :-/
     response = self.handle(request)
     return response._to_diesel(diesel_request) # sends bits, returns bool
示例#51
0
def parse_environ_into_request(environ):
    return {'request': Request.from_wsgi(environ)}
示例#52
0
def make_request(filename='echo.sock'):
    request = Request(uri='/echo.sock')
    request.website = Website([])
    request.fs = fix(filename)
    return request
示例#53
0
def test_sockets_get_nonsock_returns_None():
    request = Request()
    request.socket = None
    expected = None
    actual = sockets.get(request)
    assert actual is expected, actual
示例#54
0
def check():
    website = Website(Configuration(['fsfix']))
    response = website.handle(Request.from_diesel(DieselReq()))
    return response