Changeset 617

Show
Ignore:
Timestamp:
11/06/06 08:11:06
Author:
crchemist
Message:

Clean up code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qPloneCaptchas/trunk/tests/testCaptchaWidget.py

    r616 r617  
    7979        self.assert_(not match_obj) 
    8080     
    81     def testSubmitExpiredCaptcha(self): 
    82         pass 
    83         """ 
    84         hashkey = self.portal.getCaptcha() 
    85         key = getWord(int(parseKey(decrypt(self.captcha_key,hashkey))['key'])) 
    86         parameters = 'form.submitted=1&Creator=test_user&key=%s'%key 
    87         path = '%s/discussion_reply_form?%s'%(self.absolute_url, parameters) 
    88         extra = {'hashkey': hashkey, 
    89                  'subject': 'testing', 
    90                  'body_text': 'Text in Comment', 
    91                  'discussion_reply:method': 'Save'} 
    92                  
    93         from DateTime import DateTime 
    94         last = repr(DateTime().timeTime()) 
    95         import time 
    96         DateTime._t = time.time() + 3601.0 
    97         raise repr(DateTime().timeTime())+' '+last 
    98                  
    99         response = self.publish(path, self.basic_auth, extra=extra, request_method='GET').getBody() 
    100         DateTime._t = time.time() 
    101         patt = re.compile(".*?Comment\+added") 
    102         match_obj = patt.match(response) 
    103         self.assert_(match_obj) 
    104         """ 
    105  
    10681class TestInstallation(PloneTestCase.FunctionalTestCase): 
    10782 
  • qPloneCaptchas/trunk/utils.py

    r616 r617  
    9191 
    9292def encrypt(key, s): 
    93     return toHex(Crypto.new(key).encrypt(s)
     93    return Crypto.new(key).encrypt(s).encode("hex"
    9494     
    9595def decrypt(key, s): 
    96     return Crypto.new(key).decrypt(toStr(s)) 
     96    return Crypto.new(key).decrypt(s.decode("hex")) 
    9797 
    9898def parseKey(s): 
     
    103103    context.portal_captchas.new(key) 
    104104 
    105 def toHex(s): 
    106     lst = [] 
    107     for ch in s: 
    108         hv = hex(ord(ch)).replace('0x', '') 
    109         if len(hv) == 1: 
    110             hv = '0'+hv 
    111         lst.append(hv) 
    112      
    113     return reduce(lambda x,y:x+y, lst) 
    114  
    115 def toStr(s): 
    116     return s and chr(atoi(s[:2], base=16)) + toStr(s[2:]) or ''