当前位置: 首页>>代码示例>>Python>>正文


Python werkzeug.Request类代码示例

本文整理汇总了Python中werkzeug.Request的典型用法代码示例。如果您正苦于以下问题:Python Request类的具体用法?Python Request怎么用?Python Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

    def __call__(self, environ, start_response):
        request = Request(environ)
        lang = request.values.get('_lang')
        if lang is None:
            lang = (request.accept_languages.best or 'en').split('-')[0].lower()
        if not has_language(lang):
            lang = 'en'
        request.translations = load_core_translations(lang)
        request.translations.language = lang
        response = None

        if request.path == '/':
            view = request.values.get('_current', 'start')
            if request.values.get('_startsetup'):
                response = self.start_setup(request)
            elif view in self.views:
                handler = self.views[view]
                if handler is not None and \
                   request.values.get('_next'):
                    ctx = handler(request)
                    if ctx is not None:
                        response = self.handle_view(request, view, ctx)

                if response is None:
                    if request.values.get('_next'):
                        view = self.next[view]
                    elif request.values.get('_prev'):
                        view = self.prev[view]
                    response = self.handle_view(request, view)

        if response is None:
            response = redirect('')
        return response(environ, start_response)
开发者ID:adityaathalye,项目名称:zine,代码行数:33,代码来源:__init__.py

示例2: __init__

 def __init__(self, environ, populate_request=True, shallow=False):
     ResponseBase.__init__(self)
     RequestBase.__init__(self, environ, populate_request, shallow)
     self.href = Href(self.script_root or "/", self.charset)
     self.abs_href = Href(self.url_root, self.charset)
     self.headers = Headers([("Content-Type", "text/html")])
     self.response = []
     self.status_code = 200
开发者ID:microcosmx,项目名称:experiments,代码行数:8,代码来源:request.py

示例3: __init__

 def __init__(self, *args, **kwargs):
     self.context = {}
     Request.__init__(self, *args, **kwargs)
     # self.stream, self.form, self.files = parse_form_data(self.environ)
     
     self.context.update(self.args.to_dict())
     self.context.update(self.form.to_dict())
     self.context.update(self.cookies)
     self.context['request'] = self
开发者ID:weixionghan,项目名称:xweb,代码行数:9,代码来源:web.py

示例4: __init__

 def __init__(self, environ):
     RequestBase.__init__(self, environ)
     before_request_init.emit()
     self.url_adapter = url_map.bind_to_environ(self.environ)
     self.match_exception = None
     try:
         self.endpoint, self.view_arguments = self.url_adapter.match()
     except HTTPException, e:
         self.endpoint = self.view_arguments = None
         self.match_exception = e
开发者ID:amadev,项目名称:rater,代码行数:10,代码来源:application.py

示例5: wsgi_app

    def wsgi_app(self, environ, start_response):
        adapter = self.routes.bind_to_environ(environ)

        try:
            endpoint, args = adapter.match()
        except HTTPException as e:
            rv = e
        else:
            req = Request(environ)
            req.view_args = args
            rv = self.make_response(self.views[endpoint](req))

        return rv(environ, start_response)
开发者ID:bryant,项目名称:prym,代码行数:13,代码来源:prym.py

示例6: _send_with_auth

def _send_with_auth(values, secret_key, url):
  """Send dictionary of JSON serializable `values` as a POST body to `url`
     along with `auth_token` that's generated from `secret_key` and `values`

  scheduler.auth.create_token expects a JSON serializable payload, so we send
  a dictionary. On the receiving end of the POST request, the Flask view will
  have access to a werkzeug.datastructures.ImmutableMultiDict. The easiest
  and most surefire way to ensure that the payload sent to create_token will
  be consistent on both ends is to generate an ImmutableMultiDict using the
  werkzeug.Request.
  """

  data = urllib.urlencode(values)

  # Simulate a Flask request because that is what will be unpacked when the
  # request is received on the other side
  request = Request.from_values(
    content_length=len(data),
    input_stream=StringIO(data),
    content_type='application/x-www-form-urlencoded',
    method='POST')

  # Add the auth_token, re-encode, and send
  values['auth_token'] = create_token(secret_key, dict(request.form))
  data = urllib.urlencode(values)
  req = urllib2.Request(url, data)
  response = urllib2.urlopen(req)
  return json.loads(response.read())
开发者ID:derek-schultz,项目名称:chronology,代码行数:28,代码来源:client.py

示例7: test_wrapper_support

def test_wrapper_support():
    """Securecookie wrapper integration"""
    req = Request.from_values()
    resp = Response()
    c = SecureCookie.load_cookie(req, secret_key='foo')
    assert c.new
    c['foo'] = 42
    assert c.secret_key == 'foo'
    c.save_cookie(resp)

    req = Request.from_values(headers={
        'Cookie':  'session="%s"' % parse_cookie(resp.headers['set-cookie'])['session']
    })
    c2 = SecureCookie.load_cookie(req, secret_key='foo')
    assert not c2.new
    assert c2 == c
开发者ID:marchon,项目名称:checkinmapper,代码行数:16,代码来源:test_securecookie.py

示例8: test_large_file

def test_large_file():
    """Test a largish file."""
    data = "x" * (1024 * 600)
    req = Request.from_values(data={"foo": (StringIO(data), "test.txt")}, method="POST")
    # make sure we have a real file here, because we expect to be
    # on the disk.  > 1024 * 500
    assert isinstance(req.files["foo"].stream, file)
