本文整理匯總了Python中binascii.Incomplete方法的典型用法代碼示例。如果您正苦於以下問題:Python binascii.Incomplete方法的具體用法?Python binascii.Incomplete怎麽用?Python binascii.Incomplete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類binascii
的用法示例。
在下文中一共展示了binascii.Incomplete方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: read
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import Incomplete [as 別名]
def read(self, totalwtd):
"""Read at least wtd bytes (or until EOF)"""
decdata = ''
wtd = totalwtd
#
# The loop here is convoluted, since we don't really now how
# much to decode: there may be newlines in the incoming data.
while wtd > 0:
if self.eof: return decdata
wtd = ((wtd+2)//3)*4
data = self.ifp.read(wtd)
#
# Next problem: there may not be a complete number of
# bytes in what we pass to a2b. Solve by yet another
# loop.
#
while 1:
try:
decdatacur, self.eof = \
binascii.a2b_hqx(data)
break
except binascii.Incomplete:
pass
newdata = self.ifp.read(1)
if not newdata:
raise Error, \
'Premature EOF on binhex file'
data = data + newdata
decdata = decdata + decdatacur
wtd = totalwtd - len(decdata)
if not decdata and not self.eof:
raise Error, 'Premature EOF on binhex file'
return decdata
示例2: test_exceptions
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import Incomplete [as 別名]
def test_exceptions(self):
# Check module exceptions
self.assertTrue(issubclass(binascii.Error, Exception))
self.assertTrue(issubclass(binascii.Incomplete, Exception))
示例3: read
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import Incomplete [as 別名]
def read(self, totalwtd):
"""Read at least wtd bytes (or until EOF)"""
decdata = b''
wtd = totalwtd
#
# The loop here is convoluted, since we don't really now how
# much to decode: there may be newlines in the incoming data.
while wtd > 0:
if self.eof: return decdata
wtd = ((wtd + 2) // 3) * 4
data = self.ifp.read(wtd)
#
# Next problem: there may not be a complete number of
# bytes in what we pass to a2b. Solve by yet another
# loop.
#
while True:
try:
decdatacur, self.eof = binascii.a2b_hqx(data)
break
except binascii.Incomplete:
pass
newdata = self.ifp.read(1)
if not newdata:
raise Error('Premature EOF on binhex file')
data = data + newdata
decdata = decdata + decdatacur
wtd = totalwtd - len(decdata)
if not decdata and not self.eof:
raise Error('Premature EOF on binhex file')
return decdata
示例4: base64ToString
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import Incomplete [as 別名]
def base64ToString(s):
try:
return base64.decodestring(s)
except binascii.Error as e:
raise SyntaxError(e)
except binascii.Incomplete as e:
raise SyntaxError(e)
示例5: test_exceptions
# 需要導入模塊: import binascii [as 別名]
# 或者: from binascii import Incomplete [as 別名]
def test_exceptions(self):
# Check module exceptions
self.assert_(issubclass(binascii.Error, Exception))
self.assert_(issubclass(binascii.Incomplete, Exception))