Author: jvloothuis
Date: Sat Oct 13 16:21:23 2007
New Revision: 47427

Added:
   kukit/kss.base/trunk/kss/base/javascript.txt
Modified:
   kukit/kss.base/trunk/kss/base/commands.py
   kukit/kss.base/trunk/kss/base/commands.txt
   kukit/kss.base/trunk/kss/base/config.py
   kukit/kss.base/trunk/kss/base/corecommands.txt
   kukit/kss.base/trunk/kss/base/plugin.py
   kukit/kss.base/trunk/kss/base/plugin.txt
   kukit/kss.base/trunk/kss/base/tests.py
Log:

Removed the validation on valid XML because the protocol has been
changed. Therefore it is no longer needed.

Added more tests for the javascript.py module.


Modified: kukit/kss.base/trunk/kss/base/commands.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/commands.py   (original)
+++ kukit/kss.base/trunk/kss/base/commands.py   Sat Oct 13 16:21:23 2007
@@ -1,5 +1,4 @@
 from xml.sax.saxutils import quoteattr, escape
-from xml.parsers.expat import ParserCreate, ExpatError
 from kss.base.registry import command_set_registry
 
 kss_response_header = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
@@ -20,7 +19,6 @@
 
     def add(self, action, selector, **kwargs):
         self.strip_none_parameters(kwargs)
-        self.validate_parameters(kwargs)
         self.commands.append((action, selector, kwargs))
 
     def strip_none_parameters(self, parameters):
@@ -28,16 +26,6 @@
             if value is None:
                 del parameters[key]
 
-    def validate_parameters(self, parameters):
-        for name, value in parameters.items():
-            parser = ParserCreate()
-            try:
-                parser.Parse('<kss>%s</kss>' % value)
-            except ExpatError:
-                raise ValueError(
-                    'Argument with name: %s is not valid xml: %s' % (
-                        name, value))
-
     def render(self):
         output = [kss_response_header]
         for action, selector, options in self.commands:

Modified: kukit/kss.base/trunk/kss/base/commands.txt
==============================================================================
--- kukit/kss.base/trunk/kss/base/commands.txt  (original)
+++ kukit/kss.base/trunk/kss/base/commands.txt  Sat Oct 13 16:21:23 2007
@@ -33,25 +33,6 @@
 
   >>> commands.add('someOtherAction', CSS('#otherid'), arg='some arg')
 
-Note that all data passed will be validated. Passing in invalid data will
-raise a ValueError.
-
-  >>> commands.add('brokenAction', CSS('#id'), arg='<h1>invalid')
-  Traceback (most recent call last):
-  ...
-  ValueError: Argument with name: arg is not valid xml: <h1>invalid
-
-The validation method can also be called directly. It will only raise and
-exeption on data which has tags that are not closed properly. Data does not
-need be valid XML (text nodes may procede any tags).
-
-  >>> commands.validate_parameters(dict(html='valid data'))
-  >>> commands.validate_parameters(dict(html='valid <strong>data</strong>'))
-  >>> commands.validate_parameters(dict(html='invalid <strong>'))
-  Traceback (most recent call last):
-  ...
-  ValueError: Argument with name: html is not valid xml: invalid <strong>
-
 Now that we have a few commands we can render them.
 
   >>> commands.render()
@@ -151,3 +132,6 @@
 This command set is initialized and ready for usage.
 
   >>> core.replaceInnerHTML(CSS('div'), 'example')
+
+
+  >>> command_set_registry.unregister('core')
\ No newline at end of file

Modified: kukit/kss.base/trunk/kss/base/config.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/config.py     (original)
+++ kukit/kss.base/trunk/kss/base/config.py     Sat Oct 13 16:21:23 2007
@@ -42,7 +42,3 @@
 
     selectors = [CSS, HTMLId, SameNode, ParentNode]
 
-    # OPTIONAL!
-    events={}
-    actions=[]
-    value_providers = []

Modified: kukit/kss.base/trunk/kss/base/corecommands.txt
==============================================================================
--- kukit/kss.base/trunk/kss/base/corecommands.txt      (original)
+++ kukit/kss.base/trunk/kss/base/corecommands.txt      Sat Oct 13 16:21:23 2007
@@ -210,6 +210,3 @@
   >>> core.moveNodeAfter(CSS('div'), 'nodeid')
   >>> print commands
   moveNodeAfter(css('div'), html_id='nodeid')
