kopia lustrzana https://github.com/collective/icalendar
				
				
				
			Component returns True if checked with bool()
https://github.com/collective/icalendar/issues/141pull/179/head
							rodzic
							
								
									18637a97ee
								
							
						
					
					
						commit
						f1f4bc52db
					
				| 
						 | 
				
			
			@ -93,6 +93,21 @@ class Component(CaselessDict):
 | 
			
		|||
    #    """
 | 
			
		||||
    #    return name in not_compliant
 | 
			
		||||
 | 
			
		||||
    def __bool__(self):
 | 
			
		||||
        """
 | 
			
		||||
        Returns True, CaselessDict would return False if it had no items
 | 
			
		||||
        """
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
    # python 2 compatibility
 | 
			
		||||
    __nonzero__ = __bool__
 | 
			
		||||
 | 
			
		||||
    def is_empty(self):
 | 
			
		||||
        """
 | 
			
		||||
        Returns True if Component has no items or subcomponents, else False
 | 
			
		||||
        """
 | 
			
		||||
        return True if not (list(self.values()) + self.subcomponents) else False
 | 
			
		||||
 | 
			
		||||
    #############################
 | 
			
		||||
    # handling of property values
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,9 +18,14 @@ class TestCalComponent(unittest.TestCase):
 | 
			
		|||
        c = Component()
 | 
			
		||||
        c.name = 'VCALENDAR'
 | 
			
		||||
 | 
			
		||||
        self.assertTrue(c)
 | 
			
		||||
        self.assertTrue(c.is_empty())
 | 
			
		||||
 | 
			
		||||
        # Every key defines a property.A property can consist of either a
 | 
			
		||||
        # single item. This can be set with a single value...
 | 
			
		||||
        c['prodid'] = '-//max m//icalendar.mxm.dk/'
 | 
			
		||||
        self.assertFalse(c.is_empty())
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(
 | 
			
		||||
            c,
 | 
			
		||||
            Calendar({'PRODID': '-//max m//icalendar.mxm.dk/'})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue