Lines Matching refs:self

184     def __init__(self, s=None, charset=None,
217 self._charset = charset
218 self._continuation_ws = continuation_ws
219 self._chunks = []
221 self.append(s, charset, errors)
224 self._maxlinelen = maxlinelen
226 self._headerlen = 0
229 self._headerlen = len(header_name) + 2
231 def __str__(self):
233 self._normalize()
237 for string, charset in self._chunks:
249 hasspace = string and self._nonctext(string[0])
256 lastspace = string and self._nonctext(string[-1])
263 def __eq__(self, other):
267 return other == str(self)
269 def append(self, s, charset=None, errors='strict'):
291 charset = self._charset
310 self._chunks.append((s, charset))
312 def _nonctext(self, s):
317 def encode(self, splitchars=';, \t', maxlinelen=None, linesep='\n'):
350 self._normalize()
352 maxlinelen = self._maxlinelen
358 formatter = _ValueFormatter(self._headerlen, maxlinelen,
359 self._continuation_ws, splitchars)
362 for string, charset in self._chunks:
364 hasspace = string and self._nonctext(string[0])
370 lastspace = string and self._nonctext(string[-1])
381 formatter.feed(self._continuation_ws, ' ' + line.lstrip(),
389 if self._chunks:
397 def _normalize(self):
403 for string, charset in self._chunks:
413 self._chunks = chunks
419 def __init__(self, headerlen, maxlen, continuation_ws, splitchars):
420 self._maxlen = maxlen
421 self._continuation_ws = continuation_ws
422 self._continuation_ws_len = len(continuation_ws)
423 self._splitchars = splitchars
424 self._lines = []
425 self._current_line = _Accumulator(headerlen)
427 def _str(self, linesep):
428 self.newline()
429 return linesep.join(self._lines)
431 def __str__(self):
432 return self._str(NL)
434 def newline(self):
435 end_of_line = self._current_line.pop()
437 self._current_line.push(*end_of_line)
438 if len(self._current_line) > 0:
439 if self._current_line.is_onlyws() and self._lines:
440 self._lines[-1] += str(self._current_line)
442 self._lines.append(str(self._current_line))
443 self._current_line.reset()
445 def add_transition(self):
446 self._current_line.push(' ', '')
448 def feed(self, fws, string, charset):
455 self._ascii_split(fws, string, self._splitchars)
464 encoded_lines = charset.header_encode_lines(string, self._maxlengths())
473 self._append_chunk(fws, first_line)
479 self.newline()
480 self._current_line.push(self._continuation_ws, last_line)
483 self._lines.append(self._continuation_ws + line)
485 def _maxlengths(self):
487 yield self._maxlen - len(self._current_line)
489 yield self._maxlen - self._continuation_ws_len
491 def _ascii_split(self, fws, string, splitchars):
511 self._append_chunk(fws, part)
513 def _append_chunk(self, fws, string):
514 self._current_line.push(fws, string)
515 if len(self._current_line) > self._maxlen:
518 for ch in self._splitchars:
519 for i in range(self._current_line.part_count()-1, 0, -1):
521 fws = self._current_line[i][0]
524 prevpart = self._current_line[i-1][1]
531 fws, part = self._current_line.pop()
532 if self._current_line._initial_size > 0:
534 self.newline()
539 self._current_line.push(fws, part)
541 remainder = self._current_line.pop_from(i)
542 self._lines.append(str(self._current_line))
543 self._current_line.reset(remainder)
548 def __init__(self, initial_size=0):
549 self._initial_size = initial_size
552 def push(self, fws, string):
553 self.append((fws, string))
555 def pop_from(self, i=0):
556 popped = self[i:]
557 self[i:] = []
560 def pop(self):
561 if self.part_count()==0:
565 def __len__(self):
566 return sum((len(fws)+len(part) for fws, part in self),
567 self._initial_size)
569 def __str__(self):
571 for fws, part in self))
573 def reset(self, startval=None):
576 self[:] = startval
577 self._initial_size = 0
579 def is_onlyws(self):
580 return self._initial_size==0 and (not self or str(self).isspace())
582 def part_count(self):