Back to index

python3.2  3.2.2
Functions | Variables
lib2to3.pgen2.literals Namespace Reference

Functions

def escape
def evalString
def test

Variables

dictionary simple_escapes

Function Documentation

Definition at line 19 of file literals.py.

00019 
00020 def escape(m):
00021     all, tail = m.group(0, 1)
00022     assert all.startswith("\\")
00023     esc = simple_escapes.get(tail)
00024     if esc is not None:
00025         return esc
00026     if tail.startswith("x"):
00027         hexes = tail[1:]
00028         if len(hexes) < 2:
00029             raise ValueError("invalid hex string escape ('\\%s')" % tail)
00030         try:
00031             i = int(hexes, 16)
00032         except ValueError:
00033             raise ValueError("invalid hex string escape ('\\%s')" % tail)
00034     else:
00035         try:
00036             i = int(tail, 8)
00037         except ValueError:
00038             raise ValueError("invalid octal string escape ('\\%s')" % tail)
00039     return chr(i)

Here is the call graph for this function:

Definition at line 40 of file literals.py.

00040 
00041 def evalString(s):
00042     assert s.startswith("'") or s.startswith('"'), repr(s[:1])
00043     q = s[0]
00044     if s[:3] == q*3:
00045         q = q*3
00046     assert s.endswith(q), repr(s[-len(q):])
00047     assert len(s) >= 2*len(q)
00048     s = s[len(q):-len(q)]
00049     return re.sub(r"\\(\'|\"|\\|[abfnrtv]|x.{0,2}|[0-7]{1,3})", escape, s)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 50 of file literals.py.

00050 
00051 def test():
00052     for i in range(256):
00053         c = chr(i)
00054         s = repr(c)
00055         e = evalString(s)
00056         if e != c:
00057             print(i, c, s, e)
00058 

Here is the call graph for this function:


Variable Documentation

Initial value:
00001 {"a": "\a",
00002                   "b": "\b",
00003                   "f": "\f",
00004                   "n": "\n",
00005                   "r": "\r",
00006                   "t": "\t",
00007                   "v": "\v",
00008                   "'": "'",
00009                   '"': '"',
00010                   "\\": "\\"}

Definition at line 8 of file literals.py.