blob: d8b8fa960b04ecafbce278e81f8a94d0877bea41 [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
7__all__ = ['Generator', 'DecodedGenerator']
8
9import re
10import sys
11import time
12import random
13import warnings
14
R. David Murray96fd54e2010-10-08 15:55:28 +000015from io import StringIO, BytesIO
R David Murray3edd22a2011-04-18 13:59:37 -040016from email import policy
Guido van Rossum8b3febe2007-08-30 01:15:14 +000017from email.header import Header
R. David Murray96fd54e2010-10-08 15:55:28 +000018from email.message import _has_surrogates
R David Murray3edd22a2011-04-18 13:59:37 -040019import email.charset as _charset
Guido van Rossum8b3febe2007-08-30 01:15:14 +000020
21UNDERSCORE = '_'
R. David Murray8451c4b2010-10-23 22:19:56 +000022NL = '\n' # XXX: no longer used by the code below.
Guido van Rossum8b3febe2007-08-30 01:15:14 +000023
24fcre = re.compile(r'^From ', re.MULTILINE)
25
26
27
28class Generator:
29 """Generates output from a Message object tree.
30
31 This basic generator writes the message to the given file object as plain
32 text.
33 """
34 #
35 # Public interface
36 #
37
R David Murray3edd22a2011-04-18 13:59:37 -040038 def __init__(self, outfp, mangle_from_=True, maxheaderlen=None, *,
39 policy=policy.default):
Guido van Rossum8b3febe2007-08-30 01:15:14 +000040 """Create the generator for message flattening.
41
42 outfp is the output file-like object for writing the message to. It
43 must have a write() method.
44
45 Optional mangle_from_ is a flag that, when True (the default), escapes
46 From_ lines in the body of the message by putting a `>' in front of
47 them.
48
49 Optional maxheaderlen specifies the longest length for a non-continued
50 header. When a header line is longer (in characters, with tabs
51 expanded to 8 spaces) than maxheaderlen, the header will split as
52 defined in the Header class. Set maxheaderlen to zero to disable
53 header wrapping. The default is 78, as recommended (but not required)
54 by RFC 2822.
R David Murray3edd22a2011-04-18 13:59:37 -040055
56 The policy keyword specifies a policy object that controls a number of
57 aspects of the generator's operation. The default policy maintains
58 backward compatibility.
59
Guido van Rossum8b3febe2007-08-30 01:15:14 +000060 """
61 self._fp = outfp
62 self._mangle_from_ = mangle_from_
R David Murray3edd22a2011-04-18 13:59:37 -040063 self._maxheaderlen = (maxheaderlen if maxheaderlen is not None else
64 policy.max_line_length)
65 self.policy = policy
Guido van Rossum8b3febe2007-08-30 01:15:14 +000066
67 def write(self, s):
68 # Just delegate to the file object
69 self._fp.write(s)
70
R David Murray3edd22a2011-04-18 13:59:37 -040071 def flatten(self, msg, unixfrom=False, linesep=None):
R David Murraycd37dfc2011-03-14 18:35:56 -040072 r"""Print the message object tree rooted at msg to the output file
Guido van Rossum8b3febe2007-08-30 01:15:14 +000073 specified when the Generator instance was created.
74
75 unixfrom is a flag that forces the printing of a Unix From_ delimiter
76 before the first object in the message tree. If the original message
77 has no From_ delimiter, a `standard' one is crafted. By default, this
78 is False to inhibit the printing of any From_ delimiter.
79
80 Note that for subobjects, no From_ line is printed.
R. David Murray8451c4b2010-10-23 22:19:56 +000081
82 linesep specifies the characters used to indicate a new line in
R David Murray3edd22a2011-04-18 13:59:37 -040083 the output. The default value is determined by the policy.
R David Murraycd37dfc2011-03-14 18:35:56 -040084
Guido van Rossum8b3febe2007-08-30 01:15:14 +000085 """
R. David Murray8451c4b2010-10-23 22:19:56 +000086 # We use the _XXX constants for operating on data that comes directly
87 # from the msg, and _encoded_XXX constants for operating on data that
88 # has already been converted (to bytes in the BytesGenerator) and
89 # inserted into a temporary buffer.
R David Murray3edd22a2011-04-18 13:59:37 -040090 self._NL = linesep if linesep is not None else self.policy.linesep
91 self._encoded_NL = self._encode(self._NL)
R. David Murray8451c4b2010-10-23 22:19:56 +000092 self._EMPTY = ''
93 self._encoded_EMTPY = self._encode('')
Guido van Rossum8b3febe2007-08-30 01:15:14 +000094 if unixfrom:
95 ufrom = msg.get_unixfrom()
96 if not ufrom:
97 ufrom = 'From nobody ' + time.ctime(time.time())
R. David Murray8451c4b2010-10-23 22:19:56 +000098 self.write(ufrom + self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +000099 self._write(msg)
100
101 def clone(self, fp):
102 """Clone this generator with the exact same options."""
103 return self.__class__(fp, self._mangle_from_, self._maxheaderlen)
104
105 #
106 # Protected interface - undocumented ;/
107 #
108
R. David Murray96fd54e2010-10-08 15:55:28 +0000109 # Note that we use 'self.write' when what we are writing is coming from
110 # the source, and self._fp.write when what we are writing is coming from a
111 # buffer (because the Bytes subclass has already had a chance to transform
112 # the data in its write method in that case). This is an entirely
113 # pragmatic split determined by experiment; we could be more general by
114 # always using write and having the Bytes subclass write method detect when
115 # it has already transformed the input; but, since this whole thing is a
116 # hack anyway this seems good enough.
117
R. David Murray8451c4b2010-10-23 22:19:56 +0000118 # Similarly, we have _XXX and _encoded_XXX attributes that are used on
119 # source and buffer data, respectively.
120 _encoded_EMPTY = ''
R. David Murray96fd54e2010-10-08 15:55:28 +0000121
122 def _new_buffer(self):
123 # BytesGenerator overrides this to return BytesIO.
124 return StringIO()
125
R. David Murray8451c4b2010-10-23 22:19:56 +0000126 def _encode(self, s):
127 # BytesGenerator overrides this to encode strings to bytes.
128 return s
129
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000130 def _write(self, msg):
131 # We can't write the headers yet because of the following scenario:
132 # say a multipart message includes the boundary string somewhere in
133 # its body. We'd have to calculate the new boundary /before/ we write
134 # the headers so that we can write the correct Content-Type:
135 # parameter.
136 #
137 # The way we do this, so as to make the _handle_*() methods simpler,
R. David Murray96fd54e2010-10-08 15:55:28 +0000138 # is to cache any subpart writes into a buffer. The we write the
139 # headers and the buffer contents. That way, subpart handlers can
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000140 # Do The Right Thing, and can still modify the Content-Type: header if
141 # necessary.
142 oldfp = self._fp
143 try:
R. David Murray96fd54e2010-10-08 15:55:28 +0000144 self._fp = sfp = self._new_buffer()
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000145 self._dispatch(msg)
146 finally:
147 self._fp = oldfp
148 # Write the headers. First we see if the message object wants to
149 # handle that itself. If not, we'll do it generically.
150 meth = getattr(msg, '_write_headers', None)
151 if meth is None:
152 self._write_headers(msg)
153 else:
154 meth(self)
155 self._fp.write(sfp.getvalue())
156
157 def _dispatch(self, msg):
158 # Get the Content-Type: for the message, then try to dispatch to
159 # self._handle_<maintype>_<subtype>(). If there's no handler for the
160 # full MIME type, then dispatch to self._handle_<maintype>(). If
161 # that's missing too, then dispatch to self._writeBody().
162 main = msg.get_content_maintype()
163 sub = msg.get_content_subtype()
164 specific = UNDERSCORE.join((main, sub)).replace('-', '_')
165 meth = getattr(self, '_handle_' + specific, None)
166 if meth is None:
167 generic = main.replace('-', '_')
168 meth = getattr(self, '_handle_' + generic, None)
169 if meth is None:
170 meth = self._writeBody
171 meth(msg)
172
173 #
174 # Default handlers
175 #
176
177 def _write_headers(self, msg):
178 for h, v in msg.items():
R. David Murray96fd54e2010-10-08 15:55:28 +0000179 self.write('%s: ' % h)
Guido van Rossum9604e662007-08-30 03:46:43 +0000180 if isinstance(v, Header):
R. David Murray8451c4b2010-10-23 22:19:56 +0000181 self.write(v.encode(
182 maxlinelen=self._maxheaderlen, linesep=self._NL)+self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000183 else:
184 # Header's got lots of smarts, so use it.
185 header = Header(v, maxlinelen=self._maxheaderlen,
Barry Warsaw70d61ce2009-03-30 23:12:30 +0000186 header_name=h)
R. David Murray8451c4b2010-10-23 22:19:56 +0000187 self.write(header.encode(linesep=self._NL)+self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000188 # A blank line always separates headers from body
R. David Murray8451c4b2010-10-23 22:19:56 +0000189 self.write(self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000190
191 #
192 # Handlers for writing types and subtypes
193 #
194
195 def _handle_text(self, msg):
196 payload = msg.get_payload()
197 if payload is None:
198 return
Guido van Rossum3172c5d2007-10-16 18:12:55 +0000199 if not isinstance(payload, str):
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000200 raise TypeError('string payload expected: %s' % type(payload))
R. David Murray96fd54e2010-10-08 15:55:28 +0000201 if _has_surrogates(msg._payload):
202 charset = msg.get_param('charset')
203 if charset is not None:
204 del msg['content-transfer-encoding']
205 msg.set_payload(payload, charset)
206 payload = msg.get_payload()
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000207 if self._mangle_from_:
208 payload = fcre.sub('>From ', payload)
R. David Murray96fd54e2010-10-08 15:55:28 +0000209 self.write(payload)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000210
211 # Default body handler
212 _writeBody = _handle_text
213
214 def _handle_multipart(self, msg):
215 # The trick here is to write out each part separately, merge them all
216 # together, and then make sure that the boundary we've chosen isn't
217 # present in the payload.
218 msgtexts = []
219 subparts = msg.get_payload()
220 if subparts is None:
221 subparts = []
Guido van Rossum3172c5d2007-10-16 18:12:55 +0000222 elif isinstance(subparts, str):
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000223 # e.g. a non-strict parse of a message with no starting boundary.
R. David Murray96fd54e2010-10-08 15:55:28 +0000224 self.write(subparts)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000225 return
226 elif not isinstance(subparts, list):
227 # Scalar payload
228 subparts = [subparts]
229 for part in subparts:
R. David Murray96fd54e2010-10-08 15:55:28 +0000230 s = self._new_buffer()
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000231 g = self.clone(s)
R. David Murray8451c4b2010-10-23 22:19:56 +0000232 g.flatten(part, unixfrom=False, linesep=self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000233 msgtexts.append(s.getvalue())
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000234 # BAW: What about boundaries that are wrapped in double-quotes?
R. David Murray5260a9b2010-12-12 20:06:19 +0000235 boundary = msg.get_boundary()
236 if not boundary:
237 # Create a boundary that doesn't appear in any of the
238 # message texts.
239 alltext = self._encoded_NL.join(msgtexts)
R. David Murray73a559d2010-12-21 18:07:59 +0000240 boundary = self._make_boundary(alltext)
241 msg.set_boundary(boundary)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000242 # If there's a preamble, write it out, with a trailing CRLF
243 if msg.preamble is not None:
R. David Murray8451c4b2010-10-23 22:19:56 +0000244 self.write(msg.preamble + self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000245 # dash-boundary transport-padding CRLF
R. David Murray8451c4b2010-10-23 22:19:56 +0000246 self.write('--' + boundary + self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000247 # body-part
248 if msgtexts:
249 self._fp.write(msgtexts.pop(0))
250 # *encapsulation
251 # --> delimiter transport-padding
252 # --> CRLF body-part
253 for body_part in msgtexts:
254 # delimiter transport-padding CRLF
R. David Murray8451c4b2010-10-23 22:19:56 +0000255 self.write(self._NL + '--' + boundary + self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000256 # body-part
257 self._fp.write(body_part)
258 # close-delimiter transport-padding
R. David Murray8451c4b2010-10-23 22:19:56 +0000259 self.write(self._NL + '--' + boundary + '--')
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000260 if msg.epilogue is not None:
R. David Murray8451c4b2010-10-23 22:19:56 +0000261 self.write(self._NL)
R. David Murray96fd54e2010-10-08 15:55:28 +0000262 self.write(msg.epilogue)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000263
R. David Murraya8f480f2010-01-16 18:30:03 +0000264 def _handle_multipart_signed(self, msg):
265 # The contents of signed parts has to stay unmodified in order to keep
266 # the signature intact per RFC1847 2.1, so we disable header wrapping.
267 # RDM: This isn't enough to completely preserve the part, but it helps.
268 old_maxheaderlen = self._maxheaderlen
269 try:
270 self._maxheaderlen = 0
271 self._handle_multipart(msg)
272 finally:
273 self._maxheaderlen = old_maxheaderlen
274
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000275 def _handle_message_delivery_status(self, msg):
276 # We can't just write the headers directly to self's file object
277 # because this will leave an extra newline between the last header
278 # block and the boundary. Sigh.
279 blocks = []
280 for part in msg.get_payload():
R. David Murray96fd54e2010-10-08 15:55:28 +0000281 s = self._new_buffer()
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000282 g = self.clone(s)
R. David Murray719a4492010-11-21 16:53:48 +0000283 g.flatten(part, unixfrom=False, linesep=self._NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000284 text = s.getvalue()
R. David Murray8451c4b2010-10-23 22:19:56 +0000285 lines = text.split(self._encoded_NL)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000286 # Strip off the unnecessary trailing empty line
R. David Murray8451c4b2010-10-23 22:19:56 +0000287 if lines and lines[-1] == self._encoded_EMPTY:
288 blocks.append(self._encoded_NL.join(lines[:-1]))
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000289 else:
290 blocks.append(text)
291 # Now join all the blocks with an empty line. This has the lovely
292 # effect of separating each block with an empty line, but not adding
293 # an extra one after the last one.
R. David Murray8451c4b2010-10-23 22:19:56 +0000294 self._fp.write(self._encoded_NL.join(blocks))
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000295
296 def _handle_message(self, msg):
R. David Murray96fd54e2010-10-08 15:55:28 +0000297 s = self._new_buffer()
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000298 g = self.clone(s)
299 # The payload of a message/rfc822 part should be a multipart sequence
300 # of length 1. The zeroth element of the list should be the Message
301 # object for the subpart. Extract that object, stringify it, and
302 # write it out.
R. David Murray57c45ac2010-02-21 04:39:40 +0000303 # Except, it turns out, when it's a string instead, which happens when
304 # and only when HeaderParser is used on a message of mime type
305 # message/rfc822. Such messages are generated by, for example,
306 # Groupwise when forwarding unadorned messages. (Issue 7970.) So
307 # in that case we just emit the string body.
R David Murrayb35c8502011-04-13 16:46:05 -0400308 payload = msg._payload
R. David Murray57c45ac2010-02-21 04:39:40 +0000309 if isinstance(payload, list):
R. David Murray719a4492010-11-21 16:53:48 +0000310 g.flatten(msg.get_payload(0), unixfrom=False, linesep=self._NL)
R. David Murray57c45ac2010-02-21 04:39:40 +0000311 payload = s.getvalue()
R David Murrayb35c8502011-04-13 16:46:05 -0400312 else:
313 payload = self._encode(payload)
R. David Murray57c45ac2010-02-21 04:39:40 +0000314 self._fp.write(payload)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000315
R. David Murray96fd54e2010-10-08 15:55:28 +0000316 # This used to be a module level function; we use a classmethod for this
317 # and _compile_re so we can continue to provide the module level function
318 # for backward compatibility by doing
319 # _make_boudary = Generator._make_boundary
320 # at the end of the module. It *is* internal, so we could drop that...
321 @classmethod
322 def _make_boundary(cls, text=None):
323 # Craft a random boundary. If text is given, ensure that the chosen
324 # boundary doesn't appear in the text.
325 token = random.randrange(sys.maxsize)
326 boundary = ('=' * 15) + (_fmt % token) + '=='
327 if text is None:
328 return boundary
329 b = boundary
330 counter = 0
331 while True:
332 cre = cls._compile_re('^--' + re.escape(b) + '(--)?$', re.MULTILINE)
333 if not cre.search(text):
334 break
335 b = boundary + '.' + str(counter)
336 counter += 1
337 return b
338
339 @classmethod
340 def _compile_re(cls, s, flags):
341 return re.compile(s, flags)
342
343
344class BytesGenerator(Generator):
345 """Generates a bytes version of a Message object tree.
346
347 Functionally identical to the base Generator except that the output is
348 bytes and not string. When surrogates were used in the input to encode
R David Murray3edd22a2011-04-18 13:59:37 -0400349 bytes, these are decoded back to bytes for output. If the policy has
350 must_be_7bit set true, then the message is transformed such that the
351 non-ASCII bytes are properly content transfer encoded, using the
352 charset unknown-8bit.
R. David Murray96fd54e2010-10-08 15:55:28 +0000353
354 The outfp object must accept bytes in its write method.
355 """
356
R. David Murray8451c4b2010-10-23 22:19:56 +0000357 # Bytes versions of this constant for use in manipulating data from
R. David Murray96fd54e2010-10-08 15:55:28 +0000358 # the BytesIO buffer.
R. David Murray8451c4b2010-10-23 22:19:56 +0000359 _encoded_EMPTY = b''
R. David Murray96fd54e2010-10-08 15:55:28 +0000360
361 def write(self, s):
362 self._fp.write(s.encode('ascii', 'surrogateescape'))
363
364 def _new_buffer(self):
365 return BytesIO()
366
R. David Murray8451c4b2010-10-23 22:19:56 +0000367 def _encode(self, s):
368 return s.encode('ascii')
369
R. David Murray96fd54e2010-10-08 15:55:28 +0000370 def _write_headers(self, msg):
371 # This is almost the same as the string version, except for handling
372 # strings with 8bit bytes.
373 for h, v in msg._headers:
374 self.write('%s: ' % h)
R David Murray3edd22a2011-04-18 13:59:37 -0400375 if isinstance(v, str):
376 if _has_surrogates(v):
377 if not self.policy.must_be_7bit:
378 # If we have raw 8bit data in a byte string, we have no idea
379 # what the encoding is. There is no safe way to split this
380 # string. If it's ascii-subset, then we could do a normal
381 # ascii split, but if it's multibyte then we could break the
382 # string. There's no way to know so the least harm seems to
383 # be to not split the string and risk it being too long.
384 self.write(v+NL)
385 continue
386 h = Header(v, charset=_charset.UNKNOWN8BIT, header_name=h)
387 else:
388 h = Header(v, header_name=h)
389 self.write(h.encode(linesep=self._NL,
390 maxlinelen=self._maxheaderlen)+self._NL)
R. David Murray96fd54e2010-10-08 15:55:28 +0000391 # A blank line always separates headers from body
R. David Murray8451c4b2010-10-23 22:19:56 +0000392 self.write(self._NL)
R. David Murray96fd54e2010-10-08 15:55:28 +0000393
394 def _handle_text(self, msg):
395 # If the string has surrogates the original source was bytes, so
396 # just write it back out.
R. David Murray7372a072011-01-26 21:21:32 +0000397 if msg._payload is None:
398 return
R David Murray3edd22a2011-04-18 13:59:37 -0400399 if _has_surrogates(msg._payload) and not self.policy.must_be_7bit:
R. David Murraybdd2d932011-01-26 02:31:37 +0000400 self.write(msg._payload)
R. David Murray96fd54e2010-10-08 15:55:28 +0000401 else:
402 super(BytesGenerator,self)._handle_text(msg)
403
404 @classmethod
405 def _compile_re(cls, s, flags):
406 return re.compile(s.encode('ascii'), flags)
407
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000408
409
410_FMT = '[Non-text (%(type)s) part of message omitted, filename %(filename)s]'
411
412class DecodedGenerator(Generator):
R. David Murray70a99932010-10-01 20:38:33 +0000413 """Generates a text representation of a message.
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000414
415 Like the Generator base class, except that non-text parts are substituted
416 with a format string representing the part.
417 """
418 def __init__(self, outfp, mangle_from_=True, maxheaderlen=78, fmt=None):
419 """Like Generator.__init__() except that an additional optional
420 argument is allowed.
421
422 Walks through all subparts of a message. If the subpart is of main
423 type `text', then it prints the decoded payload of the subpart.
424
425 Otherwise, fmt is a format string that is used instead of the message
426 payload. fmt is expanded with the following keywords (in
427 %(keyword)s format):
428
429 type : Full MIME type of the non-text part
430 maintype : Main MIME type of the non-text part
431 subtype : Sub-MIME type of the non-text part
432 filename : Filename of the non-text part
433 description: Description associated with the non-text part
434 encoding : Content transfer encoding of the non-text part
435
436 The default value for fmt is None, meaning
437
438 [Non-text (%(type)s) part of message omitted, filename %(filename)s]
439 """
440 Generator.__init__(self, outfp, mangle_from_, maxheaderlen)
441 if fmt is None:
442 self._fmt = _FMT
443 else:
444 self._fmt = fmt
445
446 def _dispatch(self, msg):
447 for part in msg.walk():
448 maintype = part.get_content_maintype()
449 if maintype == 'text':
Guido van Rossum3172c5d2007-10-16 18:12:55 +0000450 print(part.get_payload(decode=False), file=self)
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000451 elif maintype == 'multipart':
452 # Just skip this
453 pass
454 else:
455 print(self._fmt % {
456 'type' : part.get_content_type(),
457 'maintype' : part.get_content_maintype(),
458 'subtype' : part.get_content_subtype(),
459 'filename' : part.get_filename('[no filename]'),
460 'description': part.get('Content-Description',
461 '[no description]'),
462 'encoding' : part.get('Content-Transfer-Encoding',
463 '[no encoding]'),
464 }, file=self)
465
466
467
R. David Murray96fd54e2010-10-08 15:55:28 +0000468# Helper used by Generator._make_boundary
Christian Heimesa37d4c62007-12-04 23:02:19 +0000469_width = len(repr(sys.maxsize-1))
Guido van Rossum8b3febe2007-08-30 01:15:14 +0000470_fmt = '%%0%dd' % _width
471
R. David Murray96fd54e2010-10-08 15:55:28 +0000472# Backward compatibility
473_make_boundary = Generator._make_boundary