56 mimetypes = ["multipart/mixed", |
56 mimetypes = ["multipart/mixed", |
57 "multipart/related", |
57 "multipart/related", |
58 "multipart/alternative"] |
58 "multipart/alternative"] |
59 |
59 |
60 def __init__(self, **options): |
60 def __init__(self, **options): |
61 super(MIMELexer, self).__init__(**options) |
61 super().__init__(**options) |
62 self.boundary = options.get("Multipart-Boundary") |
62 self.boundary = options.get("Multipart-Boundary") |
63 self.content_transfer_encoding = options.get("Content_Transfer_Encoding") |
63 self.content_transfer_encoding = options.get("Content_Transfer_Encoding") |
64 self.content_type = options.get("Content_Type", "text/plain") |
64 self.content_type = options.get("Content_Type", "text/plain") |
65 self.max_nested_level = get_int_opt(options, "MIME-max-level", -1) |
65 self.max_nested_level = get_int_opt(options, "MIME-max-level", -1) |
66 |
66 |
98 pos_body_start = match.start() |
98 pos_body_start = match.start() |
99 entire_body = match.group() |
99 entire_body = match.group() |
100 |
100 |
101 # skip first newline |
101 # skip first newline |
102 if entire_body[0] == '\n': |
102 if entire_body[0] == '\n': |
103 yield pos_body_start, Text.Whitespace, u'\n' |
103 yield pos_body_start, Text.Whitespace, '\n' |
104 pos_body_start = pos_body_start + 1 |
104 pos_body_start = pos_body_start + 1 |
105 entire_body = entire_body[1:] |
105 entire_body = entire_body[1:] |
106 |
106 |
107 # if it is not a mulitpart |
107 # if it is not a mulitpart |
108 if not self.content_type.startswith("multipart") or not self.boundary: |
108 if not self.content_type.startswith("multipart") or not self.boundary: |
174 self.content_type = match.group(1) |
174 self.content_type = match.group(1) |
175 |
175 |
176 prefix_len = match.start(1) - match.start(0) |
176 prefix_len = match.start(1) - match.start(0) |
177 yield match.start(0), Text.Whitespace, match.group(0)[:prefix_len] |
177 yield match.start(0), Text.Whitespace, match.group(0)[:prefix_len] |
178 yield match.start(1), Name.Label, match.group(2) |
178 yield match.start(1), Name.Label, match.group(2) |
179 yield match.end(2), String.Delimiter, u"/" |
179 yield match.end(2), String.Delimiter, '/' |
180 yield match.start(3), Name.Label, match.group(3) |
180 yield match.start(3), Name.Label, match.group(3) |
181 |
181 |
182 def get_content_type_subtokens(self, match): |
182 def get_content_type_subtokens(self, match): |
183 yield match.start(1), Text, match.group(1) |
183 yield match.start(1), Text, match.group(1) |
184 yield match.start(2), Text.Whitespace, match.group(2) |
184 yield match.start(2), Text.Whitespace, match.group(2) |