| 130 | # |
| 131 | |
| 132 | class TokenList(list): |
| 133 | |
| 134 | token_type = None |
| 135 | syntactic_break = True |
| 136 | ew_combine_allowed = True |
| 137 | |
| 138 | def __init__(self, *args, **kw): |
| 139 | super().__init__(*args, **kw) |
| 140 | self.defects = [] |
| 141 | |
| 142 | def __str__(self): |
| 143 | return ''.join(str(x) for x in self) |
| 144 | |
| 145 | def __repr__(self): |
| 146 | return '{}({})'.format(self.__class__.__name__, |
| 147 | super().__repr__()) |
| 148 | |
| 149 | @property |
| 150 | def value(self): |
| 151 | return ''.join(x.value for x in self if x.value) |
| 152 | |
| 153 | @property |
| 154 | def all_defects(self): |
| 155 | return sum((x.all_defects for x in self), self.defects) |
| 156 | |
| 157 | def startswith_fws(self): |
| 158 | return self[0].startswith_fws() |
| 159 | |
| 160 | @property |
| 161 | def as_ew_allowed(self): |
| 162 | """True if all top level tokens of this part may be RFC2047 encoded.""" |
| 163 | return all(part.as_ew_allowed for part in self) |
| 164 | |
| 165 | @property |
| 166 | def comments(self): |
| 167 | comments = [] |
| 168 | for token in self: |
| 169 | comments.extend(token.comments) |
| 170 | return comments |
| 171 | |
| 172 | def fold(self, *, policy): |
| 173 | return _refold_parse_tree(self, policy=policy) |
| 174 | |
| 175 | def pprint(self, indent=''): |
| 176 | print(self.ppstr(indent=indent)) |
| 177 | |
| 178 | def ppstr(self, indent=''): |
| 179 | return '\n'.join(self._pp(indent=indent)) |
| 180 | |
| 181 | def _pp(self, indent=''): |
| 182 | yield '{}{}/{}('.format( |
| 183 | indent, |
| 184 | self.__class__.__name__, |
| 185 | self.token_type) |
| 186 | for token in self: |
| 187 | if not hasattr(token, '_pp'): |
| 188 | yield (indent + ' !! invalid element in token ' |
| 189 | 'list: {!r}'.format(token)) |
no outgoing calls
no test coverage detected
searching dependent graphs…