Add better error reporting for MemoryErrors caused by str->float conversions.
[python.git] / Tools / framer / framer / util.py
blob73f33096459b9fef5a397eb90e1b9838345f8724
1 def cstring(s, width=70):
2 """Return C string representation of a Python string.
4 width specifies the maximum width of any line of the C string.
5 """
6 L = []
7 for l in s.split("\n"):
8 if len(l) < width:
9 L.append(r'"%s\n"' % l)
11 return "\n".join(L)
13 def unindent(s, skipfirst=True):
14 """Return an unindented version of a docstring.
16 Removes indentation on lines following the first one, using the
17 leading whitespace of the first indented line that is not blank
18 to determine the indentation.
19 """
21 lines = s.split("\n")
22 if skipfirst:
23 first = lines.pop(0)
24 L = [first]
25 else:
26 L = []
27 indent = None
28 for l in lines:
29 ls = l.strip()
30 if ls:
31 indent = len(l) - len(ls)
32 break
33 L += [l[indent:] for l in lines]
35 return "\n".join(L)