當前位置: 首頁>>代碼示例>>Python>>正文


Python errors.FirstHeaderLineIsContinuationDefect方法代碼示例

本文整理匯總了Python中email.errors.FirstHeaderLineIsContinuationDefect方法的典型用法代碼示例。如果您正苦於以下問題:Python errors.FirstHeaderLineIsContinuationDefect方法的具體用法?Python errors.FirstHeaderLineIsContinuationDefect怎麽用?Python errors.FirstHeaderLineIsContinuationDefect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email.errors的用法示例。


在下文中一共展示了errors.FirstHeaderLineIsContinuationDefect方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_first_line_is_continuation_header

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import FirstHeaderLineIsContinuationDefect [as 別名]
def test_first_line_is_continuation_header(self):
        eq = self.assertEqual
        m = ' Line 1\nLine 2\nLine 3'
        msg = email.message_from_string(m)
        eq(msg.keys(), [])
        eq(msg.get_payload(), 'Line 2\nLine 3')
        eq(len(msg.defects), 1)
        self.assertIsInstance(msg.defects[0],
                              errors.FirstHeaderLineIsContinuationDefect)
        eq(msg.defects[0].line, ' Line 1\n')



# Test RFC 2047 header encoding and decoding 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_email_renamed.py

示例2: test_first_line_is_continuation_header

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import FirstHeaderLineIsContinuationDefect [as 別名]
def test_first_line_is_continuation_header(self):
        eq = self.assertEqual
        m = ' Line 1\nLine 2\nLine 3'
        msg = email.message_from_string(m)
        eq(msg.keys(), [])
        eq(msg.get_payload(), 'Line 2\nLine 3')
        eq(len(msg.defects), 1)
        self.assertTrue(isinstance(msg.defects[0],
                                   errors.FirstHeaderLineIsContinuationDefect))
        eq(msg.defects[0].line, ' Line 1\n')



# Test RFC 2047 header encoding and decoding 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:16,代碼來源:test_email_renamed.py

示例3: test_first_line_is_continuation_header

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import FirstHeaderLineIsContinuationDefect [as 別名]
def test_first_line_is_continuation_header(self):
        with self._raise_point(errors.FirstHeaderLineIsContinuationDefect):
            msg = self._str_msg(' Line 1\nSubject: test\n\nbody')
        if self.raise_expected: return
        self.assertEqual(msg.keys(), ['Subject'])
        self.assertEqual(msg.get_payload(), 'body')
        self.assertEqual(len(self.get_defects(msg)), 1)
        self.assertDefectsEqual(self.get_defects(msg),
                                 [errors.FirstHeaderLineIsContinuationDefect])
        self.assertEqual(self.get_defects(msg)[0].line, ' Line 1\n') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:12,代碼來源:test_defect_handling.py

示例4: test_first_line_is_continuation_header

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import FirstHeaderLineIsContinuationDefect [as 別名]
def test_first_line_is_continuation_header(self):
        eq = self.assertEqual
        m = ' Line 1\nSubject: test\n\nbody'
        msg = email.message_from_string(m)
        eq(msg.keys(), ['Subject'])
        eq(msg.get_payload(), 'body')
        eq(len(msg.defects), 1)
        self.assertDefectsEqual(msg.defects,
                                 [errors.FirstHeaderLineIsContinuationDefect])
        eq(msg.defects[0].line, ' Line 1\n')

    # test_defect_handling 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:14,代碼來源:test_email.py

示例5: test_first_line_is_continuation_header

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import FirstHeaderLineIsContinuationDefect [as 別名]
def test_first_line_is_continuation_header(self):
        eq = self.assertEqual
        m = ' Line 1\nLine 2\nLine 3'
        msg = email.message_from_string(m)
        eq(msg.keys(), [])
        eq(msg.get_payload(), 'Line 2\nLine 3')
        eq(len(msg.defects), 1)
        self.failUnless(isinstance(msg.defects[0],
                                   errors.FirstHeaderLineIsContinuationDefect))
        eq(msg.defects[0].line, ' Line 1\n')



# Test RFC 2047 header encoding and decoding 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:16,代碼來源:test_email_renamed.py

