blob: ab37e94dbeee66462004b981291b857ec7c42a5a [file] [log] [blame]
Benjamin Peterson46a99002010-01-09 18:45:30 +00001# Copyright (C) 2001-2010 Python Software Foundation
Guido van Rossum8b3febe2007-08-30 01:15:14 +00002# Author: Barry Warsaw
3# Contact: email-sig@python.org
4
5"""Classes to generate plain text from a message object tree."""
6
R David Murray1b6c7242012-03-16 22:43:05 -04007__all__ = ['Generator', 'DecodedGenerator', 'BytesGenerator']
Guido van Rossum8b3febe2007-08-30 01:15:14 +00008
9import re
10import sys
11import time
12import random
13import warnings
14
R. David Murray96fd54e2010-10-08 15:55:28 +000015from io import StringIO, BytesIO
Guido van Rossum8b3febe2007-08-30 01:15:14 +000016from email.header import Header
R. David Murray96fd54e2010-10-08 15:55:28 +000017from email.message import _has_surrogates
Guido van Rossum8b3febe2007-08-30 01:15:14 +000018
19UNDERSCORE = '_'
R. David Murray8451c4b2010-10-23 22:19:56 +000020NL = '\n' # XXX: no longer used by the code below.
Guido van Rossum8b3febe2007-08-30 01:15:14 +000021
22fcre = re.compile(r'^From ', re.MULTILINE)
23
24
25
26class Generator:
27 """Generates output from a Message object tree.
28
29 This basic generator writes the message to the given file object as plain
30 text.
31 """
32 #
33 # Public interface
34 #
35
36 def __init__(self, outfp, mangle_from_=True, maxheaderlen=78):
37 """Create the generator for message flattening.
38
39 outfp is the output file-like object for writing the message to. It
40 must have a write() method.
41
42 Optional mangle_from_ is a flag that, when True (the default), escapes
43 From_ lines in the body of the message by putting a `>' in front of
44 them.
45
46 Optional maxheaderlen specifies the longest length for a non-continued
47 header. When a header line is longer (in characters, with tabs
48 expanded to 8 spaces) than maxheaderlen, the header will split as
49 defined in the Header class. Set maxheaderlen to zero to disable
50 header wrapping. The default is 78, as recommended (but not required)
51 by RFC 2822.
52 """
53 self._fp = outfp
54 self._mangle_from_ = mangle_from_
55 self._maxheaderlen = maxheaderlen
56
57 def write(self, s):
58 # Just delegate to the file object
59 self._fp.write(s)
60
R. David Murray8451c4b2010-10-23 22:19:56 +000061 def flatten(self, msg, unixfrom=False, linesep='\n'):
R David Murraycd37dfc2011-03-14 18:35:56 -040062 r"""Print the message object tree rooted at msg to the output file
Guido van Rossum8b3febe2007-08-30 01:15:14 +000063 specified when the Generator instance was created.
64
65 unixfrom is a flag that forces the printing of a Unix From_ delimiter
66 before the first object in the message tree. If the original message
67 has no From_ delimiter, a `standard' one is crafted. By default, this
68 is False to inhibit the printing of any From_ delimiter.
69
70 Note that for subobjects, no From_ line is printed.
R. David Murray8451c4b2010-10-23 22:19:56 +000071
72 linesep specifies the characters used to indicate a new line in
R David Murraycd37dfc2011-03-14 18:35:56 -040073 the output. The default value is the most useful for typical
74 Python applications, but it can be set to \r\n to produce RFC-compliant
75 line separators when needed.
76
Guido van Rossum8b3febe2007-08-30 01:15:14 +000077 """
R. David Murray8451c4b2010-10-23 22:19:56 +000078 # We use the _XXX constants for operating on data that comes directly
79 # from the msg, and _encoded_XXX constants for operating on data that
80 # has already been converted (to bytes in the BytesGenerator) and
81 # inserted into a temporary buffer.
82 self._NL = linesep
83 self._encoded_NL = self._encode(linesep)
84 self._EMPTY = ''
85 self._encoded_EMTPY = self._encode('')
Guido van Rossum8b3febe2007-08-30 01:15:14 +000086 if unixfrom:
87 ufrom = msg.get_unixfrom()
88 if not ufrom:
89 ufrom = 'From nobody ' + time.ctime(time.time())
R. David Murray8451c4b2010-10-23 22:19:56 +000090 self.write(ufrom + self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +000091 self._write(msg)
92
93 def clone(self, fp):
94 """Clone this generator with the exact same options."""
95 return self.__class__(fp, self._mangle_from_, self._maxheaderlen)
96
97 #
98 # Protected interface - undocumented ;/
99 #
100
R. David Murray96fd54e2010-10-08 15:55:28 +0000101 # Note that we use 'self.write' when what we are writing is coming from
102 # the source, and self._fp.write when what we are writing is coming from a
103 # buffer (because the Bytes subclass has already had a chance to transform
104 # the data in its write method in that case). This is an entirely
105 # pragmatic split determined by experiment; we could be more general by
106 # always using write and having the Bytes subclass write method detect when
107 # it has already transformed the input; but, since this whole thing is a
108 # hack anyway this seems good enough.
109
R. David Murray8451c4b2010-10-23 22:19:56 +0000110 # Similarly, we have _XXX and _encoded_XXX attributes that are used on
111 # source and buffer data, respectively.
112 _encoded_EMPTY = ''
R. David Murray96fd54e2010-10-08 15:55:28 +0000113
114 def _new_buffer(self):
115 # BytesGenerator overrides this to return BytesIO.
116 return StringIO()
117
R. David Murray8451c4b2010-10-23 22:19:56 +0000118 def _encode(self, s):
119 # BytesGenerator overrides this to encode strings to bytes.
120 return s
121
R David Murraye67c6c52013-03-07 16:38:03 -0500122 def _write_lines(self, lines):
123 # We have to transform the line endings.
124 if not lines:
125 return
126 lines = lines.splitlines(True)
127 for line in lines[:-1]:
128 self.write(line.rstrip('\r\n'))
129 self.write(self._NL)
130 laststripped = lines[-1].rstrip('\r\n')
131 self.write(laststripped)
R David Murrayb9534f42013-03-07 18:15:13 -0500132 if len(lines[-1]) != len(laststripped):
R David Murraye67c6c52013-03-07 16:38:03 -0500133 self.write(self._NL)
134
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000135 def _write(self, msg):
136 # We can't write the headers yet because of the following scenario:
137 # say a multipart message includes the boundary string somewhere in
138 # its body. We'd have to calculate the new boundary /before/ we write
139 # the headers so that we can write the correct Content-Type:
140 # parameter.
141 #
142 # The way we do this, so as to make the _handle_*() methods simpler,
R. David Murray96fd54e2010-10-08 15:55:28 +0000143 # is to cache any subpart writes into a buffer. The we write the
144 # headers and the buffer contents. That way, subpart handlers can
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000145 # Do The Right Thing, and can still modify the Content-Type: header if
146 # necessary.
147 oldfp = self._fp
148 try:
R. David Murray96fd54e2010-10-08 15:55:28 +0000149 self._fp = sfp = self._new_buffer()
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000150 self._dispatch(msg)
151 finally:
152 self._fp = oldfp
153 # Write the headers. First we see if the message object wants to
154 # handle that itself. If not, we'll do it generically.
155 meth = getattr(msg, '_write_headers', None)
156 if meth is None:
157 self._write_headers(msg)
158 else:
159 meth(self)
160 self._fp.write(sfp.getvalue())
161
162 def _dispatch(self, msg):
163 # Get the Content-Type: for the message, then try to dispatch to
164 # self._handle_<maintype>_<subtype>(). If there's no handler for the
165 # full MIME type, then dispatch to self._handle_<maintype>(). If
166 # that's missing too, then dispatch to self._writeBody().
167 main = msg.get_content_maintype()
168 sub = msg.get_content_subtype()
169 specific = UNDERSCORE.join((main, sub)).replace('-', '_')
170 meth = getattr(self, '_handle_' + specific, None)
171 if meth is None:
172 generic = main.replace('-', '_')
173 meth = getattr(self, '_handle_' + generic, None)
174 if meth is None:
175 meth = self._writeBody
176 meth(msg)
177
178 #
179 # Default handlers
180 #
181
182 def _write_headers(self, msg):
183 for h, v in msg.items():
R. David Murray96fd54e2010-10-08 15:55:28 +0000184 self.write('%s: ' % h)
Guido van Rossum9604e662007-08-30 03:46:43 +0000185 if isinstance(v, Header):
R. David Murray8451c4b2010-10-23 22:19:56 +0000186 self.write(v.encode(
187 maxlinelen=self._maxheaderlen, linesep=self._NL)+self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000188 else:
189 # Header's got lots of smarts, so use it.
190 header = Header(v, maxlinelen=self._maxheaderlen,
Barry Warsaw70d61ce2009-03-30 23:12:30 +0000191 header_name=h)
R. David Murray8451c4b2010-10-23 22:19:56 +0000192 self.write(header.encode(linesep=self._NL)+self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000193 # A blank line always separates headers from body
R. David Murray8451c4b2010-10-23 22:19:56 +0000194 self.write(self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000195
196 #
197 # Handlers for writing types and subtypes
198 #
199
200 def _handle_text(self, msg):
201 payload = msg.get_payload()
202 if payload is None:
203 return
Guido van Rossum3172c5d2007-10-16 18:12:55 +0000204 if not isinstance(payload, str):
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000205 raise TypeError('string payload expected: %s' % type(payload))
R. David Murray96fd54e2010-10-08 15:55:28 +0000206 if _has_surrogates(msg._payload):
207 charset = msg.get_param('charset')
208 if charset is not None:
209 del msg['content-transfer-encoding']
210 msg.set_payload(payload, charset)
211 payload = msg.get_payload()
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000212 if self._mangle_from_:
213 payload = fcre.sub('>From ', payload)
R David Murraye67c6c52013-03-07 16:38:03 -0500214 self._write_lines(payload)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000215
216 # Default body handler
217 _writeBody = _handle_text
218
219 def _handle_multipart(self, msg):
220 # The trick here is to write out each part separately, merge them all
221 # together, and then make sure that the boundary we've chosen isn't
222 # present in the payload.
223 msgtexts = []
224 subparts = msg.get_payload()
225 if subparts is None:
226 subparts = []
Guido van Rossum3172c5d2007-10-16 18:12:55 +0000227 elif isinstance(subparts, str):
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000228 # e.g. a non-strict parse of a message with no starting boundary.
R. David Murray96fd54e2010-10-08 15:55:28 +0000229 self.write(subparts)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000230 return
231 elif not isinstance(subparts, list):
232 # Scalar payload
233 subparts = [subparts]
234 for part in subparts:
R. David Murray96fd54e2010-10-08 15:55:28 +0000235 s = self._new_buffer()
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000236 g = self.clone(s)
R. David Murray8451c4b2010-10-23 22:19:56 +0000237 g.flatten(part, unixfrom=False, linesep=self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000238 msgtexts.append(s.getvalue())
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000239 # BAW: What about boundaries that are wrapped in double-quotes?
R. David Murray5260a9b2010-12-12 20:06:19 +0000240 boundary = msg.get_boundary()
241 if not boundary:
242 # Create a boundary that doesn't appear in any of the
243 # message texts.
244 alltext = self._encoded_NL.join(msgtexts)
R. David Murray73a559d2010-12-21 18:07:59 +0000245 boundary = self._make_boundary(alltext)
246 msg.set_boundary(boundary)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000247 # If there's a preamble, write it out, with a trailing CRLF
248 if msg.preamble is not None:
R David Murray6a31bc62012-07-22 21:47:53 -0400249 if self._mangle_from_:
250 preamble = fcre.sub('>From ', msg.preamble)
251 else:
252 preamble = msg.preamble
R David Murraye67c6c52013-03-07 16:38:03 -0500253 self._write_lines(preamble)
254 self.write(self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000255 # dash-boundary transport-padding CRLF
R. David Murray8451c4b2010-10-23 22:19:56 +0000256 self.write('--' + boundary + self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000257 # body-part
258 if msgtexts:
259 self._fp.write(msgtexts.pop(0))
260 # *encapsulation
261 # --> delimiter transport-padding
262 # --> CRLF body-part
263 for body_part in msgtexts:
264 # delimiter transport-padding CRLF
R. David Murray8451c4b2010-10-23 22:19:56 +0000265 self.write(self._NL + '--' + boundary + self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000266 # body-part
267 self._fp.write(body_part)
268 # close-delimiter transport-padding
R. David Murray8451c4b2010-10-23 22:19:56 +0000269 self.write(self._NL + '--' + boundary + '--')
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000270 if msg.epilogue is not None:
R. David Murray8451c4b2010-10-23 22:19:56 +0000271 self.write(self._NL)
R David Murray6a31bc62012-07-22 21:47:53 -0400272 if self._mangle_from_:
273 epilogue = fcre.sub('>From ', msg.epilogue)
274 else:
275 epilogue = msg.epilogue
R David Murraye67c6c52013-03-07 16:38:03 -0500276 self._write_lines(epilogue)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000277
R. David Murraya8f480f2010-01-16 18:30:03 +0000278 def _handle_multipart_signed(self, msg):
279 # The contents of signed parts has to stay unmodified in order to keep
280 # the signature intact per RFC1847 2.1, so we disable header wrapping.
281 # RDM: This isn't enough to completely preserve the part, but it helps.
282 old_maxheaderlen = self._maxheaderlen
283 try:
284 self._maxheaderlen = 0
285 self._handle_multipart(msg)
286 finally:
287 self._maxheaderlen = old_maxheaderlen
288
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000289 def _handle_message_delivery_status(self, msg):
290 # We can't just write the headers directly to self's file object
291 # because this will leave an extra newline between the last header
292 # block and the boundary. Sigh.
293 blocks = []
294 for part in msg.get_payload():
R. David Murray96fd54e2010-10-08 15:55:28 +0000295 s = self._new_buffer()
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000296 g = self.clone(s)
R. David Murray719a4492010-11-21 16:53:48 +0000297 g.flatten(part, unixfrom=False, linesep=self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000298 text = s.getvalue()
R. David Murray8451c4b2010-10-23 22:19:56 +0000299 lines = text.split(self._encoded_NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000300 # Strip off the unnecessary trailing empty line
R. David Murray8451c4b2010-10-23 22:19:56 +0000301 if lines and lines[-1] == self._encoded_EMPTY:
302 blocks.append(self._encoded_NL.join(lines[:-1]))
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000303 else:
304 blocks.append(text)
305 # Now join all the blocks with an empty line. This has the lovely
306 # effect of separating each block with an empty line, but not adding
307 # an extra one after the last one.
R. David Murray8451c4b2010-10-23 22:19:56 +0000308 self._fp.write(self._encoded_NL.join(blocks))
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000309
310 def _handle_message(self, msg):
R. David Murray96fd54e2010-10-08 15:55:28 +0000311 s = self._new_buffer()
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000312 g = self.clone(s)
313 # The payload of a message/rfc822 part should be a multipart sequence
314 # of length 1. The zeroth element of the list should be the Message
315 # object for the subpart. Extract that object, stringify it, and
316 # write it out.
R. David Murray57c45ac2010-02-21 04:39:40 +0000317 # Except, it turns out, when it's a string instead, which happens when
318 # and only when HeaderParser is used on a message of mime type
319 # message/rfc822. Such messages are generated by, for example,
320 # Groupwise when forwarding unadorned messages. (Issue 7970.) So
321 # in that case we just emit the string body.
322 payload = msg.get_payload()
323 if isinstance(payload, list):
R. David Murray719a4492010-11-21 16:53:48 +0000324 g.flatten(msg.get_payload(0), unixfrom=False, linesep=self._NL)
R. David Murray57c45ac2010-02-21 04:39:40 +0000325 payload = s.getvalue()
326 self._fp.write(payload)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000327
R. David Murray96fd54e2010-10-08 15:55:28 +0000328 # This used to be a module level function; we use a classmethod for this
329 # and _compile_re so we can continue to provide the module level function
330 # for backward compatibility by doing
331 # _make_boudary = Generator._make_boundary
332 # at the end of the module. It *is* internal, so we could drop that...
333 @classmethod
334 def _make_boundary(cls, text=None):
335 # Craft a random boundary. If text is given, ensure that the chosen
336 # boundary doesn't appear in the text.
337 token = random.randrange(sys.maxsize)
338 boundary = ('=' * 15) + (_fmt % token) + '=='
339 if text is None:
340 return boundary
341 b = boundary
342 counter = 0
343 while True:
344 cre = cls._compile_re('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
345 if not cre.search(text):
346 break
347 b = boundary + '.' + str(counter)
348 counter += 1
349 return b
350
351 @classmethod
352 def _compile_re(cls, s, flags):
353 return re.compile(s, flags)
354
355
356class BytesGenerator(Generator):
357 """Generates a bytes version of a Message object tree.
358
359 Functionally identical to the base Generator except that the output is
360 bytes and not string. When surrogates were used in the input to encode
361 bytes, these are decoded back to bytes for output.
362
363 The outfp object must accept bytes in its write method.
364 """
365
R. David Murray8451c4b2010-10-23 22:19:56 +0000366 # Bytes versions of this constant for use in manipulating data from
R. David Murray96fd54e2010-10-08 15:55:28 +0000367 # the BytesIO buffer.
R. David Murray8451c4b2010-10-23 22:19:56 +0000368 _encoded_EMPTY = b''
R. David Murray96fd54e2010-10-08 15:55:28 +0000369
370 def write(self, s):
371 self._fp.write(s.encode('ascii', 'surrogateescape'))
372
373 def _new_buffer(self):
374 return BytesIO()
375
R. David Murray8451c4b2010-10-23 22:19:56 +0000376 def _encode(self, s):
377 return s.encode('ascii')
378
R. David Murray96fd54e2010-10-08 15:55:28 +0000379 def _write_headers(self, msg):
380 # This is almost the same as the string version, except for handling
381 # strings with 8bit bytes.
382 for h, v in msg._headers:
383 self.write('%s: ' % h)
384 if isinstance(v, Header):
R David Murray9fd170e2012-03-14 14:05:03 -0400385 self.write(v.encode(maxlinelen=self._maxheaderlen)+self._NL)
R. David Murray96fd54e2010-10-08 15:55:28 +0000386 elif _has_surrogates(v):
387 # If we have raw 8bit data in a byte string, we have no idea
388 # what the encoding is. There is no safe way to split this
389 # string. If it's ascii-subset, then we could do a normal
390 # ascii split, but if it's multibyte then we could break the
391 # string. There's no way to know so the least harm seems to
392 # be to not split the string and risk it being too long.
393 self.write(v+NL)
394 else:
395 # Header's got lots of smarts and this string is safe...
396 header = Header(v, maxlinelen=self._maxheaderlen,
397 header_name=h)
R. David Murray8451c4b2010-10-23 22:19:56 +0000398 self.write(header.encode(linesep=self._NL)+self._NL)
R. David Murray96fd54e2010-10-08 15:55:28 +0000399 # A blank line always separates headers from body
R. David Murray8451c4b2010-10-23 22:19:56 +0000400 self.write(self._NL)
R. David Murray96fd54e2010-10-08 15:55:28 +0000401
402 def _handle_text(self, msg):
403 # If the string has surrogates the original source was bytes, so
404 # just write it back out.
R. David Murray7372a072011-01-26 21:21:32 +0000405 if msg._payload is None:
406 return
R. David Murraybdd2d932011-01-26 02:31:37 +0000407 if _has_surrogates(msg._payload):
R David Murray638d40b2012-08-24 11:14:13 -0400408 if self._mangle_from_:
409 msg._payload = fcre.sub(">From ", msg._payload)
R David Murraye67c6c52013-03-07 16:38:03 -0500410 self._write_lines(msg._payload)
R. David Murray96fd54e2010-10-08 15:55:28 +0000411 else:
412 super(BytesGenerator,self)._handle_text(msg)
413
R David Murrayceaa8b12013-02-09 13:02:58 -0500414 # Default body handler
415 _writeBody = _handle_text
416
R. David Murray96fd54e2010-10-08 15:55:28 +0000417 @classmethod
418 def _compile_re(cls, s, flags):
419 return re.compile(s.encode('ascii'), flags)
420
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000421
422
423_FMT = '[Non-text (%(type)s) part of message omitted, filename %(filename)s]'
424
425class DecodedGenerator(Generator):
R. David Murray70a99932010-10-01 20:38:33 +0000426 """Generates a text representation of a message.
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000427
428 Like the Generator base class, except that non-text parts are substituted
429 with a format string representing the part.
430 """
431 def __init__(self, outfp, mangle_from_=True, maxheaderlen=78, fmt=None):
432 """Like Generator.__init__() except that an additional optional
433 argument is allowed.
434
435 Walks through all subparts of a message. If the subpart is of main
436 type `text', then it prints the decoded payload of the subpart.
437
438 Otherwise, fmt is a format string that is used instead of the message
439 payload. fmt is expanded with the following keywords (in
440 %(keyword)s format):
441
442 type : Full MIME type of the non-text part
443 maintype : Main MIME type of the non-text part
444 subtype : Sub-MIME type of the non-text part
445 filename : Filename of the non-text part
446 description: Description associated with the non-text part
447 encoding : Content transfer encoding of the non-text part
448
449 The default value for fmt is None, meaning
450
451 [Non-text (%(type)s) part of message omitted, filename %(filename)s]
452 """
453 Generator.__init__(self, outfp, mangle_from_, maxheaderlen)
454 if fmt is None:
455 self._fmt = _FMT
456 else:
457 self._fmt = fmt
458
459 def _dispatch(self, msg):
460 for part in msg.walk():
461 maintype = part.get_content_maintype()
462 if maintype == 'text':
Guido van Rossum3172c5d2007-10-16 18:12:55 +0000463 print(part.get_payload(decode=False), file=self)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000464 elif maintype == 'multipart':
465 # Just skip this
466 pass
467 else:
468 print(self._fmt % {
469 'type' : part.get_content_type(),
470 'maintype' : part.get_content_maintype(),
471 'subtype' : part.get_content_subtype(),
472 'filename' : part.get_filename('[no filename]'),
473 'description': part.get('Content-Description',
474 '[no description]'),
475 'encoding' : part.get('Content-Transfer-Encoding',
476 '[no encoding]'),
477 }, file=self)
478
479
480
R. David Murray96fd54e2010-10-08 15:55:28 +0000481# Helper used by Generator._make_boundary
Christian Heimesa37d4c62007-12-04 23:02:19 +0000482_width = len(repr(sys.maxsize-1))
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000483_fmt = '%%0%dd' % _width
484
R. David Murray96fd54e2010-10-08 15:55:28 +0000485# Backward compatibility
486_make_boundary = Generator._make_boundary