help

2008-05-30 Thread ha bo
hi 
i wanna paginate my table (x lines per pages),the size of my table is changing 
according to the user.
i wanna know if paginator.py can help me ,if yes how?
some one can help me 
ps:i use django
thank you 

_
Découvrez Windows Live Spaces et créez votre site Web perso en quelques clics !
http://spaces.live.com/signup.aspx--
http://mail.python.org/mailman/listinfo/python-list

[no subject]

2008-04-11 Thread ha bo
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 << 8for j in 
xrange(8):if (crc ^ c) & 0x8000:crc = (crc 
<< 1) ^ maskelse:crc = crc << 1 
   c = c << 1 return crc & 0x


and i call this function in other function in my view:


def encodekey(var, expires=None, user='', trusted=False):  import 
random, base64import updcrckey = "%02X" % len(var) + var
key += "%02X" % len(user) + userif expires is not None:key 
+= expires.strftime('%Y%m%d%H%M')else:year = 
random.choice(range(2000,2100))month = 23day = 
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" % checksumreturn 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-- 
http://mail.python.org/mailman/listinfo/python-list

RE: unpack

2008-04-11 Thread ha bo
thank you i did find solution i did have just change: 

 unpackedData = struct.unpack(unpackFormat, data)  to

 unpackedData = struct.unpack(unpackFormat, data.decode('string_escape'))




From: [EMAIL PROTECTED]
Subject: Python-list Digest, Vol 55, Issue 179
To: python-list@python.org
Date: Fri, 11 Apr 2008 15:50:04 +0200

Send Python-list mailing list submissions to
python-list@python.org
 
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.python.org/mailman/listinfo/python-list
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]
 
You can reach the person managing the list at
[EMAIL PROTECTED]
 
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-list digest..."
--Pièce jointe du message transmise--
From: [EMAIL PROTECTED]
To: python-list@python.org
Date: Fri, 11 Apr 2008 05:58:46 -0700
Subject: Re: Rounding a number to nearest even

On Apr 11, 2:14 pm, bdsatish <[EMAIL PROTECTED]> wrote:
> The built-in function round( ) will always "round up", that is 1.5 is
> rounded to 2.0 and 2.5 is rounded to 3.0.
>
> If I want to round to the nearest even, that is
>
> my_round(1.5) = 2# As expected
> my_round(2.5) = 2# Not 3, which is an odd num
>
> I'm interested in rounding numbers of the form "x.5" depending upon
> whether x is odd or even. Any idea about how to implement it ?
 
def even_round(x):
if x % 1 == .5 and not (int(x) % 2):
return float(int(x))
else:
return round(x)
 
nums = [ 3.2, 3.6, 3.5, 2.5, -.5, -1.5, -1.3, -1.8, -2.5 ]
for num in nums:
print num, '->', even_round(num)
 
3.2 -> 3.0
3.6 -> 4.0
3.5 -> 4.0
2.5 -> 2.0
-0.5 -> 0.0
-1.5 -> -2.0
-1.3 -> -1.0
-1.8 -> -2.0
-2.5 -> -2.0
 
 
--Pièce jointe du message transmise--
From: [EMAIL PROTECTED]
To: python-list@python.org
Date: Fri, 11 Apr 2008 09:07:42 -0400
Subject: Re: (unknown)

ha bo wrote:
> hi i use this programme in my application django:
> import struct
> MASK_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 & 0x
> 
> 
> 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
> 
Next time you report an error, please include the whole traceback, not 
just the exception message. That information is included for a reason.
 
You might also want to print out the value of data in your updcrc 
function, since that is where the problem is occurring.
 
Finally I might point out there is little point to the struct.unpack 
since you don't use its result, but I am guessing this is because your 
algorithm is currently in transition.
 
regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/
 
 
--Pièce jointe du message transmise--
From: [EMAIL PROTECTED]
CC: python-list@python.org
To: [EMAIL PROTECTED]
Date: Fri, 11 Apr 2008 08:36:02 -0500
Subject: Re: String Literal to Blob

Nope. Do not see it. My ugly stupid way works. I guess I will just proceed with 
that and write my howto accordingly.
Victor


On Thu, Apr 10