Source

pida-patches / proxy-unification

# HG changeset patch
# Parent 795d0059ca8f72f49995a488991efdcd05bcc325
unify the language external proxy generation

diff --git a/pida/core/languages.py b/pida/core/languages.py
--- a/pida/core/languages.py
+++ b/pida/core/languages.py
@@ -456,7 +456,7 @@ class ExternalDocument(Document):
         pass
     project = property(_get_project, _set_project)
 
-class ExternalProxy(object):
+class ExternalProxy(BaseCachedDocumentHandler):
     """
     Base Class for all proxy objects.
     """
@@ -488,27 +488,6 @@ class ExternalProxy(object):
     def run(self, *k, **kw):
         return self.svc.jobserver.run(self)
 
-
-class ExternalValidatorProxy(ExternalProxy, Validator):
-    """Proxies to the jobmanager and therefor to the external process"""
-    mytype = 'validator'
-
-class ExternalOutlinerProxy(ExternalProxy, Outliner):
-    """Proxies to the jobmanager and therefor to the external process"""
-    mytype = 'outliner'
-
-class ExternalDefinerProxy(ExternalProxy, Definer):
-    """Proxies to the jobmanager and therefor to the external process"""
-    mytype = 'definer'
-
-class ExternalDocumentatorProxy(ExternalProxy, Documentator):
-    """Proxies to the jobmanager and therefor to the external process"""
-    mytype = 'documenter'
-
-class ExternalCompleterProxy(ExternalProxy, Completer):
-    """Proxies to the jobmanager and therefor to the external process"""
-    mytype = 'completer'
-
 class Merger(BaseDocumentHandler):
     """
     Merges different sources of providers into one stream
@@ -657,30 +636,28 @@ class LanguageService(Service):
         if self.external is not None and multiprocessing:
             # if we have multiprocessing support we exchange the
             # language factories to the proxy objects
-            def newproxy(old, factory):
-                if old is None:
-                    return factory
-                class NewProxy(factory):
-                    pass
-                NewProxy._uuid = old.uuid()
-                NewProxy.priority = old.priority
-                NewProxy.name = old.name
-                NewProxy.plugin = old.plugin
-                NewProxy.description = old.description
+            def newproxy(old, mytype_):
+                class NewProxy(ExternalProxy):
+                    mytype = mytype_
+                    _uuid = old.uuid()
+                    priority = old.priority
+                    name = old.name
+                    plugin = old.plugin
+                    description = old.description
+                    __name__ = 'External%sProxy' % mytype.capitalize()
+                    try:
+                        filter_type = old.filter_type
+                    except AttributeError:
+                        pass
                 return NewProxy
 
-            if self.external.validator:
-                self.validator_factory = newproxy(self.validator_factory, ExternalValidatorProxy)
-            if self.external.outliner:
-                ofac = self.outliner_factory
-                self.outliner_factory = newproxy(self.outliner_factory, ExternalOutlinerProxy)
-                self.outliner_factory.filter_type = ofac.filter_type
-            if self.external.documentator:
-                self.documentator_factory = newproxy(self.documentator_factory, ExternalDocumentatorProxy)
-            if self.external.definer:
-                self.definer_factory = newproxy(self.definer_factory, ExternalDefinerProxy)
-            if self.external.completer:
-                self.completer_factory = newproxy(self.completer_factory, ExternalCompleterProxy)
+            for name in 'validator outliner documentator definer completer'.split():
+                if getattr(self.external, name):
+                    attr = name + '_factory'
+                    old = getattr(self, attr)
+                    proxy = newproxy(old, name)
+                    setattr(self, attr, proxy)
+
 
         super(LanguageService, self).__init__(boss)
         self.boss = boss
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.