1. Olemis Lang
  2. trac-mq

Commits

Olemis Lang  committed 4eaeff5

Trac #11148 : 'extends_with_prefix' transformed into class decorator

  • Participants
  • Parent commits 7aebf82
  • Branches trac_t11148

Comments (0)

Files changed (1)

File t11148/t11148_r11782_IEntityChangeListener_extends_with_prefix.diff

View file
  • Ignore whitespace
 
 diff -r 8d0c3223a818 trac/core.py
 --- a/trac/core.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/core.py	Thu Apr 18 19:52:28 2013 -0500
-@@ -165,8 +165,22 @@
++++ b/trac/core.py	Thu Apr 18 20:08:21 2013 -0500
+@@ -165,8 +165,16 @@
  
          locals_.setdefault('_implements', []).extend(interfaces)
  
 +    @staticmethod
 +    def extends_with_prefix(prefix):
-+        import sys
-+ 
-+        frame = sys._getframe(1)
-+        locals_ = frame.f_locals
++        def prefix_decorator(class_):
++            class_._extends_with_prefix = prefix
++            return class_
 +
-+        # Some sanity checks
-+        assert locals_ is not frame.f_globals and '__module__' in locals_, \
-+            'extends_with_prefix() can only be used in a class definition'
-+
-+        locals_['_extends_with_prefix'] = prefix
-+
++        return prefix_decorator
  
  implements = Component.implements
 +extends_with_prefix = Component.extends_with_prefix
  
  
  class ComponentManager(object):
-@@ -236,3 +250,92 @@
+@@ -236,3 +244,92 @@
          with the given class will not be available.
          """
          return True
 +
 diff -r 8d0c3223a818 trac/ticket/model.py
 --- a/trac/ticket/model.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/ticket/model.py	Thu Apr 18 19:52:28 2013 -0500
++++ b/trac/ticket/model.py	Thu Apr 18 20:08:21 2013 -0500
 @@ -25,7 +25,8 @@
  from trac.attachment import Attachment
  from trac import core
  
      @classmethod
      def select(cls, env, db=None):
-@@ -830,10 +846,13 @@
-                 obj.value = obj._old_value = value
+@@ -831,9 +847,15 @@
                  yield obj
  
+ 
++@extends_with_prefix("type")
 +class ITypeChangeListener(IEntityChangeListener):
-+    extends_with_prefix("type")
- 
++    pass
++
++
  class Type(AbstractEnum):
      type = 'ticket_type'
      ticket_col = 'type'
  
  
  class Status(object):
-@@ -847,19 +866,33 @@
-             status.name = state
+@@ -848,16 +870,39 @@
              yield status
  
+ 
++@extends_with_prefix("resolution")
 +class IResolutionChangeListener(IEntityChangeListener):
-+    extends_with_prefix("resolution")
- 
++    pass
++
++
  class Resolution(AbstractEnum):
      type = 'resolution'
 +    change_listener_interface = IResolutionChangeListener
++
++
++@extends_with_prefix("priority")
++class IPriorityChangeListener(IEntityChangeListener):
++    pass
  
  
-+class IPriorityChangeListener(IEntityChangeListener):
-+    extends_with_prefix("priority")
-+
  class Priority(AbstractEnum):
      type = 'priority'
 +    change_listener_interface = IPriorityChangeListener
++
++
++@extends_with_prefix("severity")
++class ISeverityChangeListener(IEntityChangeListener):
++    pass
  
  
-+class ISeverityChangeListener(IEntityChangeListener):
-+    extends_with_prefix("severity")
-+
  class Severity(AbstractEnum):
      type = 'severity'
 +    change_listener_interface = ISeverityChangeListener
++
++
++@extends_with_prefix("component")
++class IComponentChangeListener(IEntityChangeListener):
++   pass 
  
  
-+class IComponentChangeListener(IEntityChangeListener):
-+    extends_with_prefix("component")
-+
  class Component(object):
-     def __init__(self, env, name=None, db=None):
-         """
-@@ -893,9 +926,13 @@
+@@ -893,9 +938,13 @@
          with self.env.db_transaction as db:
              self.env.log.info("Deleting component %s", self.name)
              db("DELETE FROM component WHERE name=%s", (self.name,))
      def insert(self, db=None):
          """Insert a new component.
  
-@@ -915,6 +952,9 @@
+@@ -915,6 +964,9 @@
              self._old_name = self.name
              TicketSystem(self.env).reset_ticket_fields()
  
      def update(self, db=None):
          """Update the component.
  
-@@ -926,6 +966,7 @@
+@@ -926,6 +978,7 @@
          if not self.name:
              raise TracError(_("Invalid component name."))
  
          with self.env.db_transaction as db:
              self.env.log.info("Updating component '%s'", self.name)
              db("""UPDATE component SET name=%s,owner=%s, description=%s
-@@ -939,6 +980,13 @@
+@@ -939,6 +992,13 @@
                  self._old_name = self.name
              TicketSystem(self.env).reset_ticket_fields()
  
      @classmethod
      def select(cls, env, db=None):
          """
-@@ -1169,6 +1217,8 @@
-         groups.append((_('Closed'), closed_milestones))
+@@ -1170,6 +1230,11 @@
      return groups
  
+ 
++@extends_with_prefix("version")
 +class IVersionChangeListener(IEntityChangeListener):
-+    extends_with_prefix("version")
- 
++    pass
++
++
  class Version(object):
      def __init__(self, env, name=None, db=None):
-@@ -1199,9 +1249,12 @@
+         self.env = env
+@@ -1199,9 +1264,12 @@
          with self.env.db_transaction as db:
              self.env.log.info("Deleting version %s", self.name)
              db("DELETE FROM version WHERE name=%s", (self.name,))
      def insert(self, db=None):
          """Insert a new version.
  
-@@ -1220,6 +1273,9 @@
+@@ -1220,6 +1288,9 @@
              self._old_name = self.name
              TicketSystem(self.env).reset_ticket_fields()
  
      def update(self, db=None):
          """Update the version.
  
-@@ -1231,6 +1287,7 @@
+@@ -1231,6 +1302,7 @@
          if not self.name:
              raise TracError(_("Invalid version name."))
  
          with self.env.db_transaction as db:
              self.env.log.info("Updating version '%s'", self.name)
              db("""UPDATE version
-@@ -1244,6 +1301,14 @@
+@@ -1244,6 +1316,14 @@
                  self._old_name = self.name
              TicketSystem(self.env).reset_ticket_fields()
  
          """
 diff -r 8d0c3223a818 trac/ticket/tests/model.py
 --- a/trac/ticket/tests/model.py	Thu Apr 18 14:30:21 2013 +0000
-+++ b/trac/ticket/tests/model.py	Thu Apr 18 19:52:28 2013 -0500
++++ b/trac/ticket/tests/model.py	Thu Apr 18 20:08:21 2013 -0500
 @@ -12,8 +12,8 @@
  from trac.core import TracError, implements
  from trac.resource import ResourceNotFound