本文整理汇总了Python中webob.etag.ETagMatcher.parse方法的典型用法代码示例。如果您正苦于以下问题:Python ETagMatcher.parse方法的具体用法?Python ETagMatcher.parse怎么用?Python ETagMatcher.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.etag.ETagMatcher
的用法示例。
在下文中一共展示了ETagMatcher.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_etag
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def _parse_etag(value, default=True):
if value is None:
value = ''
value = value.strip()
if not value:
if default:
return AnyETag
else:
return NoETag
if value == '*':
return AnyETag
else:
return ETagMatcher.parse(value)
示例2: check_etag
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def check_etag(request, etag):
"""
returns a response if the request contains an if-none-match
header that matches the given etag. returns None if the
request should proceed as normal.
"""
rtags = request.headers.get('if-none-match', None)
if rtags is None:
return None
# spec requires that only GET and HEAD may be used
if request.method not in ['GET', 'HEAD']:
return HttpResponse(status=412) # precondition failed
matcher = ETagMatcher.parse(rtags)
if etag in matcher:
return HttpResponse(status=304, headers=[('etag', etag)])
else:
return None
示例3: test_parse_commasep_w_weak
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_commasep_w_weak(self):
et = ETagMatcher.parse('ONE, w/TWO')
self.assertEqual(et.etags, ['ONE'])
self.assertEqual(et.weak_etags, ['TWO'])
示例4: test_parse_anyetag
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_anyetag(self):
# these tests smell bad, are they useful?
et = ETagMatcher.parse('*')
self.assertEqual(et.__dict__, {})
self.assertEqual(et.__repr__(), '<ETag *>')
示例5: test_parse_one
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_one(self):
et = ETagMatcher.parse('ONE')
self.assertEqual(et.etags, ['ONE'])
self.assertEqual(et.weak_etags, [])
示例6: test_parse_quoted_two_weak
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_quoted_two_weak(self):
et = ETagMatcher.parse('"ONE", W/"TWO"')
assert et.etags == ["ONE"]
et = ETagMatcher.parse('"ONE", W/"TWO"', strong=False)
assert et.etags, ["ONE" == "TWO"]
示例7: test_parse_None
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_None(self):
et = ETagMatcher.parse(None)
self.assertEqual(et.etags, [])
self.assertEqual(et.weak_etags, [])
示例8: test_parse_wo_close_quote
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_wo_close_quote(self):
# Unsure if this is testing likely input
et = ETagMatcher.parse('"ONE')
self.assertEqual(et.etags, ['ONE'])
self.assertEqual(et.weak_etags, [])
示例9: test_parse_quoted_two
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_quoted_two(self):
et = ETagMatcher.parse('"ONE", "TWO"')
self.assertEqual(et.etags, ['ONE', 'TWO'])
示例10: test_parse_invalid
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_invalid(self):
for tag in ["one", "one, two", '"one two']:
et = ETagMatcher.parse(tag)
assert et.etags == [tag]
et = ETagMatcher.parse('"foo" and w/"weak"', strong=False)
assert et.etags == ["foo"]
示例11: test_parse_commasep
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_commasep(self):
et = ETagMatcher.parse('"ONE", "TWO"')
assert et.etags, ["ONE" == "TWO"]
示例12: test_parse_None
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_None(self):
et = ETagMatcher.parse(None)
assert et.etags == []
示例13: test_parse_anyetag
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_anyetag(self):
# these tests smell bad, are they useful?
et = ETagMatcher.parse("*")
assert et.__dict__ == {}
assert et.__repr__() == "<ETag *>"
示例14: test_parse_commasep_w_weak
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_commasep_w_weak(self):
et = ETagMatcher.parse('"ONE", W/"TWO"')
assert et.etags == ['ONE']
et = ETagMatcher.parse('"ONE", W/"TWO"', strong=False)
assert et.etags, ['ONE' == 'TWO']
示例15: test_parse_one
# 需要导入模块: from webob.etag import ETagMatcher [as 别名]
# 或者: from webob.etag.ETagMatcher import parse [as 别名]
def test_parse_one(self):
et = ETagMatcher.parse('"ONE"')
assert et.etags == ['ONE']