开发者ID:s0undt3ch,项目名称:werkzeug,代码行数:7,代码来源:test_formparser.py

示例9: test_nonstandard_line_endings

def test_nonstandard_line_endings():
    """Test nonstandard line endings of multipart form data"""
    for nl in "\n", "\r", "\r\n":
        data = nl.join(
            (
                "--foo",
                "Content-Disposition: form-data; name=foo",
                "",
                "this is just bar",
                "--foo",
                "Content-Disposition: form-data; name=bar",
                "",
                "blafasel",
                "--foo--",
            )
        )
        req = Request.from_values(
            input_stream=StringIO(data),
            content_length=len(data),
            content_type="multipart/form-data; " "boundary=foo",
            method="POST",
        )
        print req.form
        assert req.form["foo"] == "this is just bar"
        assert req.form["bar"] == "blafasel"
开发者ID:s0undt3ch,项目名称:werkzeug,代码行数:25,代码来源:test_formparser.py

示例10: test_large_file

def test_large_file():
    """Test a largish file."""
    data = 'x' * (1024 * 600)
    req = Request.from_values(data={'foo': (StringIO(data), 'test.txt')},
                              method='POST')
    # make sure we have a real file here, because we expect to be
    # on the disk.  > 1024 * 500
    assert isinstance(req.files['foo'].stream, file)
开发者ID:marchon,项目名称:checkinmapper,代码行数:8,代码来源:test_formparser.py

示例11: dispatch

    def dispatch(self, environ, start_response):
        local.application = self
        request = Request(environ)
        local.url_adapter = adapter = url_map.bind_to_environ(environ)

        request.debug = self.debug
        
        request.session = SecureCookie.load_cookie(request, 
                                                   key='com.kinaj.session', 
                                                   secret_key='kinaj')
        
        try:
            endpoint, values = adapter.match()
            handler = getattr(views, endpoint)
            response = handler(request, **values)
            
        except NotFound, e:
            response = views.not_found(request)
            response.status_code = 404
开发者ID:kinaj,项目名称:kinaj,代码行数:19,代码来源:application.py

示例12: __init__

 def __init__(self, environ):
     RequestBase.__init__(self, environ)
     before_request_init.emit()
     self.url_adapter = url_map.bind_to_environ(self.environ)
     self.view_lang = self.match_exception = None
     try:
         self.endpoint, self.view_arguments = self.url_adapter.match()
         view_lang = self.view_arguments.pop('lang_code', None)
         if view_lang is not None:
             try:
                 self.view_lang = Locale.parse(view_lang)
                 if not has_section(self.view_lang):
                     raise UnknownLocaleError(str(self.view_lang))
             except UnknownLocaleError:
                 self.view_lang = None
                 self.match_exception = NotFound()
     except HTTPException, e:
         self.endpoint = self.view_arguments = None
         self.match_exception = e
开发者ID:DasIch,项目名称:solace,代码行数:19,代码来源:application.py

示例13: dispatch

	def dispatch(self, environ, start_response):
		local.application = self
		request = Request(environ)

		## this is where we load the cookie if any, or create a new one
		sid = request.cookies.get('kif415-helfer-login')
		if sid is None:
			request.session = session_store.new()
		else:
			request.session = session_store.get(sid)
			if not validate_session(request.session):
				session_store.delete(request.session)
				request.session = session_store.new()
				request.session['logout'] = True

		local.url_adapter = adapter = url_map.bind_to_environ(environ)
		try:
			endpoint, values = adapter.match()
			handler = getattr(views, endpoint)
			response = handler(request, **values)
		except HTTPException, e:
			response = e # XXX hrm? this breaks when setting cookies!
开发者ID:t-animal,项目名称:helfertool,代码行数:22,代码来源:application.py

示例14: test_multipart_file_no_content_type

def test_multipart_file_no_content_type():
    """Chrome does not always provide a content type."""
    data = (
        '--foo\r\n'
        'Content-Disposition: form-data; name="test"; filename="test.txt"\r\n\r\n'
        'file contents\r\n--foo--'
    )
    data = Request.from_values(input_stream=StringIO(data),
                               content_length=len(data),
                               content_type='multipart/form-data; boundary=foo',
                               method='POST')
    assert data.files['test'].filename == 'test.txt'
    assert data.files['test'].read() == 'file contents'
开发者ID:marchon,项目名称:checkinmapper,代码行数:13,代码来源:test_formparser.py

示例15: test_extra_newline_multipart

def test_extra_newline_multipart():
    """Test for multipart uploads with extra newlines"""
    # this test looks innocent but it was actually timeing out in
    # the Werkzeug 0.5 release version (#394)
    data = "\r\n\r\n--foo\r\n" 'Content-Disposition: form-data; name="foo"\r\n\r\n' "a string\r\n" "--foo--"
    data = Request.from_values(
        input_stream=StringIO(data),
        content_length=len(data),
        content_type="multipart/form-data; boundary=foo",
        method="POST",
    )
    assert not data.files
    assert data.form["foo"] == "a string"
开发者ID:s0undt3ch,项目名称:werkzeug,代码行数:13,代码来源:test_formparser.py


注:本文中的werkzeug.Request类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。