316
316
else: # didn't see any content
320
def to_patch_lines(stanza, max_width=72):
321
"""Convert a stanza into RIO-Patch format lines.
323
RIO-Patch is a RIO variant designed to be e-mailed as part of a patch.
324
It resists common forms of damage such as newline conversion or the removal
325
of trailing whitespace, yet is also reasonably easy to read.
327
:param max_width: The maximum number of characters per physical line.
328
:return: a list of lines
331
max_rio_width = max_width - 4
333
for pline in stanza.to_lines():
334
for line in pline.split('\n')[:-1]:
335
line = re.sub('\\\\', '\\\\\\\\', line)
337
partline = line[:max_rio_width]
338
line = line[max_rio_width:]
339
if len(line) > 0 and line[0] != [' ']:
341
break_index = partline.rfind(' ', -20)
343
break_index = partline.rfind('-', -20)
346
break_index = partline.rfind('/', -20)
348
line = partline[break_index:] + line
349
partline = partline[:break_index]
352
partline = re.sub('\r', '\\\\r', partline)
356
elif re.search(' $', partline):
359
lines.append('# ' + partline + '\n')
365
def _patch_stanza_iter(line_iter):
370
return map[match.group(0)]
373
for line in line_iter:
374
if line.startswith('# '):
377
assert line.startswith('#')
379
if last_line is not None and len(line) > 2:
381
line = re.sub('\r', '', line)
382
line = re.sub('\\\\(.|\n)', mapget, line)
383
if last_line is None:
387
if last_line[-1] == '\n':
390
if last_line is not None:
394
def read_patch_stanza(line_iter):
395
"""Convert an iterable of RIO-Patch format lines into a Stanza.
397
RIO-Patch is a RIO variant designed to be e-mailed as part of a patch.
398
It resists common forms of damage such as newline conversion or the removal
399
of trailing whitespace, yet is also reasonably easy to read.
403
return read_stanza(_patch_stanza_iter(line_iter))