]> git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Tools/framer/framer/util.py
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Tools / framer / framer / util.py
1 def cstring(s, width=70):
2 """Return C string representation of a Python string.
3
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)
10
11 return "\n".join(L)
12
13 def unindent(s, skipfirst=True):
14 """Return an unindented version of a docstring.
15
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 """
20
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]
34
35 return "\n".join(L)