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


Python Request.environ['CONTENT_LENGTH']方法代码示例

本文整理汇总了Python中webob.Request.environ['CONTENT_LENGTH']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.environ['CONTENT_LENGTH']方法的具体用法?Python Request.environ['CONTENT_LENGTH']怎么用?Python Request.environ['CONTENT_LENGTH']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webob.Request的用法示例。


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

示例1: test_request_post_valid

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import environ['CONTENT_LENGTH'] [as 别名]
    def test_request_post_valid(self):
        environ = {'wsgi.input': StringIO('')}
        req=Request(environ)
        req.method = 'POST'
        req.body='dblistform_d:0:name=a&dblistform_d:0:id=1'
        req.environ['CONTENT_LENGTH'] = str(len(req.body))
        req.environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'

        self.mw.config.debug = True
        r = self.widget().request(req)
        assert r.body == """Form posted successfully [{'id': 1, 'name': u'a'}]""", r.body
开发者ID:LeResKP,项目名称:tw2.sqla,代码行数:13,代码来源:test_widgets.py

示例2: test_request_post_redirect

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import environ['CONTENT_LENGTH'] [as 别名]
    def test_request_post_redirect(self):
        environ = {'wsgi.input': StringIO('')}
        req=Request(environ)
        req.method = 'POST'
        req.body='dbformpage_d:name=a'
        req.environ['CONTENT_LENGTH'] = str(len(req.body))
        req.environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'

        self.mw.config.debug = True
        r = self.widget(redirect="/foo").request(req)
        assert( r.status_int == 302 and r.location=="/foo" )
开发者ID:LeResKP,项目名称:tw2.sqla,代码行数:13,代码来源:test_widgets.py

示例3: test_request_post_counts_update

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import environ['CONTENT_LENGTH'] [as 别名]
    def test_request_post_counts_update(self):
        environ = {'wsgi.input': StringIO('')}
        req=Request(environ)
        req.method = 'POST'
        req.body='dblistform_d:0:name=a&dblistform_d:0:id=1&dblistform_d:1:name=b&dblistform_d:1:id=2'
        req.environ['CONTENT_LENGTH'] = str(len(req.body))
        req.environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'

        self.mw.config.debug = True
        assert(self.DbTestCls1.query.count() == 2)
        r = self.widget().request(req)
        assert(self.DbTestCls1.query.count() == 2)
开发者ID:LeResKP,项目名称:tw2.sqla,代码行数:14,代码来源:test_widgets.py

示例4: test_request_post_valid

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import environ['CONTENT_LENGTH'] [as 别名]
    def test_request_post_valid(self):
        environ = {'wsgi.input': StringIO(''),
                   }
        req=Request(environ)
        req.method = 'POST'
        req.body='mytestwidget:field1=a&mytestwidget:field2=b&mytestwidget:field3=c'
        req.environ['CONTENT_LENGTH'] = str(len(req.body))
        req.environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'

        self.mw.config.debug = True
        r = self.widget().request(req)
        assert (
            r.body == """Form posted successfully {'field2': 'b', 'field3': 'c', 'field1': 'a'}""" or
            r.body == """Form posted successfully {'field2': u'b', 'field3': u'c', 'field1': u'a'}"""
            ), r.body
开发者ID:knzm,项目名称:tw2.forms,代码行数:17,代码来源:test_widgets.py

示例5: test_request_post_valid

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import environ['CONTENT_LENGTH'] [as 别名]
    def test_request_post_valid(self):
        environ = {'wsgi.input': StringIO('')}
        req = Request(environ)
        req.method = 'POST'
        attr = six.PY3 and "text" or "body"
        setattr(req, attr, ('mytestwidget:field1=a&mytestwidget'
            ':field2=b&mytestwidget:field3=c'))
        req.environ['CONTENT_LENGTH'] = str(len(req.body))
        req.environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'

        self.mw.config.debug = True
        r = self.widget().request(req)
        target = six.b(
            "Form posted successfully {'field2': 'b', 'field3': 'c', 'field1': 'a'}"
        )
        assert(target in r.body, r.body)
开发者ID:LeResKP,项目名称:tw2.forms,代码行数:18,代码来源:test_widgets.py

示例6: _test_request_post_content_update

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import environ['CONTENT_LENGTH'] [as 别名]
    def _test_request_post_content_update(self):
        environ = {'wsgi.input': StringIO('')}
        req=Request(environ)
        req.method = 'POST'
        req.body='dblistform_d:0:name=b&dblistform_d:0:id=1'
        req.environ['CONTENT_LENGTH'] = str(len(req.body))
        req.environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'

        self.mw.config.debug = True
        original = self.DbTestCls1.query.filter(self.DbTestCls1.id==1).one()
        assert(original.name == 'foo1')
        r = self.widget().request(req)
        updated = self.DbTestCls1.query.filter(self.DbTestCls1.id=='1')
        assert(updated.count() == 1)
        updated = updated.one()
        assert(updated.name == 'b')
开发者ID:LeResKP,项目名称:tw2.sqla,代码行数:18,代码来源:test_widgets.py

示例7: test_no_query_property

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import environ['CONTENT_LENGTH'] [as 别名]
    def test_no_query_property(self):
        old_prop = self.widget.entity.query
        self.widget.entity.query = None

        environ = {'wsgi.input': StringIO('')}
        req=Request(environ)
        req.method = 'POST'
        req.body='dbformpage_d:name=a'
        req.environ['CONTENT_LENGTH'] = str(len(req.body))
        req.environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'

        self.mw.config.debug = True
        try:
            r = self.widget().request(req)
            assert False
        except AttributeError, e:
            print e
            assert(str(e) == 'entity has no query_property()')
开发者ID:LeResKP,项目名称:tw2.sqla,代码行数:20,代码来源:test_widgets.py

示例8: str

# 需要导入模块: from webob import Request [as 别名]
# 或者: from webob.Request import environ['CONTENT_LENGTH'] [as 别名]
req.POST.items()
req.method = 'POST'
req.body = 'name=Joe&[email protected]'
req.POST
req.POST['name']

req.params
req.params['name']
req.params.getall('name')
for name, value in req.params.items():
    print '%s: %r' % (name, value)

req = Request.blank('/test?check=a&check=b&name=Bob')
req.method = 'PUT'
req.body = body = 'var1=value1&var2=value2&rep=1&rep=2'
req.environ['CONTENT_LENGTH'] = str(len(req.body))
req.environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
req.GET
# Why post have items???
req.POST

req.charset = 'utf8'

req = Request.blank('/')
def wsgi_app(environ, start_response):
    start_response('200 OK', [('Content-type', 'text/plain')])
    return ['Hi!']
req.call_application(wsgi_app)
res = req.get_response(wsgi_app)

# add user defined attribute
开发者ID:youzhibicheng,项目名称:ThinkingPython,代码行数:33,代码来源:webob_tutorial.py


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