本文整理汇总了Python中pyslet.py2.ul函数的典型用法代码示例。如果您正苦于以下问题:Python ul函数的具体用法?Python ul怎么用?Python ul使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ul函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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')
示例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))
示例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
示例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)))
示例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
示例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"))
示例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")
示例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 == '<')
示例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 == ")")
示例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"))
示例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)
示例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")
示例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())
示例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")
示例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))