Commits

Ginés Martínez Sánchez committed 4ec7c29 Draft

cleaning

Comments (0)

Files changed (1)

         GConfig.__init__(self, gconfig)
 
     def __del__(self):
-        logging.debug("Destroyed! <-- %r" % (self))
+        if self.logger:
+            self.logger.debug("Destroyed! <-- %r" % (self))
 
     def __str__(self):
         name = "%s" % (self.name)
         if self.__random_name__:
             name = self.get_random_name(name)
 
-        self.logger.debug("Creating --> '%s:%s'" % (
-            gclass.__name__, name))
+        if self.logger:
+            self.logger.debug("Creating --> '%s:%s'" % (
+                gclass.__name__, name))
 
         gobj = gclass()
 
     def destroy_gobj(gobj):
         """ Destroy a gobj
         """
-        gobj.logger.debug("Destroying --> %r" % (gobj))
+        if gobj.logger:
+            gobj.logger.debug("Destroying --> %r" % (gobj))
 
         if gobj._destroyed:
-            gobj.logger.error("ERROR reentering in destroy_gobj: %r" % gobj)
+            if gobj.logger:
+                gobj.logger.error(
+                    "ERROR reentering in destroy_gobj: %r" % gobj)
             return
 
         gobj._destroyed = True
         existing_subs = self._find_subscription(event_name, subscriber_gobj)
         if existing_subs:
             # avoid duplication subscriptions
-            self.logger.warning(
-                "WARNING duplicate subscription:\n"
-                "  me : %r\n"
-                "  ev : %r\n"
-                "  sub: %r\n" %
-                (self, event_name, subscriber_gobj))
+            if self.logger:
+                self.logger.warning(
+                    "WARNING duplicate subscription:\n"
+                    "  me : %r\n"
+                    "  ev : %r\n"
+                    "  sub: %r\n" %
+                    (self, event_name, subscriber_gobj))
             self.delete_subscription(event_name, subscriber_gobj)
         subscription = _Subscription(self, event_name, subscriber_gobj, **kw)
-        self.logger.debug('NEW %r' % subscription)
+        if self.logger:
+            self.logger.debug('NEW %r' % subscription)
         self._dl_subscriptions.add(subscription)
         self._some_subscriptions = True
 
         :param subscriber_gobj: subscriber gobj.
         """
         sub = self._find_subscription(event_name, subscriber_gobj)
-        self.logger.debug('DEL %r' % sub)
+        if self.logger:
+            self.logger.debug('DEL %r' % sub)
         if sub:
             if sub.kw.get('__hard_subscription__', None):
-                self.logger.error(
-                    "WARNING cannot delete a hard subscription(): '%s'" % (
-                        event_name))
+                if self.logger:
+                    self.logger.error(
+                        "WARNING cannot delete a hard subscription(): '%s'" % (
+                            event_name))
                 return False
             else:
                 self._dl_subscriptions.remove(sub)
                     self._some_subscriptions = False
                 return True
 
-        self.logger.error(
-            "ERROR delete_subscription(): '%s' NOT FOUND " % (event_name))
+        if self.logger:
+            self.logger.error(
+                "ERROR delete_subscription(): '%s' NOT FOUND " % (event_name))
 
         return False
 
             if not force:
                 if sub.kw.get('__hard_subscription__'):
                     continue
-            self.logger.debug('DEL %r' % sub)
+            if self.logger:
+                self.logger.debug('DEL %r' % sub)
             self._dl_subscriptions.remove(sub)
 
         if len(self._dl_subscriptions) == 0:
         """ Enable gobjs tree to work with Pyramid traversal URL dispatch.
         """
         trace_traverse = self.config.trace_traverse
-        if trace_traverse:
-            logger = self.logger
-            logger.debug("==> TRAVERSING('%s') -> %s" % (
+        if trace_traverse and self.logger:
+            self.logger.debug("==> TRAVERSING('%s') -> %s" % (
                 name, self.resource_path()))
 
         if name is None:
                 continue
             else:
                 if gobj.name == name:
-                    if trace_traverse:
-                        logger.debug("    TRAVERSING FOUND!")
+                    if trace_traverse and self.logger:
+                        self.logger.debug("    TRAVERSING FOUND!")
                     return gobj
 
         # Secondly search re_name
                 if gobj._re_compiled_name.match(name) is not None:
                     # this gobj has been got as re_matched_name.
                     gobj.re_matched_name = name
-                    if trace_traverse:
-                        logger.debug("    TRAVERSING %s FOUND RE!" % name)
+                    if trace_traverse and self.logger:
+                        self.logger.debug("    TRAVERSING %s FOUND RE!" % name)
                     return gobj
             else:
                 continue
-        if trace_traverse:
-            logger.debug("<== TRAVERSING('%s') -> %s END!" % (
+        if trace_traverse and self.logger:
+            self.logger.debug("<== TRAVERSING('%s') -> %s END!" % (
                 name, self.resource_path()))
         raise KeyError('No such child named %s' % name)