[KSS-checkins] r49290 - kukit/kss.zope/trunk/kss/zope

reebalazs at codespeak.net reebalazs at codespeak.net
Sun Dec 2 18:09:16 CET 2007


Author: reebalazs
Date: Sun Dec  2 18:09:15 2007
New Revision: 49290

Modified:
   kukit/kss.zope/trunk/kss/zope/commands.py
Log:
Clean up commands, add compatibility for addCommand, addParam

Modified: kukit/kss.zope/trunk/kss/zope/commands.py
==============================================================================
--- kukit/kss.zope/trunk/kss/zope/commands.py	(original)
+++ kukit/kss.zope/trunk/kss/zope/commands.py	Sun Dec  2 18:09:15 2007
@@ -2,6 +2,10 @@
 from kss.base import KSSCommands
 from interfaces import IKSSPluginRegistry, IZopeCommandSet
 from bbb.commandset import CompatCommandSet
+# BBB
+from kss.base.selectors import Selector, css 
+#from bbb.deprecated import deprecated
+#when = 'after 2008-08-01'
 
 class KSSZopeCommands(KSSCommands):
     def __init__(self, view, context, request):
@@ -23,124 +27,19 @@
         else:
             return commandset_factory(self)
 
-    # Add something like this
-    # XXX XXX This is not working!!!!!!! 
+    ## Don't BBB yet. Uncommenting the next line will activate BBB.
+    ##@deprecated('use view.commands.add(action, selector **kw)', when)
     def addCommand(self, command_name, selector=None, **kw):
-        command = KSSCommand(command_name, selector=selector, **kw)
-        self.append(command)
-        return command
-
-'''
-# BBB stuf
-class KSSParam:
-    implements(IKSSParam)
-    
-    def __init__(self, name, content=''):
-        self.name = name
-        self.content = content
-
-    def force_content_unicode(self):
-        # Content must be str with ascii encoding, or unicode!
-        self.content = force_unicode(self.content)
-
-    def getName(self):
-        return self.name
-
-    def getContent(self):
-        return self.content
-        
-class KSSCommand:
-    implements(IKSSCommand)
-    
-    def __init__(self, command_name, selector=None, **kw):
-        try:
-            checkRegisteredCommand_old(command_name)
-        except KSSPluginError:
-            # we expect this is not registered as command, anyway
-            # so check it as an action.
-            checkRegisteredCommand(command_name)
-        else:
-            # ok. XXX this will be deprecated
-            # All registerCommand commands are obsolete, by default
-            import warnings, textwrap
-            warnings.warn(textwrap.dedent('
-            The usage of the kss command "%s" is deprecated'
-                % (command_name, )), DeprecationWarning, 2)
-        if selector is not None:
-            if isinstance(selector, basestring): 
-                # the default selector - given just as a string
-                self.selector = selector
-                self.selectorType = ''
-            else:
-                checkRegisteredSelector(selector.type)
-                self.selector = selector.value
-                self.selectorType = selector.type
-        else:
-            self.selector = None
-            self.selectorType = None
-        self.name = command_name
-        self.params = []
-        # Add parameters passed in **kw
-        for key, value in kw.iteritems():
-            self.addParam(key, value)
-
-    # --
-    # Different parameter conversions
-    # --
-
-    # REMARK: with the jsonserver product present, you can
-    # just send complex data types directly with AddParam
-
-    def addParam(self, name, content=''):
-        'Add the param as is'
-        param = KSSParam(name, content)
-        self.params.append(param)
-        return param
-
-    #
-    # Some helpers
-    #
-
-    def addUnicodeParam(self, name, content=''):
-        'Add the param as unicode'
-        self.addParam(name, content=content)
-
-    def addStringParam(self, name, content='', encoding='utf'):
-        'Add the param as an encoded string, by default UTF-8'
-        content = unicode(content, 'utf')
-        self.addParam(name, content=content)
-
-    def addHtmlParam(self, name, content=''):
-        'Add the param as an HTML content.'
-        content = HtmlParser(content)().encode('ascii', 'xmlcharrefreplace')
-        ##self.addParam(name, content=content)
-        # add html as cdata!
-        self.addCdataParam(name, content=content)
-
-    def addXmlParam(self, name, content=''):
-        'Add the param as XML content'
-        content = XmlParser(content)().encode('ascii', 'xmlcharrefreplace')
-        self.addParam(name, content=content)
-
-    def addCdataParam(self, name, content=''):
-        'Add the param as a CDATA node'
-        content = '<![CDATA[%s]]>' % (content, )
-        self.addParam(name, content=content)
-
-
-    # --
-    # Accessors, not sure if we need them
-    # --
-
-    def getName(self):
-        return self.name
-
-    def getSelector(self):
-        return self.selector
-
-    def getSelectorType(self):
-        return self.selectorType
-
-    def getParams(self):
-        return self.params
-'''
+        self._strip_none_parameters(kw)
+
+        if selector is not None and not isinstance(selector, Selector):
+            selector = css(selector)
+
+        self.commands.append(CompatCommand(command_name, selector, kw))
+
+# Nasty BBB for covering this old usage:
+#     command = self.addCommand('command_name', 'selector')
+#     command.addParam('key', 'value')
+class CompatCommand(tuple):
+    def addParam(self, key, value):
+        self[2][key] = value


More information about the Kukit-checkins mailing list