Changeset 3121 in products


Ignore:
Timestamp:
Apr 15, 2011 1:00:00 PM (13 years ago)
Author:
vmaksymiv
Message:

pep8 fixes

Location:
quintagroup.formlib.captcha/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/example.py

    r2810 r3121  
    88from quintagroup.formlib.captcha import Captcha 
    99 
     10 
    1011# Define CaptchaFormlibForm form schema 
    11  
    1212class ICaptchaFormlibFormSchema(Interface): 
    1313    label = TextLine(title=u'Label', 
    1414                     required=False) 
    1515    captcha = Captcha(title=u'Type the code') 
    16        
     16 
     17 
    1718# Create adapter for any object to ICaptchaFormlibFormSchema 
    1819# schema interface 
    19  
    2020class CaptchaFormlibFormAdapter(object): 
    2121    implements(ICaptchaFormlibFormSchema) 
     
    2626    label = u'' 
    2727    captcha = None 
    28        
     28 
     29 
    2930# And at the last define the CaptchaFormlibForm form 
    30  
    3131class CaptchaFormlibForm(EditForm): 
    3232    form_fields = FormFields(ICaptchaFormlibFormSchema) 
  • quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/field.py

    r2210 r3121  
    33from interfaces import ICaptcha 
    44 
     5 
    56class Captcha(ASCIILine): 
    67    implements(ICaptcha) 
  • quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/interfaces.py

    r2210 r3121  
    11from zope.schema.interfaces import IASCIILine 
     2 
    23 
    34class ICaptcha(IASCIILine): 
  • quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/tests/test_doctests.py

    r2806 r3121  
    1515from quintagroup.captcha.core.tests.testWidget import addTestLayer 
    1616 
     17 
    1718class FormlibCaptchaLayer(PloneSite): 
    1819    @classmethod 
     
    2930    def tearDown(cls): 
    3031        pass 
    31      
    32 ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default',]) 
     32 
     33ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default', ]) 
     34 
    3335 
    3436class FormlibCaptchaTestCase(ptc.FunctionalTestCase): 
     
    4446        self.hashkey = self.portal.getCaptcha() 
    4547        decrypted = decrypt(captcha_key, self.hashkey) 
    46         self.captcha_word = getWord(int(parseKey(decrypted)['key'])-1 ) 
     48        self.captcha_word = getWord(int(parseKey(decrypted)['key']) - 1) 
    4749 
    4850 
     
    5456            'README.txt', package='quintagroup.formlib.captcha', 
    5557            test_class=FormlibCaptchaTestCase, 
    56             optionflags=doctest.REPORT_ONLY_FIRST_FAILURE | doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS), 
    57              
     58            optionflags=doctest.REPORT_ONLY_FIRST_FAILURE | \ 
     59                        doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS), 
    5860        ]) 
    5961 
  • quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/tests/test_unittests.py

    r2800 r3121  
    2121from quintagroup.formlib.captcha import CaptchaWidget 
    2222 
     23 
    2324@onsetup 
    2425def setup_product(): 
     
    3132 
    3233setup_product() 
    33 ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default',]) 
     34ptc.setupPloneSite(extension_profiles=['quintagroup.captcha.core:default', ]) 
    3435 
    3536 
     
    7980        FIELDTAG = '<input\s+[^>]*type=\"text\"\s*[^>]*>' 
    8081        self.assertEqual(re.search(FIELDTAG, self.html) is not None, True) 
    81          
     82 
    8283 
    8384class TestCaptchaWidgetToField(ptc.PloneTestCase): 
     
    101102    def testSubmitRightCaptcha(self): 
    102103        decrypted = decrypt(self.captcha_key, self.hashkey) 
    103         key = getWord(int(parseKey(decrypted)['key'])-1 ) 
     104        key = getWord(int(parseKey(decrypted)['key']) - 1) 
    104105        try: 
    105106            res = self.widget._toFieldValue(key) 
    106107        except ConversionError, e: 
    107             self.fail("Rised unexpected %s error on right captcha submit" % e.doc()) 
     108            self.fail("Rised unexpected %s error on right captcha submit" % \ 
     109                      e.doc()) 
    108110        else: 
    109111            self.assertEqual(res, key) 
    110          
     112 
    111113    def testSubmitWrongCaptcha(self): 
    112114        try: 
     
    119121    def testSubmitRightCaptchaTwice(self): 
    120122        decrypted = decrypt(self.captcha_key, self.hashkey) 
    121         key = getWord(int(parseKey(decrypted)['key'])-1 ) 
     123        key = getWord(int(parseKey(decrypted)['key']) - 1) 
    122124        self.widget._toFieldValue(key) 
    123125        try: 
  • quintagroup.formlib.captcha/trunk/quintagroup/formlib/captcha/widget.py

    r3098 r3121  
    2323logger = logging.getLogger('quintagroup.formlib.captcha') 
    2424 
     25 
    2526class CaptchaWidget(ASCIIWidget): 
    2627 
     
    4243 
    4344        site = self.get_site() 
    44         portal_url = getToolByName(site , 'portal_url')() 
     45        portal_url = getToolByName(site, 'portal_url')() 
    4546        key = site.getCaptcha() 
    4647 
     
    5253        return u"""<input type="hidden" value="%s" name="%shashkey" /> 
    5354                   %s 
    54                    <img src="%s/getCaptchaImage/%s" alt="Enter the word"/>""" % (key, 
    55                                                                                  prefix, 
    56                                                                                  renderElement(self.tag, **kwargs), 
    57                                                                                  portal_url, 
    58                                                                                  key) 
    59           
     55                   <img src="%s/getCaptchaImage/%s" 
     56                        alt="Enter the word"/>""" % (key, 
     57                                                     prefix, 
     58                                                     renderElement(self.tag, 
     59                                                                   **kwargs), 
     60                                                     portal_url, 
     61                                                     key) 
     62 
    6063    def _toFieldValue(self, input): 
    6164        # Verify the user input against the captcha 
     
    6467        site = self.get_site() 
    6568        captcha_type = site.getCaptchaType() 
    66          
     69 
    6770        # validate captcha input 
    6871        if input and captcha_type in ['static', 'dynamic']: 
     
    7275            else: 
    7376                prefix = '' 
    74              
     77 
    7578            hashkey = self.request.get('%shashkey' % prefix, '') 
    7679            decrypted_key = decrypt(site.captcha_key, hashkey) 
    7780            parsed_key = parseKey(decrypted_key) 
    78              
     81 
    7982            index = parsed_key['key'] 
    8083            date = parsed_key['date'] 
    81              
     84 
    8285            if captcha_type == 'static': 
    8386                img = getattr(site, '%s.jpg' % index) 
     
    8790                enc = input 
    8891                solution = getWord(int(index)) 
    89              
     92 
    9093            captcha_tool = getToolByName(site, 'portal_captchas') 
    91             if (enc != solution) or (captcha_tool.has_key(decrypted_key)) or (DateTime().timeTime() - float(date) > 3600): 
     94            if (enc != solution) or (decrypted_key in captcha_tool) or \ 
     95               (DateTime().timeTime() - float(date) > 3600): 
    9296                raise ConversionError(_(u'Please re-enter validation code.')) 
    9397            else: 
    9498                captcha_tool.addExpiredKey(decrypted_key) 
    95          
     99 
    96100        return super(CaptchaWidget, self)._toFieldValue(input) 
  • quintagroup.formlib.captcha/trunk/setup.py

    r2809 r3121  
    66setup(name='quintagroup.formlib.captcha', 
    77      version=version, 
    8       description="Captcha field for formlib based on quintagroup.captcha.core package", 
     8      description="Captcha field for formlib based on " 
     9                  "quintagroup.captcha.core package", 
    910      long_description=open("README.txt").read() + "\n" + 
    1011                       open(os.path.join("docs", "HISTORY.txt")).read(), 
    11       # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers 
    1212      classifiers=[ 
    1313        "Framework :: Plone", 
Note: See TracChangeset for help on using the changeset viewer.