本文整理汇总了Python中mimetools.Message.gettype方法的典型用法代码示例。如果您正苦于以下问题:Python Message.gettype方法的具体用法?Python Message.gettype怎么用?Python Message.gettype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mimetools.Message
的用法示例。
在下文中一共展示了Message.gettype方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _open_stream
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import gettype [as 别名]
def _open_stream(self):
self.conn.request("GET", self.path, headers=self.request_headers)
resp = self.conn.getresponse()
content_type = None
try:
if resp.status != 200 or resp.msg.getmaintype() != 'multipart':
raise ConnectionError(
u"Unexpected response: {resp.status}\n"
u"{resp.msg}\n{data}"
.format(data=resp.read(), **locals()))
log.debug("Opened stream\n%s", resp.msg)
boundary = resp.msg.getparam('boundary')
assert boundary
fp = ReadlineAdapter(resp)
while True:
sep = fp.readline().rstrip()
if not sep:
# XXX: instead of this should just read two bytes
# after the end of the data?
sep = fp.readline().rstrip()
if sep != b'--' + boundary:
if sep != b'--' + boundary + b'--':
raise StreamingError(u"Bad boundary %r" % sep)
break
msg = Message(fp, seekable=0)
content_length = int(msg['content-length'])
# XXX: impose maximum limit on content_length?
data = fp.read(content_length)
if content_type:
bad_type = msg.gettype() != content_type
else:
bad_type = msg.getmaintype() != 'image'
content_type = msg.gettype()
if bad_type:
raise StreamingError(
u"Unexpected content-type\n{msg}\n{data}"
.format(**locals()))
log.debug("Got part\n%s", msg)
yield VideoFrame(data, msg.gettype())
finally:
resp.close()
示例2: _extractContentType
# 需要导入模块: from mimetools import Message [as 别名]
# 或者: from mimetools.Message import gettype [as 别名]
def _extractContentType(self,doc,docDictionary):
header = Message(StringIO(docDictionary["DOCHDR"]))
return header.gettype()