Ignore:
Timestamp:
Apr 19, 2011 12:05:38 PM (13 years ago)
Author:
vmaksymiv
Message:

pep8 fixes

Location:
quintagroup.canonicalpath/trunk/quintagroup/canonicalpath
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/adapters.py

    r2369 r3145  
    5555        """ 
    5656        if self.context.hasProperty(self.prop): 
    57             self.context.manage_delProperties(ids=[self.prop,]) 
     57            self.context.manage_delProperties(ids=[self.prop, ]) 
    5858 
    5959 
     
    8686    def __init__(self, context): 
    8787        super(DefaultCanonicalPathAdapter, self).__init__(context) 
    88         self.purl = getToolByName(self.context,'portal_url') 
     88        self.purl = getToolByName(self.context, 'portal_url') 
    8989 
    9090    def getDefault(self): 
    91         return '/'+'/'.join(self.purl.getRelativeContentPath(self.context)) 
     91        return '/' + '/'.join(self.purl.getRelativeContentPath(self.context)) 
    9292 
    9393    canonical_path = property(DefaultCanonicalAdapter.getProp, 
  • quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/catalog.py

    r2125 r3145  
    22from zope.component import queryAdapter 
    33 
    4 #for compatibility with older plone versions  
     4#for compatibility with older plone versions 
    55try: 
    6     from plone.indexer.decorator import indexer  
     6    from plone.indexer.decorator import indexer 
    77    IS_NEW = True 
    88except: 
    99    IS_NEW = False 
    10     class IDummyInterface:pass 
     10 
     11    class IDummyInterface: 
     12        pass 
     13 
    1114    class indexer: 
    1215 
    13          def __init__(self, *interfaces): 
     16        def __init__(self, *interfaces): 
    1417            self.interfaces = IDummyInterface, 
    1518 
    16          def __call__(self, callable): 
    17              callable.__component_adapts__ = self.interfaces 
    18              callable.__implemented__ = Interface 
    19              return callable 
    20      
     19        def __call__(self, callable): 
     20            callable.__component_adapts__ = self.interfaces 
     21            callable.__implemented__ = Interface 
     22            return callable 
     23 
    2124from interfaces import ICanonicalPath 
    2225from interfaces import ICanonicalLink 
     26 
    2327 
    2428@indexer(Interface) 
     
    3135    return None 
    3236 
     37 
    3338@indexer(Interface) 
    3439def canonical_link(obj, **kwargs): 
     
    4045    return None 
    4146 
    42 #for compatibility with older plone versions  
     47#for compatibility with older plone versions 
    4348if not IS_NEW: 
    4449    from Products.CMFPlone.CatalogTool import registerIndexableAttribute 
  • quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/interfaces.py

    r1927 r3145  
    11from zope.interface import Interface, Attribute 
     2 
    23 
    34class ICanonicalPath(Interface): 
     
    910        "*setter* and *getter* for the attribute") 
    1011 
     12 
    1113class ICanonicalLink(Interface): 
    1214    """canonical_link provider interface 
     
    1618        "canonical_link - for the object. Adapter must implement " 
    1719        "*setter* and *getter* for the attribute") 
    18  
  • quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py

    r2972 r3145  
    66from zope.schema.interfaces import InvalidValue 
    77 
    8 #for compatibility with older plone versions  
     8#for compatibility with older plone versions 
    99try: 
    1010    from plone.indexer.interfaces import IIndexableObject 
     
    3535from quintagroup.canonicalpath.upgrades import CanonicalConvertor 
    3636 
     37 
    3738def registerCanonicalPathInReg(): 
    38     import quintagroup.canonicalpath, Products.Five 
     39    import quintagroup.canonicalpath 
     40    import Products.Five 
    3941    fiveconfigure.debug_mode = True 
    4042    zcml.load_config('meta.zcml', Products.Five) 
    4143    zcml.load_config('configure.zcml', quintagroup.canonicalpath) 
    4244    fiveconfigure.debug_mode = False 
     45 
    4346 
    4447class TestCase(ptc.PloneTestCase): 
     
    5457ptc.setupPloneSite() 
    5558 
     59 
    5660class TestIndexerRegistration(TestCase): 
    5761 
     
    5963        self.loginAsPortalOwner() 
    6064        self.catalog = getToolByName(self.portal, 'portal_catalog') 
    61         self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') 
     65        self.my_doc = makeContent(self.portal, portal_type='Document', 
     66                                  id='my_doc') 
    6267        self.logout() 
    6368 
     
    6671            wrapper = None 
    6772            if not IIndexableObject.providedBy(obj): 
    68                 wrapper = queryMultiAdapter((obj, self.catalog), IIndexableObject) 
     73                wrapper = queryMultiAdapter((obj, self.catalog), 
     74                                            IIndexableObject) 
    6975        else: 
    7076            wf = getattr(self.portal, 'portal_workflow', None) 
     
    7379            else: 
    7480                vars = {} 
    75             wrapper = getMultiAdapter((obj, self.portal), _old_IIndexableObjectWrapper) 
     81            wrapper = getMultiAdapter((obj, self.portal), 
     82                                      _old_IIndexableObjectWrapper) 
    7683            wrapper.update(vars) 
    77              
     84 
    7885        return wrapper and wrapper or obj 
    7986 
    8087    def testForAT(self): 
    8188        wrapper = self.get_indexable_wrapper(self.my_doc) 
    82         self.assertFalse(wrapper is None, "No indexer registered for document object") 
     89        self.assertFalse(wrapper is None, 
     90                         "No indexer registered for document object") 
    8391 
    8492    def testCanonicalPathForAT(self): 
    8593        wrapper = self.get_indexable_wrapper(self.my_doc) 
    8694        self.assertTrue(hasattr(wrapper, 'canonical_path'), 
    87             "'canonical_path' attribute not accessible with indexer wrapper for Document object") 
     95                        "'canonical_path' attribute not accessible with "\ 
     96                        "indexer wrapper for Document object") 
    8897 
    8998    def testCanonicalLinkForAT(self): 
    9099        wrapper = self.get_indexable_wrapper(self.my_doc) 
    91100        self.assertTrue(hasattr(wrapper, 'canonical_link'), 
    92             "'canonical_link' attribute not accessible with indexer wrapper for Document object") 
    93  
    94  
    95          
     101                        "'canonical_link' attribute not accessible with "\ 
     102                        "indexer wrapper for Document object") 
     103 
     104 
    96105class TestDefaultCanonicalPathAdapter(TestCase): 
    97106 
     
    99108        self.loginAsPortalOwner() 
    100109        self.purl = getToolByName(self.portal, 'portal_url') 
    101         self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') 
     110        self.my_doc = makeContent(self.portal, portal_type='Document', 
     111                                  id='my_doc') 
    102112        self.logout() 
    103113 
    104         self.mydoc_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.my_doc)) 
    105         self.portal_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.portal)) 
     114        self.mydoc_cp = '/' + '/'.join(self.purl.getRelativeContentPath( 
     115                                            self.my_doc)) 
     116        self.portal_cp = '/' + '/'.join(self.purl.getRelativeContentPath( 
     117                                            self.portal)) 
    106118 
    107119    def testRegistration4Portal(self): 
     
    114126        self.assertFalse(cpadapter is None, 
    115127            "Can't get canonical path adapter for the Document object") 
    116          
    117128 
    118129    def testGetDefault4Portal(self): 
     
    120131        self.assertTrue(cpadapter.canonical_path == self.portal_cp, 
    121132            "Canonical path adapter return '%s' for portal, must be: '%s'" % ( 
    122             cpadapter.canonical_path, self.portal_cp) ) 
    123  
     133            cpadapter.canonical_path, self.portal_cp)) 
    124134 
    125135    def testGetDefault4AT(self): 
    126136        cpadapter = queryAdapter(self.my_doc, ICanonicalPath) 
    127137        self.assertTrue(cpadapter.canonical_path == self.mydoc_cp, 
    128             "Canonical path adapter return '%s' for document, must be: '%s'" % ( 
    129             cpadapter.canonical_path, self.mydoc_cp) ) 
    130  
     138            "Canonical path adapter return '%s' for document, "\ 
     139            "must be: '%s'" % (cpadapter.canonical_path, self.mydoc_cp)) 
    131140 
    132141    def testSet4Portal(self): 
     
    138147        self.assertTrue(prop == newcp, 
    139148            "Canonical path adapter setter NOT SET new '%s' value to '%s' " \ 
    140             "propery for the portal" % (newcp, PROPERTY_PATH) ) 
     149            "propery for the portal" % (newcp, PROPERTY_PATH)) 
    141150 
    142151        self.assertTrue(cpadapter.canonical_path == newcp, 
    143152            "Canonical path adapter GET '%s' canonical_path, for portal, " \ 
    144             "must be: '%s'" % (cpadapter.canonical_path, newcp) ) 
    145  
     153            "must be: '%s'" % (cpadapter.canonical_path, newcp)) 
    146154 
    147155    def testSet4AT(self): 
     
    153161        self.assertTrue(prop == newcp, 
    154162            "Canonical path adapter setter NOT SET new '%s' value to '%s' " \ 
    155             "propery for the Document" % (newcp, PROPERTY_PATH) ) 
     163            "propery for the Document" % (newcp, PROPERTY_PATH)) 
    156164 
    157165        self.assertTrue(cpadapter.canonical_path == newcp, 
    158166            "Canonical path adapter GET '%s' canonical_path, for Document, " \ 
    159             "must be: '%s'" % (cpadapter.canonical_path, newcp) ) 
    160  
     167            "must be: '%s'" % (cpadapter.canonical_path, newcp)) 
    161168 
    162169    def testValidationWrong(self): 
    163170        cpadapter = queryAdapter(self.my_doc, ICanonicalPath) 
    164         for wrong in ['new\nline','s p a c e','with\ttabs']: 
     171        for wrong in ['new\nline', 's p a c e', 'with\ttabs']: 
    165172            try: 
    166173                cpadapter.canonical_path = wrong 
     
    170177                raise self.failureException, "InvalidValue not raised when " \ 
    171178                      "'%s' wrong value try to set" % wrong 
    172          
     179 
    173180    def testValidationGood(self): 
    174181        cpadapter = queryAdapter(self.my_doc, ICanonicalPath) 
    175         for good in ['./good','../good','/good', 'good']: 
     182        for good in ['./good', '../good', '/good', 'good']: 
    176183            cpadapter.canonical_path = good 
    177  
    178184 
    179185    def testDeleteProperty(self): 
     
    187193            "Not deleted Canonical path customization property for the portal") 
    188194 
    189  
    190195    def testDelCustomization(self): 
    191196        cpadapter = queryAdapter(self.portal, ICanonicalPath) 
     
    204209        self.loginAsPortalOwner() 
    205210        self.purl = getToolByName(self.portal, 'portal_url') 
    206         self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') 
     211        self.my_doc = makeContent(self.portal, portal_type='Document', 
     212                                  id='my_doc') 
    207213        self.logout() 
    208214 
     
    218224        self.assertFalse(cladapter is None, 
    219225            "Can't get canonical link adapter for the Document object") 
    220          
    221226 
    222227    def testGetDefault4Portal(self): 
     
    224229        self.assertTrue(cladapter.canonical_link == self.purl(), 
    225230            "Canonical link adapter return '%s' for portal, must be: '%s'" % ( 
    226             cladapter.canonical_link, self.purl()) ) 
    227  
     231            cladapter.canonical_link, self.purl())) 
    228232 
    229233    def testGetDefault4AT(self): 
    230234        cladapter = queryAdapter(self.my_doc, ICanonicalLink) 
    231235        self.assertTrue(cladapter.canonical_link == self.mydoc_cl, 
    232             "Canonical link adapter return '%s' for document, must be: '%s'" % ( 
    233             cladapter.canonical_link, self.mydoc_cl) ) 
    234  
     236            "Canonical link adapter return '%s' for document, "\ 
     237            "must be: '%s'" % (cladapter.canonical_link, self.mydoc_cl)) 
    235238 
    236239    def testSet4Portal(self): 
     
    242245        self.assertTrue(prop == newcl, 
    243246            "Canonical link adapter setter NOT SET new '%s' value to '%s' " \ 
    244             "propery for the portal" % (newcl, PROPERTY_LINK) ) 
     247            "propery for the portal" % (newcl, PROPERTY_LINK)) 
    245248 
    246249        self.assertTrue(cladapter.canonical_link == newcl, 
    247250            "Canonical link adapter GET '%s' canonical_link, for portal, " \ 
    248             "must be: '%s'" % (cladapter.canonical_link, newcl) ) 
    249  
     251            "must be: '%s'" % (cladapter.canonical_link, newcl)) 
    250252 
    251253    def testSet4AT(self): 
     
    257259        self.assertTrue(prop == newcl, 
    258260            "Canonical link adapter setter NOT SET new '%s' value to '%s' " \ 
    259             "propery for the Document" % (newcl, PROPERTY_LINK) ) 
     261            "propery for the Document" % (newcl, PROPERTY_LINK)) 
    260262 
    261263        self.assertTrue(cladapter.canonical_link == newcl, 
    262264            "Canonical link adapter GET '%s' canonical_link, for Document, " \ 
    263             "must be: '%s'" % (cladapter.canonical_link, newcl) ) 
     265            "must be: '%s'" % (cladapter.canonical_link, newcl)) 
    264266 
    265267    def testValidationWrong(self): 
    266268        cladapter = queryAdapter(self.my_doc, ICanonicalLink) 
    267         for wrong in ['http://new\nline','s p a c e','with\ttabs']: 
     269        for wrong in ['http://new\nline', 's p a c e', 'with\ttabs']: 
    268270            try: 
    269271                cladapter.canonical_link = wrong 
     
    273275                raise self.failureException, "InvalidValue not raised when " \ 
    274276                    "'%s' wrong value try to set" % wrong 
    275          
     277 
    276278    def testValidationGood(self): 
    277279        cladapter = queryAdapter(self.my_doc, ICanonicalLink) 
    278         for good in ['http://', './good','../good','/good', 'good']: 
     280        for good in ['http://', './good', '../good', '/good', 'good']: 
    279281            cladapter.canonical_link = good 
    280  
    281282 
    282283    def testDeleteProperty(self): 
     
    290291            "Not deleted Canonical link customization property for the portal") 
    291292 
    292  
    293293    def test_DelCustomization(self): 
    294294        cladapter = queryAdapter(self.portal, ICanonicalLink) 
     
    304304## Dummy object for converter tests 
    305305## 
     306 
     307 
    306308class PortalURL: 
    307309    def __call__(self): 
    308310        return "http://nohost/plone" 
     311 
    309312    def getRelativeContentPath(self, context): 
    310313        return ("plone", context.getId()) 
    311314 
     315 
    312316class BaseItem: 
    313317    portal_url = PortalURL() 
     
    320324 
    321325    def absolute_url(self): 
    322         return self.portal_url() + '/'+ self.getId() 
     326        return self.portal_url() + '/' + self.getId() 
     327 
    323328 
    324329class GoodItem(BaseItem, PropertyManager, Traversable): 
    325330    """Property provider.""" 
    326331 
     332 
    327333class NotPropertyProviderItem(BaseItem, Traversable): 
    328334    """Not property provider.""" 
     335 
    329336 
    330337class NotAdaptableItem(BaseItem): 
     
    349356        # 2. canonical path propery mast be delete from the object 
    350357        self.assertEqual(item.hasProperty(ICanonicalPath(item).prop), False, 
    351                          "canonical path' property not deleted from the object") 
     358                         "canonical path property not deleted from the object") 
    352359 
    353360    def test_convertPPathToLink(self): 
     
    368375        self.convertor.convertIPathToLink(bad) 
    369376        result = self.convertor.getLogs() 
    370         expect = "NotPropertyProviderItem instance has no attribute 'hasProperty'" 
     377        expect = "NotPropertyProviderItem instance "\ 
     378                 "has no attribute 'hasProperty'" 
    371379        self.assertEqual(expect in result, True, "Wrong log: %s" % result) 
    372380 
     
    397405        logs3 = self.convertor.getLogs() 
    398406        self.assertEqual(logs3 > logs2, True, 
    399              "Log was not updated - last: \"%s\", previous: \"%s\"" % (logs3, logs2)) 
    400          
     407             "Log was not updated - last: \"%s\", previous: \"%s\"" % (logs3, 
     408                                                                       logs2)) 
     409 
    401410    def test_loggingCleanup(self): 
    402411        bad = NotPropertyProviderItem("item") 
     
    417426 
    418427    def test_PropertyManagerAndTraversable(self): 
    419         class ProperyAndTraverseProvider(BaseItem, PropertyManager, Traversable): 
     428        class ProperyAndTraverseProvider(BaseItem, PropertyManager, 
     429                                         Traversable): 
    420430            """Property and Traversable provider.""" 
    421431        item = ProperyAndTraverseProvider("test") 
    422432        self.assertNotEqual(queryAdapter(item, ICanonicalLink), None, 
    423            self.cant % ICanonicalLink.__name__ + "IPropertyManager and ITraversable.") 
     433            self.cant % ICanonicalLink.__name__ + "IPropertyManager and "\ 
     434                                                  "ITraversable.") 
    424435        self.assertNotEqual(queryAdapter(item, ICanonicalPath), None, 
    425            self.cant % ICanonicalPath.__name__ + "IPropertyManager and ITraversable.") 
     436            self.cant % ICanonicalPath.__name__ + "IPropertyManager and "\ 
     437                                                  "ITraversable.") 
    426438 
    427439    def test_Traversable(self): 
     
    452464        item = NotProvider("test") 
    453465        self.assertEqual(queryAdapter(item, ICanonicalLink), None, 
    454            self.doget % ICanonicalLink.__name__ + "nor ITraversabe not IPropertyManager.") 
     466           self.doget % ICanonicalLink.__name__ + "nor ITraversabe not "\ 
     467                                                  "IPropertyManager.") 
    455468        self.assertEqual(queryAdapter(item, ICanonicalPath), None, 
    456            self.doget % ICanonicalPath.__name__ + "nor ITraversabe not IPropertyManager.") 
     469           self.doget % ICanonicalPath.__name__ + "nor ITraversabe not "\ 
     470                                                  "IPropertyManager.") 
    457471 
    458472 
  • quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/upgrades.py

    r2371 r3145  
    1212from quintagroup.canonicalpath.adapters import PROPERTY_PATH 
    1313from quintagroup.canonicalpath.adapters import DefaultPropertyAdapter 
     14 
    1415 
    1516class CanonicalConvertor(object): 
     
    6566           Log results in logger. 
    6667        """ 
    67         src_msg = type(src_iface) in StringTypes and src_iface or src_iface.__name__ 
     68        src_msg = type(src_iface) in StringTypes and src_iface \ 
     69                                                 or src_iface.__name__ 
    6870        msg = "Migrate %s into %s for %s object: " \ 
    6971               % (src_msg, dst_iface.__name__, obj.absolute_url()) 
     
    8486            msg += "SUCCESS" 
    8587        self._logger.log(lev, msg) 
    86              
     88 
    8789        return lev == INFO and True or False 
    88      
     90 
    8991    def _getOrMakeAdapter(self, obj, arg): 
    9092        """Function return adapter for process of the property. 
    91            Adapter get by interface (if arg is not a string - interface assumed) 
     93           Adapter get by interface(if arg is not a string - interface assumed) 
    9294           OR if arg is string - adapter created from DefaultCanonicalAdapter. 
    9395        """ 
     
    120122        self._logger = Logger("quintagroup.canonicalpath", NOTSET) 
    121123        self._logger.addHandler(handler) 
    122  
Note: See TracChangeset for help on using the changeset viewer.