1 from collections
import defaultdict
2 from io
import StringIO
3 from textwrap
import indent
6 class CodeWriter(StringIO
):
8 Blob of text that, when used in the context of facade.py, ends up
9 holding the source code for a Python class and associated methods.
17 def write(self
, msg
, depth
=0):
19 prefix
= self
.INDENT
* depth
20 msg
= indent(msg
, prefix
)
22 return super(CodeWriter
, self
).write(msg
)
25 return super(CodeWriter
, self
).getvalue()
28 class Capture(defaultdict
):
30 A collection of CodeWriter objects, together representing a Python
35 def __init__(self
, default_factory
=CodeWriter
, *args
, **kwargs
):
36 super(Capture
, self
).__init
__(default_factory
, *args
, **kwargs
)
38 def clear(self
, name
):
40 Reset one of the keys in this class, if it exists.
42 This is necessary, because we don't worry about de-duplicating
43 the schemas for each version of juju up front, and this gives
44 us a way to sort of de-duplicate on the fly, by resetting a
45 specific CodeWriter instance before we start to write a class