示例6: _parse_headers

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import FirstHeaderLineIsContinuationDefect [as 別名]
def _parse_headers(self, lines):
        # Passed a list of lines that make up the headers for the current msg
        lastheader = ''
        lastvalue = []
        for lineno, line in enumerate(lines):
            # Check for continuation
            if line[0] in ' \t':
                if not lastheader:
                    # The first line of the headers was a continuation.  This
                    # is illegal, so let's note the defect, store the illegal
                    # line, and ignore it for purposes of headers.
                    defect = errors.FirstHeaderLineIsContinuationDefect(line)
                    self._cur.defects.append(defect)
                    continue
                lastvalue.append(line)
                continue
            if lastheader:
                # XXX reconsider the joining of folded lines
                lhdr = EMPTYSTRING.join(lastvalue)[:-1].rstrip('\r\n')
                self._cur[lastheader] = lhdr
                lastheader, lastvalue = '', []
            # Check for envelope header, i.e. unix-from
            if line.startswith('From '):
                if lineno == 0:
                    # Strip off the trailing newline
                    mo = NLCRE_eol.search(line)
                    if mo:
                        line = line[:-len(mo.group(0))]
                    self._cur.set_unixfrom(line)
                    continue
                elif lineno == len(lines) - 1:
                    # Something looking like a unix-from at the end - it's
                    # probably the first line of the body, so push back the
                    # line and stop.
                    self._input.unreadline(line)
                    return
                else:
                    # Weirdly placed unix-from line.  Note this as a defect
                    # and ignore it.
                    defect = errors.MisplacedEnvelopeHeaderDefect(line)
                    self._cur.defects.append(defect)
                    continue
            # Split the line on the colon separating field name from value.
            i = line.find(':')
            if i < 0:
                defect = errors.MalformedHeaderDefect(line)
                self._cur.defects.append(defect)
                continue
            lastheader = line[:i]
            lastvalue = [line[i+1:].lstrip()]
        # Done with all the lines, so handle the last header.
        if lastheader:
            # XXX reconsider the joining of folded lines
            self._cur[lastheader] = EMPTYSTRING.join(lastvalue).rstrip('\r\n') 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:56,代碼來源:feedparser.py

示例7: _parse_headers

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import FirstHeaderLineIsContinuationDefect [as 別名]
def _parse_headers(self, lines):
        # Passed a list of lines that make up the headers for the current msg
        lastheader = ''
        lastvalue = []
        for lineno, line in enumerate(lines):
            # Check for continuation
            if line[0] in ' \t':
                if not lastheader:
                    # The first line of the headers was a continuation.  This
                    # is illegal, so let's note the defect, store the illegal
                    # line, and ignore it for purposes of headers.
                    defect = errors.FirstHeaderLineIsContinuationDefect(line)
                    self.policy.handle_defect(self._cur, defect)
                    continue
                lastvalue.append(line)
                continue
            if lastheader:
                self._cur.set_raw(*self.policy.header_source_parse(lastvalue))
                lastheader, lastvalue = '', []
            # Check for envelope header, i.e. unix-from
            if line.startswith('From '):
                if lineno == 0:
                    # Strip off the trailing newline
                    mo = NLCRE_eol.search(line)
                    if mo:
                        line = line[:-len(mo.group(0))]
                    self._cur.set_unixfrom(line)
                    continue
                elif lineno == len(lines) - 1:
                    # Something looking like a unix-from at the end - it's
                    # probably the first line of the body, so push back the
                    # line and stop.
                    self._input.unreadline(line)
                    return
                else:
                    # Weirdly placed unix-from line.  Note this as a defect
                    # and ignore it.
                    defect = errors.MisplacedEnvelopeHeaderDefect(line)
                    self._cur.defects.append(defect)
                    continue
            # Split the line on the colon separating field name from value.
            # There will always be a colon, because if there wasn't the part of
            # the parser that calls us would have started parsing the body.
            i = line.find(':')

            # If the colon is on the start of the line the header is clearly
            # malformed, but we might be able to salvage the rest of the
            # message. Track the error but keep going.
            if i == 0:
                defect = errors.InvalidHeaderDefect("Missing header name.")
                self._cur.defects.append(defect)
                continue

            assert i>0, "_parse_headers fed line with no : and no leading WS"
            lastheader = line[:i]
            lastvalue = [line]
        # Done with all the lines, so handle the last header.
        if lastheader:
            self._cur.set_raw(*self.policy.header_source_parse(lastvalue)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:61,代碼來源:feedparser.py


注:本文中的email.errors.FirstHeaderLineIsContinuationDefect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。