-
-
-

Added: kukit/kss.base/trunk/kss/base/javascript.txt
==============================================================================
--- (empty file)
+++ kukit/kss.base/trunk/kss/base/javascript.txt        Sat Oct 13 16:21:23 2007
@@ -0,0 +1,33 @@
+==================
+Javascript helpers
+==================
+
+The javascript module has some helpers which can be used to easily get
+the Javascript files from the active plugins.
+
+Concatinated
+============
+
+With the concatinated function you can get the a single string
+containing all the Javascript from each active plugin.
+
+  >>> from kss.base.javascript import concatinated
+
+When we run the code without activating any plugin we will get an
+empty string.
+
+  >>> concatinated()
+  ''
+
+Now if we run the code again after we activate a plugin we get
+something more interesting.
+
+  >>> from kss.base import load_plugins
+  >>> load_plugins('kss-core')
+  >>> concatinated()
+  '/*\n* Copyright (c) 2005-2007\n* Authors: KSS Project Contributors...'
+
+Finally we will unregister the core plugin to clean up.
+
+  >>> from kss.base.plugin import unload_plugins
+  >>> unload_plugins('kss-core')

Modified: kukit/kss.base/trunk/kss/base/plugin.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/plugin.py     (original)
+++ kukit/kss.base/trunk/kss/base/plugin.py     Sat Oct 13 16:21:23 2007
@@ -17,10 +17,19 @@
         for name, commandset in self.commandsets.iteritems():
             registry.register(name, commandset)
 
+    def unregister_commandsets(self, registry):
+        for name, commandset in self.commandsets.iteritems():
+            registry.unregister(name)
+
     def register_selectors(self):
         for selector in self.selectors:
             setattr(kss_selectors, selector.__name__, selector)
 
+    def unregister_selectors(self):
+        for selector in self.selectors:
+            delattr(kss_selectors, selector.__name__)
+
+
 def javascripts_from(path):
     javascripts = []
     if not os.path.isdir(path):
@@ -48,6 +57,18 @@
             plugin.register_commandsets(command_set_registry)
             plugin.register_selectors()
 
+def unload_plugins(*names):
+    for name in names:
+        for entry_point in iter_entry_points('kss.plugin', name):
+            plugin_factory = entry_point.load()
+
+            plugin = plugin_factory()
+            # Tear down of all hooks
+            plugin.unregister_commandsets(command_set_registry)
+            plugin.unregister_selectors()
+
+            plugin_registry.unregister(name)
+    
 
 def activated_plugins():
     return plugin_registry.items()

Modified: kukit/kss.base/trunk/kss/base/plugin.txt
==============================================================================
--- kukit/kss.base/trunk/kss/base/plugin.txt    (original)
+++ kukit/kss.base/trunk/kss/base/plugin.txt    Sat Oct 13 16:21:23 2007
@@ -77,6 +77,10 @@
   >>> tuple(activated_plugins())
   (('kss-testing', <ExamplePlugin object at ...>),)
 
+Finally we will unregister our plugin to clean up.
+
+  >>> from kss.base.plugin import unload_plugins
+  >>> unload_plugins('kss-testing')
 
 -----------------
 Utility functions
@@ -105,5 +109,3 @@
   Traceback (most recent call last):
   ...
   ValueError: Path is not a directory: .../kss/base/__init__.py
-
-

Modified: kukit/kss.base/trunk/kss/base/tests.py
==============================================================================
--- kukit/kss.base/trunk/kss/base/tests.py      (original)
+++ kukit/kss.base/trunk/kss/base/tests.py      Sat Oct 13 16:21:23 2007
@@ -1,5 +1,6 @@
 import unittest
 import doctest
+from kss.base.plugin import unload_plugins, activated_plugins
 
 def test_suite():
     suite = unittest.TestSuite((
@@ -7,6 +8,7 @@
             'README.txt', 'selectors.txt',
             'registry.txt', 'plugin.txt',
             'commands.txt', 'corecommands.txt',
+            'javascript.txt',
             package='kss.base',
             optionflags=doctest.ELLIPSIS|doctest.REPORT_ONLY_FIRST_FAILURE,
         ),
_______________________________________________
Kukit-checkins mailing list
[email protected]
http://codespeak.net/mailman/listinfo/kukit-checkins

Reply via email to