Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions | Private Attributes
email.header._ValueFormatter Class Reference

List of all members.

Public Member Functions

def __init__
def __str__
def newline
def add_transition
def feed

Private Member Functions

def _str
def _maxlengths
def _ascii_split
def _append_chunk

Private Attributes

 _maxlen
 _continuation_ws
 _continuation_ws_len
 _splitchars
 _lines
 _current_line

Detailed Description

Definition at line 376 of file header.py.


Constructor & Destructor Documentation

def email.header._ValueFormatter.__init__ (   self,
  headerlen,
  maxlen,
  continuation_ws,
  splitchars 
)

Definition at line 377 of file header.py.

00377 
00378     def __init__(self, headerlen, maxlen, continuation_ws, splitchars):
00379         self._maxlen = maxlen
00380         self._continuation_ws = continuation_ws
00381         self._continuation_ws_len = len(continuation_ws)
00382         self._splitchars = splitchars
00383         self._lines = []
00384         self._current_line = _Accumulator(headerlen)

Here is the caller graph for this function:


Member Function Documentation

Definition at line 389 of file header.py.

00389 
00390     def __str__(self):
00391         return self._str(NL)

Here is the call graph for this function:

def email.header._ValueFormatter._append_chunk (   self,
  fws,
  string 
) [private]

Definition at line 471 of file header.py.

00471 
00472     def _append_chunk(self, fws, string):
00473         self._current_line.push(fws, string)
00474         if len(self._current_line) > self._maxlen:
00475             # Find the best split point, working backward from the end.
00476             # There might be none, on a long first line.
00477             for ch in self._splitchars:
00478                 for i in range(self._current_line.part_count()-1, 0, -1):
00479                     if ch.isspace():
00480                         fws = self._current_line[i][0]
00481                         if fws and fws[0]==ch:
00482                             break
00483                     prevpart = self._current_line[i-1][1]
00484                     if prevpart and prevpart[-1]==ch:
00485                         break
00486                 else:
00487                     continue
00488                 break
00489             else:
00490                 fws, part = self._current_line.pop()
00491                 if self._current_line._initial_size > 0:
00492                     # There will be a header, so leave it on a line by itself.
00493                     self.newline()
00494                     if not fws:
00495                         # We don't use continuation_ws here because the whitespace
00496                         # after a header should always be a space.
00497                         fws = ' '
00498                 self._current_line.push(fws, part)
00499                 return
00500             remainder = self._current_line.pop_from(i)
00501             self._lines.append(str(self._current_line))
00502             self._current_line.reset(remainder)
00503 

Here is the call graph for this function:

Here is the caller graph for this function:

def email.header._ValueFormatter._ascii_split (   self,
  fws,
  string,
  splitchars 
) [private]

Definition at line 449 of file header.py.

00449 
00450     def _ascii_split(self, fws, string, splitchars):
00451         # The RFC 2822 header folding algorithm is simple in principle but
00452         # complex in practice.  Lines may be folded any place where "folding
00453         # white space" appears by inserting a linesep character in front of the
00454         # FWS.  The complication is that not all spaces or tabs qualify as FWS,
00455         # and we are also supposed to prefer to break at "higher level
00456         # syntactic breaks".  We can't do either of these without intimate
00457         # knowledge of the structure of structured headers, which we don't have
00458         # here.  So the best we can do here is prefer to break at the specified
00459         # splitchars, and hope that we don't choose any spaces or tabs that
00460         # aren't legal FWS.  (This is at least better than the old algorithm,
00461         # where we would sometimes *introduce* FWS after a splitchar, or the
00462         # algorithm before that, where we would turn all white space runs into
00463         # single spaces or tabs.)
00464         parts = re.split("(["+FWS+"]+)", fws+string)
00465         if parts[0]:
00466             parts[:0] = ['']
00467         else:
00468             parts.pop(0)
00469         for fws, part in zip(*[iter(parts)]*2):
00470             self._append_chunk(fws, part)

Here is the call graph for this function:

Here is the caller graph for this function:

def email.header._ValueFormatter._maxlengths (   self) [private]

Definition at line 443 of file header.py.

00443 
00444     def _maxlengths(self):
00445         # The first line's length.
00446         yield self._maxlen - len(self._current_line)
00447         while True:
00448             yield self._maxlen - self._continuation_ws_len

Here is the caller graph for this function:

def email.header._ValueFormatter._str (   self,
  linesep 
) [private]

Definition at line 385 of file header.py.

00385 
00386     def _str(self, linesep):
00387         self.newline()
00388         return linesep.join(self._lines)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 403 of file header.py.

00403 
00404     def add_transition(self):
00405         self._current_line.push(' ', '')

def email.header._ValueFormatter.feed (   self,
  fws,
  string,
  charset 
)

Definition at line 406 of file header.py.

00406 
00407     def feed(self, fws, string, charset):
00408         # If the charset has no header encoding (i.e. it is an ASCII encoding)
00409         # then we must split the header at the "highest level syntactic break"
00410         # possible. Note that we don't have a lot of smarts about field
00411         # syntax; we just try to break on semi-colons, then commas, then
00412         # whitespace.  Eventually, this should be pluggable.
00413         if charset.header_encoding is None:
00414             self._ascii_split(fws, string, self._splitchars)
00415             return
00416         # Otherwise, we're doing either a Base64 or a quoted-printable
00417         # encoding which means we don't need to split the line on syntactic
00418         # breaks.  We can basically just find enough characters to fit on the
00419         # current line, minus the RFC 2047 chrome.  What makes this trickier
00420         # though is that we have to split at octet boundaries, not character
00421         # boundaries but it's only safe to split at character boundaries so at
00422         # best we can only get close.
00423         encoded_lines = charset.header_encode_lines(string, self._maxlengths())
00424         # The first element extends the current line, but if it's None then
00425         # nothing more fit on the current line so start a new line.
00426         try:
00427             first_line = encoded_lines.pop(0)
00428         except IndexError:
00429             # There are no encoded lines, so we're done.
00430             return
00431         if first_line is not None:
00432             self._append_chunk(fws, first_line)
00433         try:
00434             last_line = encoded_lines.pop()
00435         except IndexError:
00436             # There was only one line.
00437             return
00438         self.newline()
00439         self._current_line.push(self._continuation_ws, last_line)
00440         # Everything else are full lines in themselves.
00441         for line in encoded_lines:
00442             self._lines.append(self._continuation_ws + line)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 392 of file header.py.

00392 
00393     def newline(self):
00394         end_of_line = self._current_line.pop()
00395         if end_of_line != (' ', ''):
00396             self._current_line.push(*end_of_line)
00397         if len(self._current_line) > 0:
00398             if self._current_line.is_onlyws():
00399                 self._lines[-1] += str(self._current_line)
00400             else:
00401                 self._lines.append(str(self._current_line))
00402         self._current_line.reset()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 379 of file header.py.

Definition at line 380 of file header.py.

Definition at line 383 of file header.py.

Definition at line 382 of file header.py.

Definition at line 378 of file header.py.

Definition at line 381 of file header.py.


The documentation for this class was generated from the following file: