Use raw-mode docstring whenever there's an escape code in an example --
they're easier to read this way.
This commit is contained in:
parent
03e35327f2
commit
55762f5f80
|
@ -185,9 +185,9 @@ class ArgumentDescriptor(object):
|
||||||
from struct import unpack as _unpack
|
from struct import unpack as _unpack
|
||||||
|
|
||||||
def read_uint1(f):
|
def read_uint1(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> read_uint1(StringIO.StringIO('\\xff'))
|
>>> read_uint1(StringIO.StringIO('\xff'))
|
||||||
255
|
255
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -204,11 +204,11 @@ uint1 = ArgumentDescriptor(
|
||||||
|
|
||||||
|
|
||||||
def read_uint2(f):
|
def read_uint2(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> read_uint2(StringIO.StringIO('\\xff\\x00'))
|
>>> read_uint2(StringIO.StringIO('\xff\x00'))
|
||||||
255
|
255
|
||||||
>>> read_uint2(StringIO.StringIO('\\xff\\xff'))
|
>>> read_uint2(StringIO.StringIO('\xff\xff'))
|
||||||
65535
|
65535
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -225,11 +225,11 @@ uint2 = ArgumentDescriptor(
|
||||||
|
|
||||||
|
|
||||||
def read_int4(f):
|
def read_int4(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> read_int4(StringIO.StringIO('\\xff\\x00\\x00\\x00'))
|
>>> read_int4(StringIO.StringIO('\xff\x00\x00\x00'))
|
||||||
255
|
255
|
||||||
>>> read_int4(StringIO.StringIO('\\x00\\x00\\x00\\x80')) == -(2**31)
|
>>> read_int4(StringIO.StringIO('\x00\x00\x00\x80')) == -(2**31)
|
||||||
True
|
True
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -246,20 +246,20 @@ int4 = ArgumentDescriptor(
|
||||||
|
|
||||||
|
|
||||||
def read_stringnl(f, decode=True, stripquotes=True):
|
def read_stringnl(f, decode=True, stripquotes=True):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> read_stringnl(StringIO.StringIO("'abcd'\\nefg\\n"))
|
>>> read_stringnl(StringIO.StringIO("'abcd'\nefg\n"))
|
||||||
'abcd'
|
'abcd'
|
||||||
|
|
||||||
>>> read_stringnl(StringIO.StringIO("\\n"))
|
>>> read_stringnl(StringIO.StringIO("\n"))
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
ValueError: no string quotes around ''
|
ValueError: no string quotes around ''
|
||||||
|
|
||||||
>>> read_stringnl(StringIO.StringIO("\\n"), stripquotes=False)
|
>>> read_stringnl(StringIO.StringIO("\n"), stripquotes=False)
|
||||||
''
|
''
|
||||||
|
|
||||||
>>> read_stringnl(StringIO.StringIO("''\\n"))
|
>>> read_stringnl(StringIO.StringIO("''\n"))
|
||||||
''
|
''
|
||||||
|
|
||||||
>>> read_stringnl(StringIO.StringIO('"abcd"'))
|
>>> read_stringnl(StringIO.StringIO('"abcd"'))
|
||||||
|
@ -268,8 +268,8 @@ def read_stringnl(f, decode=True, stripquotes=True):
|
||||||
ValueError: no newline found when trying to read stringnl
|
ValueError: no newline found when trying to read stringnl
|
||||||
|
|
||||||
Embedded escapes are undone in the result.
|
Embedded escapes are undone in the result.
|
||||||
>>> read_stringnl(StringIO.StringIO("'a\\\\nb\\x00c\\td'\\n'e'"))
|
>>> read_stringnl(StringIO.StringIO(r"'a\n\\b\x00c\td'" + "\n'e'"))
|
||||||
'a\\nb\\x00c\\td'
|
'a\n\\b\x00c\td'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = f.readline()
|
data = f.readline()
|
||||||
|
@ -319,9 +319,9 @@ stringnl_noescape = ArgumentDescriptor(
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def read_stringnl_noescape_pair(f):
|
def read_stringnl_noescape_pair(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> read_stringnl_noescape_pair(StringIO.StringIO("Queue\\nEmpty\\njunk"))
|
>>> read_stringnl_noescape_pair(StringIO.StringIO("Queue\nEmpty\njunk"))
|
||||||
'Queue Empty'
|
'Queue Empty'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -341,13 +341,13 @@ stringnl_noescape_pair = ArgumentDescriptor(
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def read_string4(f):
|
def read_string4(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> read_string4(StringIO.StringIO("\\x00\\x00\\x00\\x00abc"))
|
>>> read_string4(StringIO.StringIO("\x00\x00\x00\x00abc"))
|
||||||
''
|
''
|
||||||
>>> read_string4(StringIO.StringIO("\\x03\\x00\\x00\\x00abcdef"))
|
>>> read_string4(StringIO.StringIO("\x03\x00\x00\x00abcdef"))
|
||||||
'abc'
|
'abc'
|
||||||
>>> read_string4(StringIO.StringIO("\\x00\\x00\\x00\\x03abcdef"))
|
>>> read_string4(StringIO.StringIO("\x00\x00\x00\x03abcdef"))
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
ValueError: expected 50331648 bytes in a string4, but only 6 remain
|
ValueError: expected 50331648 bytes in a string4, but only 6 remain
|
||||||
|
@ -375,11 +375,11 @@ string4 = ArgumentDescriptor(
|
||||||
|
|
||||||
|
|
||||||
def read_string1(f):
|
def read_string1(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> read_string1(StringIO.StringIO("\\x00"))
|
>>> read_string1(StringIO.StringIO("\x00"))
|
||||||
''
|
''
|
||||||
>>> read_string1(StringIO.StringIO("\\x03abcdef"))
|
>>> read_string1(StringIO.StringIO("\x03abcdef"))
|
||||||
'abc'
|
'abc'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -404,10 +404,10 @@ string1 = ArgumentDescriptor(
|
||||||
|
|
||||||
|
|
||||||
def read_unicodestringnl(f):
|
def read_unicodestringnl(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> read_unicodestringnl(StringIO.StringIO("abc\\uabcd\\njunk"))
|
>>> read_unicodestringnl(StringIO.StringIO("abc\uabcd\njunk"))
|
||||||
u'abc\\uabcd'
|
u'abc\uabcd'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = f.readline()
|
data = f.readline()
|
||||||
|
@ -429,12 +429,12 @@ unicodestringnl = ArgumentDescriptor(
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def read_unicodestring4(f):
|
def read_unicodestring4(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> s = u'abcd\\uabcd'
|
>>> s = u'abcd\uabcd'
|
||||||
>>> enc = s.encode('utf-8')
|
>>> enc = s.encode('utf-8')
|
||||||
>>> enc
|
>>> enc
|
||||||
'abcd\\xea\\xaf\\x8d'
|
'abcd\xea\xaf\x8d'
|
||||||
>>> n = chr(len(enc)) + chr(0) * 3 # little-endian 4-byte length
|
>>> n = chr(len(enc)) + chr(0) * 3 # little-endian 4-byte length
|
||||||
>>> t = read_unicodestring4(StringIO.StringIO(n + enc + 'junk'))
|
>>> t = read_unicodestring4(StringIO.StringIO(n + enc + 'junk'))
|
||||||
>>> s == t
|
>>> s == t
|
||||||
|
@ -469,12 +469,12 @@ unicodestring4 = ArgumentDescriptor(
|
||||||
|
|
||||||
|
|
||||||
def read_decimalnl_short(f):
|
def read_decimalnl_short(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> read_decimalnl_short(StringIO.StringIO("1234\\n56"))
|
>>> read_decimalnl_short(StringIO.StringIO("1234\n56"))
|
||||||
1234
|
1234
|
||||||
|
|
||||||
>>> read_decimalnl_short(StringIO.StringIO("1234L\\n56"))
|
>>> read_decimalnl_short(StringIO.StringIO("1234L\n56"))
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
ValueError: trailing 'L' not allowed in '1234L'
|
ValueError: trailing 'L' not allowed in '1234L'
|
||||||
|
@ -498,20 +498,20 @@ def read_decimalnl_short(f):
|
||||||
return long(s)
|
return long(s)
|
||||||
|
|
||||||
def read_decimalnl_long(f):
|
def read_decimalnl_long(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
|
|
||||||
>>> read_decimalnl_long(StringIO.StringIO("1234\\n56"))
|
>>> read_decimalnl_long(StringIO.StringIO("1234\n56"))
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
ValueError: trailing 'L' required in '1234'
|
ValueError: trailing 'L' required in '1234'
|
||||||
|
|
||||||
Someday the trailing 'L' will probably go away from this output.
|
Someday the trailing 'L' will probably go away from this output.
|
||||||
|
|
||||||
>>> read_decimalnl_long(StringIO.StringIO("1234L\\n56"))
|
>>> read_decimalnl_long(StringIO.StringIO("1234L\n56"))
|
||||||
1234L
|
1234L
|
||||||
|
|
||||||
>>> read_decimalnl_long(StringIO.StringIO("123456789012345678901234L\\n6"))
|
>>> read_decimalnl_long(StringIO.StringIO("123456789012345678901234L\n6"))
|
||||||
123456789012345678901234L
|
123456789012345678901234L
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -546,9 +546,9 @@ decimalnl_long = ArgumentDescriptor(
|
||||||
|
|
||||||
|
|
||||||
def read_floatnl(f):
|
def read_floatnl(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO
|
>>> import StringIO
|
||||||
>>> read_floatnl(StringIO.StringIO("-1.25\\n6"))
|
>>> read_floatnl(StringIO.StringIO("-1.25\n6"))
|
||||||
-1.25
|
-1.25
|
||||||
"""
|
"""
|
||||||
s = read_stringnl(f, decode=False, stripquotes=False)
|
s = read_stringnl(f, decode=False, stripquotes=False)
|
||||||
|
@ -568,12 +568,12 @@ floatnl = ArgumentDescriptor(
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def read_float8(f):
|
def read_float8(f):
|
||||||
"""
|
r"""
|
||||||
>>> import StringIO, struct
|
>>> import StringIO, struct
|
||||||
>>> raw = struct.pack(">d", -1.25)
|
>>> raw = struct.pack(">d", -1.25)
|
||||||
>>> raw
|
>>> raw
|
||||||
'\\xbf\\xf4\\x00\\x00\\x00\\x00\\x00\\x00'
|
'\xbf\xf4\x00\x00\x00\x00\x00\x00'
|
||||||
>>> read_float8(StringIO.StringIO(raw + "\\n"))
|
>>> read_float8(StringIO.StringIO(raw + "\n"))
|
||||||
-1.25
|
-1.25
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue