本文整理汇总了Python中pyslet.py2.ul函数的典型用法代码示例。如果您正苦于以下问题:Python ul函数的具体用法?Python ul怎么用?Python ul使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ul函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_parse_hex_digit
def test_parse_hex_digit(self):
p = unicode5.BasicParser(
u8(b"0123456789abcdefghijklmnopqrstuvwxyz"
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b"\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xa3\xd9\xa4\xd9\xa5"
b"\xd9\xa6\xd9\xa7\xd9\xa8\xd9\xa9"))
result = []
while p.the_char is not None:
digit = p.parse_hex_digit()
if digit is not None:
result.append(digit)
else:
p.next_char()
self.assertTrue(ul('').join(result) ==
ul('0123456789abcdefABCDEF'))
# and now binary
p = unicode5.BasicParser(
b"0123456789abcdefghijklmnopqrstuvwxyz"
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
result = []
while p.the_char is not None:
digit = p.parse_hex_digit()
if digit is not None:
result.append(digit)
else:
p.next_char()
self.assertTrue(join_bytes(result) ==
b'0123456789abcdefABCDEF')
开发者ID:stevehof,项目名称:pyslet,代码行数:28,代码来源:test_unicode5.py
示例2: test_char_prop
def test_char_prop(self):
"""::
charProp ::= IsCategory | IsBlock"""
tests = {
# positive and negative tests
'Nd': (u8(b'123\xdb\xb1\xdb\xb2\xdb\xb3'),
u8(b'ABC\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98')),
'S': (u8(b'+<=>\xe2\x81\x84\xe2\x82\xac'), "(){}"),
'IsBasicLatin': ("ABC", ul("\xc0\xdf\xa9")),
'IsLatin-1Supplement': (ul("\xc0\xdf\xa9"), "ABC"),
'IsCurrencySymbols': (u8(b'\xe2\x82\xa4\xe2\x82\xa9\xe2\x82\xac'),
ul("\x24\xa2\xa3")),
'IsNumberForms': (
u8(b'\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98'),
"1/5 2/5 3/5 4/5")
}
for b in dict_keys(tests):
p = xsi.RegularExpressionParser(b)
cclass = p.require_char_prop()
self.assertTrue(p.the_char is None)
t1, t2 = tests[b]
for c in t1:
self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
for c in t2:
self.assertFalse(cclass.test(c), "%s in %s" % (repr(c), b))
开发者ID:damycra,项目名称:pyslet,代码行数:25,代码来源:test_xml_xsdatatypes.py
示例3: test_is_block
def test_is_block(self):
"""::
IsBlock ::= 'Is' [a-zA-Z0-9#x2D]+"""
tests = {
# positive and negative tests
'BasicLatin': ("ABC", ul("\xc0\xdf\xa9")),
'Latin-1Supplement': (ul("\xc0\xdf\xa9"), "ABC"),
'CurrencySymbols': (u8(b'\xe2\x82\xa4\xe2\x82\xa9\xe2\x82\xac'),
ul("\x24\xa2\xa3")),
'NumberForms': (
u8(b'\xe2\x85\x95\xe2\x85\x96\xe2\x85\x97\xe2\x85\x98'),
"1/5 2/5 3/5 4/5")
}
for b in dict_keys(tests):
p = xsi.RegularExpressionParser("Is" + b)
cclass = p.require_is_block()
self.assertTrue(p.the_char is None)
t1, t2 = tests[b]
for c in t1:
self.assertTrue(cclass.test(c), "%s not in %s" % (repr(c), b))
for c in t2:
self.assertFalse(cclass.test(c), "%s in Is%s" % (repr(c), b))
p = xsi.RegularExpressionParser("IsNumberFoams")
try:
cclass = p.require_is_block()
self.fail("IsNumberFoams")
except xsi.RegularExpressionError:
pass
开发者ID:damycra,项目名称:pyslet,代码行数:28,代码来源:test_xml_xsdatatypes.py
示例4: test_parseurn
def test_parseurn(self):
"""An URN ends when an octet/character from the excluded
character set (<excluded>) is encountered."""
tests = [
'urn:foo:bar\x00wrong',
'urn:foo:bar wrong',
'urn:foo:bar\\wrong',
'urn:foo:bar"wrong',
'urn:foo:bar&wrong',
'urn:foo:bar<wrong',
'urn:foo:bar>wrong',
'urn:foo:bar[wrong',
'urn:foo:bar]wrong',
'urn:foo:bar^wrong',
'urn:foo:bar`wrong',
'urn:foo:bar{wrong',
'urn:foo:bar|wrong',
'urn:foo:bar}wrong',
'urn:foo:bar~wrong',
ul('urn:foo:bar\x7fwrong'),
ul(b'urn:foo:bar\x9fwrong'),
ul(b'urn:foo:bar\xff')]
for src in tests:
dst = urn.parse_urn(src)
self.assertTrue(dst == 'urn:foo:bar', "parse_urn(%s) == %s" %
(repr(src), repr(dst)))
开发者ID:damycra,项目名称:pyslet,代码行数:26,代码来源:test_urn.py
示例5: run_constructor
def run_constructor(self):
path = self.fs()
self.assertTrue(isinstance(path, vfs.VirtualFilePath),
"VirtualFilePath abstract class")
self.assertTrue(path.is_empty(), "Empty path creation")
self.assertTrue(path.is_single_component(),
"Empty path is a single component")
self.assertFalse(path.is_dirlike(), "Empty path is not diretory like")
self.assertFalse(path.is_root(), "Empty path is not the root")
self.assertFalse(path, "Non-zero test of empty path")
path = self.fs('hello')
self.assertFalse(path.is_empty(), "Single path component")
self.assertTrue(path.is_single_component(),
"path is a single component")
self.assertFalse(path.is_dirlike(), "path is not diretory like")
self.assertFalse(path.is_root(), "path is not the root")
self.assertTrue(path.to_bytes() == b"hello", "convert to binary str")
self.assertTrue(to_text(path) == ul("hello"), "convert to text")
self.assertTrue(path, "Non-zero test of non-empty path")
# create a path from a path
path = self.fs(path)
self.assertTrue(to_text(path) == ul("hello"), "check path")
# create a path from a string and instance mix
hello_world = ul("hello") + to_text(self.fs.sep) + ul("world")
path = self.fs(path, 'world')
self.assertTrue(to_text(path) == hello_world)
# create a path from a string ending with the separator
path = self.fs(ul('hello') + to_text(self.fs.sep), 'world')
self.assertTrue(to_text(path) == hello_world)
self.assertTrue(str(path) == str(hello_world))
path = self.fs(ul('Caf\xe9'))
self.assertTrue(path.to_bytes() == ul('Caf\xe9').encode(path.codec),
"convert to binary string")
self.assertTrue(to_text(path) == ul('Caf\xe9'), "convert to text")
# create a path with a trailing sep
hello = self.fs.path_str('hello') + self.fs.sep
path = self.fs(hello)
self.assertFalse(path.is_empty(), "Trailing slash non empty")
self.assertFalse(path.is_single_component(),
"trailing slash is a single component")
self.assertTrue(path.is_dirlike(), "trailing slash diretory like")
self.assertFalse(path.is_root(), "trailing slash not the root")
self.assertTrue(to_text(path) == ul(hello), "convert to text")
# create a path with a trailing sep and current dir indicator
hello = self.fs.path_str('hello') + self.fs.sep + self.fs.curdir
path = self.fs(hello)
self.assertFalse(path.is_empty(), "Trailing dot-slash non empty")
self.assertFalse(path.is_single_component(),
"trailing dot-slash is a single component")
self.assertTrue(path.is_dirlike(), "trailing dot-slash diretory like")
self.assertFalse(path.is_root(), "trailing dot-slash not the root")
self.assertTrue(to_text(path) == ul(hello), "convert to text")
# bad argument types raise TypeError
try:
path = self.fs(45)
self.fail("constructor requires string argument")
except TypeError:
pass
开发者ID:swl10,项目名称:pyslet,代码行数:58,代码来源:test_vfs.py
示例6: test_match_one
def test_match_one(self):
p = unicode5.BasicParser(ul("hello"))
self.assertTrue(p.match_one(ul("hello")))
self.assertTrue(p.match_one(ul("h")))
self.assertFalse(p.match_one(ul("e")))
p = unicode5.BasicParser(b"hello")
self.assertTrue(p.match_one(b"hello"))
self.assertTrue(p.match_one(b"h"))
self.assertFalse(p.match_one(b"e"))
开发者ID:stevehof,项目名称:pyslet,代码行数:9,代码来源:test_unicode5.py
示例7: test_literals
def test_literals(self):
container = MockContainer(container=self.container,
dbapi=MockAPI(0), max_connections=5)
# format each type of literal
v = edm.SimpleValue.from_type(edm.SimpleType.Binary)
v.set_from_value(b'1234')
self.assertTrue(container.prepare_sql_literal(v) == "X'31323334'")
v = edm.SimpleValue.from_type(edm.SimpleType.Boolean)
v.set_from_value(True)
self.assertTrue(container.prepare_sql_literal(v) == "TRUE")
v = edm.SimpleValue.from_type(edm.SimpleType.Byte)
v.set_from_value(3)
self.assertTrue(container.prepare_sql_literal(v) == "3")
v = edm.SimpleValue.from_type(edm.SimpleType.DateTime)
v.set_from_value(iso.TimePoint.from_str('1972-03-03T09:45:00.000'))
# discard fractional seconds
self.assertTrue(container.prepare_sql_literal(v) ==
"'1972-03-03T09:45:00'")
v = edm.SimpleValue.from_type(edm.SimpleType.DateTimeOffset)
v.set_from_value(iso.TimePoint.from_str('1972-03-03T09:45:00.000Z'))
# discard fractional seconds
self.assertTrue(container.prepare_sql_literal(v) ==
"'1972-03-03T09:45:00Z'")
v = edm.SimpleValue.from_type(edm.SimpleType.Time)
v.set_from_value(iso.Time.from_str('09:45:00.000'))
# discard fractional seconds
self.assertTrue(container.prepare_sql_literal(v) ==
"'09:45:00'")
v = edm.SimpleValue.from_type(edm.SimpleType.Decimal)
v.set_from_value(decimal.Decimal('3.14'))
self.assertTrue(container.prepare_sql_literal(v) == "3.14")
v = edm.SimpleValue.from_type(edm.SimpleType.Double)
v.set_from_value(3.14)
self.assertTrue(container.prepare_sql_literal(v) == "3.14")
v = edm.SimpleValue.from_type(edm.SimpleType.Single)
v.set_from_value(3.14)
self.assertTrue(container.prepare_sql_literal(v) == "3.14")
v = edm.SimpleValue.from_type(edm.SimpleType.Guid)
v.set_from_value(uuid.UUID(int=3))
self.assertTrue(container.prepare_sql_literal(v) ==
"X'00000000000000000000000000000003'")
v = edm.SimpleValue.from_type(edm.SimpleType.Int16)
v.set_from_value(3)
self.assertTrue(container.prepare_sql_literal(v) == "3")
v = edm.SimpleValue.from_type(edm.SimpleType.Int32)
v.set_from_value(3)
self.assertTrue(container.prepare_sql_literal(v) == "3")
v = edm.SimpleValue.from_type(edm.SimpleType.Int64)
v.set_from_value(3)
self.assertTrue(container.prepare_sql_literal(v) == "3")
v = edm.SimpleValue.from_type(edm.SimpleType.String)
v.set_from_value(ul("Dave's Caf\xe9"))
self.assertTrue(container.prepare_sql_literal(v) ==
ul("'Dave''s Caf\xe9'"))
v = edm.SimpleValue.from_type(edm.SimpleType.SByte)
v.set_from_value(-3)
self.assertTrue(container.prepare_sql_literal(v) == "-3")
开发者ID:swl10,项目名称:pyslet,代码行数:57,代码来源:test_odata2_sqlds.py
示例8: test_constructor
def test_constructor(self):
e = structures.XMLEntity(b"<hello>")
self.assertTrue(e.line_num == 1)
self.assertTrue(e.line_pos == 1)
self.assertTrue(is_unicode(e.the_char) and e.the_char == '<')
e = structures.XMLEntity(ul("<hello>"))
self.assertTrue(is_unicode(e.the_char) and e.the_char == '<')
e = structures.XMLEntity(StringIO(ul("<hello>")))
self.assertTrue(e.line_num == 1)
self.assertTrue(e.line_pos == 1)
self.assertTrue(is_unicode(e.the_char) and e.the_char == '<')
开发者ID:rcplay,项目名称:pyslet,代码行数:11,代码来源:test_xml_structures.py
示例9: test_branch
def test_branch(self):
"""::
branch ::= piece* """
p = xsi.RegularExpressionParser(
ul("A[A-z-[\[-\]]](Hello(Mum)|(Dad))A{0,0}[A-Z]{0,1}(Hello)"
"{0,}B{1,}[@-\xA9]?)"))
self.assertTrue(
p.require_branch() ==
ul("A[A-Z_-z^](Hello(Mum)|(Dad))[A-Z]?(Hello)*B+[@-\xA9]?"),
"Branch")
self.assertTrue(p.the_char == ")")
开发者ID:damycra,项目名称:pyslet,代码行数:11,代码来源:test_xml_xsdatatypes.py
示例10: test_match_insensitive
def test_match_insensitive(self):
p = unicode5.BasicParser(ul("heLLo"))
p.next_char()
save_pos = p.pos
self.assertTrue(p.match_insensitive(ul("ell")))
self.assertTrue(p.pos == save_pos)
self.assertFalse(p.match_insensitive(ul("hell")))
self.assertTrue(p.pos == save_pos)
p = unicode5.BasicParser(b"heLLo")
p.next_char()
self.assertTrue(p.match_insensitive(b"ell"))
self.assertFalse(p.match_insensitive(b"hell"))
开发者ID:stevehof,项目名称:pyslet,代码行数:12,代码来源:test_unicode5.py
示例11: test_parse_integer
def test_parse_integer(self):
p = unicode5.BasicParser(ul("23p"))
# all defaults, unbounded
self.assertTrue(p.parse_integer() == 23)
self.assertTrue(p.pos == 2)
p.setpos(1)
# provide a minimum value
self.assertTrue(p.parse_integer(4) is None)
self.assertTrue(p.parse_integer(2) == 3)
p.setpos(1)
# provide a minimum and maximum value
self.assertTrue(p.parse_integer(0, 2) is None)
self.assertTrue(p.parse_integer(1, 4) == 3)
p.setpos(0)
# min value < 0, should throw an error
try:
p.parse_integer(-1)
self.fail("min = -1 didn't raise exception")
except ValueError:
# and it shouldn't move the parser
self.assertTrue(p.pos == 0)
# min value > max, should throw an error
try:
p.parse_integer(3, 1)
self.fail("min > max didn't raise exception")
except ValueError:
# and it shouldn't move the parser
self.assertTrue(p.pos == 0)
# check we can exceed ordinary integer sizes
istr = ul("123456789" + "0" * 256)
p = unicode5.BasicParser(istr)
# test max digits
self.assertTrue(p.parse_integer(0, None, 10) == 1234567890)
# check wide zeros
self.assertTrue(p.parse_integer(0, None, 10) == 0)
self.assertTrue(p.pos == 20)
p.setpos(0)
# check large numbers
self.assertTrue(p.parse_integer(0, None, 15) == 123456789000000)
# test Arabic digits, should not parse!
p = unicode5.BasicParser(
u8(b'\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xa3\xd9\xa4\xd9\xa5'
b'\xd9\xa6\xd9\xa7\xd9\xa8\xd9\xa9'))
for i in range3(10):
self.assertTrue(p.parse_integer() is None)
p.next_char()
# test binary forms
p = unicode5.BasicParser(b"234p")
self.assertTrue(p.parse_integer(max_digits=1) == 2)
self.assertTrue(p.parse_integer(0, 2) is None)
self.assertTrue(p.parse_integer() == 34)
p.next_char()
self.assertTrue(p.parse_integer() is None)
开发者ID:stevehof,项目名称:pyslet,代码行数:53,代码来源:test_unicode5.py
示例12: test_length
def test_length(self):
es = self.schema['SampleEntities.Employees']
self.assertTrue(isinstance(es, edm.EntitySet))
with es.open() as collection:
self.assertTrue(len(collection) == 0, "Length on load")
self.employees.data["ABCDE"] = (
ul("ABCDE"), ul("John Smith"), None, None)
self.assertTrue(len(collection) == 1, "Length after insert")
self.employees.data["FGHIJ"] = (
ul("FGHIJ"), ul("Jane Smith"), None, None)
self.assertTrue(len(collection) == 2, "Length after 2xinsert")
del collection["ABCDE"]
self.assertTrue(len(collection) == 1, "Length after delete")
开发者ID:damycra,项目名称:pyslet,代码行数:13,代码来源:test_odata2_memds.py
示例13: test_getcwd
def test_getcwd(self):
wd = self.fs.getcwd()
self.assertTrue(isinstance(wd, self.fs))
self.assertTrue(isinstance(wd, vfs.VirtualFilePath))
self.assertTrue(to_text(wd) == ul('C:\\home'))
# the current drive letter is used to make a path absolute
path = self.fs(ul('\\home'))
self.assertTrue(path.isabs(), "Missing path letter still absolute")
apath = path.abspath()
self.assertTrue(apath != path, "Path should change for abspath")
self.assertTrue(apath.splitdrive()[0] == ul('C:'))
# check that the drive is not absolute
self.assertFalse(apath.splitdrive()[0].isabs())
开发者ID:swl10,项目名称:pyslet,代码行数:13,代码来源:test_vfs.py
示例14: test_canonicalize_data
def test_canonicalize_data(self):
try:
uri.canonicalize_data(ul('Caf\xe9'))
self.fail("non-ASCII character for canonicalisation")
except UnicodeEncodeError:
pass
self.assertTrue(uri.canonicalize_data(
"%2D%5F%2e%21%7e%2A%27%28%29%41%5a%61%7A%30%39") ==
"-_.!~*'()AZaz09", "unreserved characters are unescaped")
self.assertTrue(
uri.canonicalize_data('"<[one #word\x09or two\r\n]>"',
allowed_test=uri.is_allowed_2396) ==
'%22%3C%5Bone%20%23word%09or%20two%0D%0A%5D%3E%22',
"escape chars neither unreserved nor reserved (rfc2396)")
self.assertTrue(
uri.canonicalize_data('"<[one #word\x09or two\r\n]>"') ==
'%22%3C[one%20%23word%09or%20two%0D%0A]%3E%22',
"escape chars neither unreserved nor reserved")
# passing is_alphanum effectively causes 'marks' to stay as-is
self.assertTrue(uri.canonicalize_data(
"%2D%5F%2e%21%7e%2A%27%28%29%41%5a%61%7A%30%39",
uri.is_alphanum) == "%2D%5F%2E%21%7E%2A%27%28%29AZaz09",
"(only) unreserved characters are unescaped")
# passing lambda: x:False effectively causes everything to stay as-is
self.assertTrue(uri.canonicalize_data(
"%2D%5F%2e%21%7e%2A%27%28%29%41%5a%61%7A%30%39",
lambda x: False) ==
"%2D%5F%2E%21%7E%2A%27%28%29%41%5A%61%7A%30%39",
"no characters are unescaped")
开发者ID:swl10,项目名称:pyslet,代码行数:29,代码来源:test_rfc2396.py
示例15: test_getcroot
def test_getcroot(self):
wd = self.fs.getcroot()
self.assertTrue(isinstance(wd, self.fs))
self.assertTrue(isinstance(wd, vfs.VirtualFilePath))
self.assertTrue(to_text(wd) == ul('/'))
self.assertTrue(wd.to_bytes() == b'/')
self.assertTrue(isinstance(wd.to_bytes(), bytes))
开发者ID:swl10,项目名称:pyslet,代码行数:7,代码来源:test_vfs.py
示例16: test_open_w_r
def test_open_w_r(self):
ss = blockstore.StreamStore(bs=self.bs, ls=self.ls,
entity_set=self.cdef['Streams'])
s1 = ss.new_stream("text/plain")
self.assertTrue(s1['md5'].value == hashlib.md5().digest())
with ss.open_stream(s1, 'w') as s:
self.assertFalse(s.closed)
self.assertFalse(s.readable())
self.assertTrue(s.writable())
self.assertTrue(s.tell() == 0)
# try writing a multi-block string
nbytes = 0
fox = b"The quick brown fox jumped over the lazy dog"
cafe = ul("Caf\xe9").encode('utf-8')
data = fox + cafe + fox
while nbytes < len(data):
nbytes += s.write(data[nbytes:])
self.assertTrue(s.tell() == nbytes)
self.assertTrue(s1['size'].value == nbytes)
self.assertTrue(s1['md5'].value == hashlib.md5(data).digest())
with self.cdef['BlockLists'].open() as blocks:
# data should spill over to 2 blocks
self.assertTrue(len(blocks) == 2)
with ss.open_stream(s1, 'r') as s:
self.assertFalse(s.closed)
self.assertTrue(s.readable())
self.assertFalse(s.writable())
self.assertTrue(s.tell() == 0)
rdata = s.read()
self.assertTrue(rdata == data, "Read back %s" % repr(rdata))
self.assertTrue(s.tell() == nbytes)
开发者ID:damycra,项目名称:pyslet,代码行数:31,代码来源:test_blockstore.py
示例17: test_entity_tag
def test_entity_tag(self):
try:
etag = EntityTag()
self.fail("Required tag in constructor")
except TypeError:
pass
etag = EntityTag("hello")
self.assertTrue(etag.weak, "ETag constructor makes weak tags")
etag = EntityTag("hello", False)
self.assertFalse(etag.weak, "ETag constructor with strong tag")
self.assertTrue(etag.tag, "ETag constructor tag not None")
etag = EntityTag.from_str('W/"hello"')
self.assertTrue(etag.weak, "Failed to parse weak tag")
self.assertTrue(etag.tag == b"hello", "Failed to parse ETag value")
etag = EntityTag.from_str('w/ "h\\"ello"')
self.assertTrue(
etag.weak, "Failed to parse weak tag with lower case 'w'")
self.assertTrue(
etag.tag == b'h"ello',
"Failed to unpick quoted pair from ETag value; found %s" %
repr(etag.tag))
etag = EntityTag.from_str('"hello"')
self.assertFalse(etag.weak, "Failed to parse strong tag")
self.assertTrue(etag.tag == b"hello", "Failed to parse ETag value")
etag = EntityTag.from_str(ul('"hello"'))
self.assertFalse(etag.weak, "Failed to parse strong tag")
self.assertTrue(etag.tag == b"hello", "Failed to parse ETag value")
开发者ID:damycra,项目名称:pyslet,代码行数:27,代码来源:test_http_params.py
示例18: test_boundary_delimiter
def test_boundary_delimiter(self):
# boundary_delimiter is read from the MediaType
ct = MediaType.from_str(
"multipart/mixed; boundary=gc0p4Jq0M2Yt08j34c0p")
boundary = multipart.get_boundary_delimiter(ct)
self.assertTrue(boundary == "\r\n--gc0p4Jq0M2Yt08j34c0p")
ct = MediaType.from_str(
'multipart/mixed; boundary="gc0pJq0M:08jU534c0p"')
boundary = multipart.get_boundary_delimiter(ct)
self.assertTrue(boundary == "\r\n--gc0pJq0M:08jU534c0p")
# boundary delimiters and headers are always 7bit US-ASCII
# (non-US-ASCII encoding deprecated)
ct = MediaType.from_str(
ul('multipart/mixed; boundary="gc0pJq0M\xa608jU534c0p"'))
try:
boundary = multipart.get_boundary_delimiter(ct)
self.fail("8-bit boundary")
except multipart.MultipartError:
pass
# must be no longer than 70 characters, not counting the two
# leading hyphens
ct = MediaType.from_str(
"multipart/mixed; boundary=abcdefghijklmnopqrstuvwxyz1234567890"
"abcdefghijklmnopqrstuvwxyz12345678")
self.assertTrue(len(multipart.get_boundary_delimiter(ct)) == 74)
ct = MediaType.from_str(
"multipart/mixed; boundary=abcdefghijklmnopqrstuvwxyz1234567890"
"abcdefghijklmnopqrstuvwxyz123456789")
try:
multipart.get_boundary_delimiter(ct)
self.fail("long boundary")
except multipart.MultipartError:
pass
开发者ID:swl10,项目名称:pyslet,代码行数:33,代码来源:test_http_multipart.py
示例19: test_nonces
def test_nonces(self):
with self.silo['Consumers'].open() as collection:
consumer = lti.ToolConsumer.new_from_values(
collection.new_entity(), self.cipher, 'default', key="12345",
secret=ul("secret"))
collection.insert_entity(consumer.entity)
provider = lti.ToolProvider(
self.container['Consumers'], self.container['Nonces'],
self.cipher)
consumer = provider.lookup_consumer('12345')
self.assertTrue(provider.validate_timestamp_and_nonce(
consumer.key, 0, '9e4a4b085c8c46d6aae6b5d9c8a15418', None))
# the same nonce should now evaluate to True
self.assertFalse(provider.validate_timestamp_and_nonce(
consumer.key, 0, '9e4a4b085c8c46d6aae6b5d9c8a15418', None))
# but a different one is False
self.assertTrue(provider.validate_timestamp_and_nonce(
consumer.key, 0, '8f274dca508711c2e70a67ab68fcc1f2', None))
# now at 89:59 we are still not allowed to reuse the nonce
self.mock_time.tick(89*60+59.0)
self.assertFalse(provider.validate_timestamp_and_nonce(
consumer.key, 0, '9e4a4b085c8c46d6aae6b5d9c8a15418', None))
# but if we tick over 90 mins we're good to go again
self.mock_time.tick(1.001)
self.assertTrue(provider.validate_timestamp_and_nonce(
consumer.key, 0, '9e4a4b085c8c46d6aae6b5d9c8a15418', None))
开发者ID:swl10,项目名称:pyslet,代码行数:26,代码来源:test_imsbltiv1p0.py
示例20: test_output
def test_output(self):
txt_out = io.StringIO()
save_stdout = sys.stdout
try:
sys.stdout = txt_out
py2.output(py2.ul("Going to the\nCaf\xe9"))
finally:
sys.stdout = save_stdout
self.assertTrue(txt_out.getvalue() == py2.ul("Going to the\nCaf\xe9"))
bin_out = io.BytesIO()
try:
sys.stdout = bin_out
py2.output(py2.ul("Going to the\nCaf\xe9"))
finally:
sys.stdout = save_stdout
self.assertTrue(bin_out.getvalue() == b"Going to the\nCaf\xc3\xa9")
开发者ID:swl10,项目名称:pyslet,代码行数:16,代码来源:test_py2.py
注:本文中的pyslet.py2.ul函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论