下面的代码中那句 Skip unix From name time lines
是啥意思?HTTP头部怎么会出现 From
开头的行?
PS:因为 seekable
输入是0,所以我删掉了一些代码,源码位于 /usr/lib/python2.7/rfc822.py
class Message:
"""Represents a single RFC 2822-compliant message."""
def __init__(self, fp, seekable = 1):
self.fp = fp
self.seekable = seekable
self.startofheaders = None
self.startofbody = None
self.readheaders()
def readheaders(self):
self.dict = {}
self.unixfrom = ''
self.headers = lst = []
self.status = ''
headerseen = ""
firstline = 1
startofline = unread = tell = None
if hasattr(self.fp, 'unread'):
unread = self.fp.unread
while 1:
line = self.fp.readline()
if not line:
self.status = 'EOF in headers'
break
# 下面这行啥意思?
# Skip unix From name time lines
if firstline and line.startswith('From '):
self.unixfrom = self.unixfrom + line
continue
firstline = 0
if headerseen and line[0] in ' \t':
# It's a continuation line.
lst.append(line)
x = (self.dict[headerseen] + "\n " + line.strip())
self.dict[headerseen] = x.strip()
continue
elif self.iscomment(line):
# It's a comment. Ignore it.
continue
elif self.islast(line):
# Note! No pushback here! The delimiter line gets eaten.
break
headerseen = self.isheader(line)
if headerseen:
# It's a legal header line, save it.
lst.append(line)
self.dict[headerseen] = line[len(headerseen)+1:].strip()
continue
elif headerseen is not None:
# An empty header name. These aren't allowed in HTTP, but it's
# probably a benign mistake. Don't add the header, just keep
# going.
continue
else:
# It's not a header line; throw it back and stop here.
if not self.dict:
self.status = 'No headers'
else:
self.status = 'Non-header line where header expected'
# Try to undo the read.
if unread:
unread(line)
elif tell:
self.fp.seek(startofline)
else:
self.status = self.status + '; bad seek'
break
1
VicYu 2015-07-22 19:05:09 +08:00 1
|
2
loggerhead OP @VicYu 不是同一个东西吧
|
3
VicYu 2015-07-22 19:29:05 +08:00
|
4
VicYu 2015-07-22 19:31:10 +08:00
|
5
julyclyde 2015-07-22 21:31:13 +08:00 1
都写了是rfc822
http是rfc2616 |
6
loggerhead OP |
7
julyclyde 2015-07-23 17:04:00 +08:00
@loggerhead header那几行的格式倒是差不多的。不过From 开头这个,在邮件和http里很不同
|