No subject
ha bo
hasna1980_14 at hotmail.com
Fri Apr 11 06:10:33 EDT 2008
hi i use this programme in my application django:
import structMASK_CCITT = 0x1021 # CRC-CCITT mask (ISO 3309, used in X25, HDLC)MASK_CRC16 = 0xA001 # CRC16 mask (used in ARC files)def updcrc(crc, data, mask=MASK_CRC16): data_length = len(data) unpackFormat = '%db' % data_length unpackedData = struct.unpack(unpackFormat, data) for char in data: c = ord(char) c = c << 8 for j in xrange(8): if (crc ^ c) & 0x8000: crc = (crc << 1) ^ mask else: crc = crc << 1 c = c << 1 return crc & 0xffff
and i call this function in other function in my view:
def encodekey(var, expires=None, user='', trusted=False): import random, base64 import updcrc key = "%02X" % len(var) + var key += "%02X" % len(user) + user if expires is not None: key += expires.strftime('%Y%m%d%H%M') else: year = random.choice(range(2000,2100)) month = 23 day = random.choice(range(1,32)) hour = random.choice(range(1,25)) minute = random.choice(range(1,60)) key += "%04d%02d%02d%02d%02d" % (year, month, day, hour, minute) if trusted: checksum = updcrc(42, key) else: checksum = updcrc(0, key) key += "%04X" % checksum return base64.b64encode(key)
but it give me this error:
unpack requires a string argument of length 31
someone can help me
_________________________________________________________________
Lancez des recherches en toute sécurité depuis n'importe quelle page Web. Téléchargez GRATUITEMENT Windows Live Toolbar aujourd'hui !
http://toolbar.live.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080411/42370a9c/attachment-0001.html>
More information about the Python-list
mailing list