in a state of flux
authorShikhar Bhushan <shikhar@schmizz.net>
Thu, 23 Apr 2009 01:47:19 +0000 (01:47 +0000)
committerShikhar Bhushan <shikhar@schmizz.net>
Thu, 23 Apr 2009 01:47:19 +0000 (01:47 +0000)
git-svn-id: http://ncclient.googlecode.com/svn/trunk@45 6dbcf712-26ac-11de-a2f3-1373824ab735

ncclient/content.py [deleted file]
ncclient/content/__init__.py [new file with mode: 0644]
ncclient/operations/rpc.py [moved from ncclient/rpc.py with 91% similarity]
ncclient/session/listeners.py [moved from ncclient/listeners.py with 100% similarity]
ncclient/session/session.py [moved from ncclient/session.py with 100% similarity]
ncclient/session/ssh.py [moved from ncclient/ssh.py with 100% similarity]
ncclient/session/subject.py [moved from ncclient/subject.py with 100% similarity]

diff --git a/ncclient/content.py b/ncclient/content.py
deleted file mode 100644 (file)
index b67150d..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-# Copyright 2009 Shikhar Bhushan
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import logging
-from xml.etree import cElementTree as ElementTree
-from cStringIO import StringIO
-
-logger = logging.getLogger('ncclient.content')
-
-
-def qualify(tag, ns=None):
-    if ns is None:
-        return tag
-    else:
-        return '{%s}%s' % (ns, tag)
-_ = qualify
-
-################################################################################
-
-class Hello:
-    
-    NS = 'urn:ietf:params:xml:ns:netconf:base:1.0'
-    
-    @staticmethod
-    def build(capabilities, encoding='utf-8'):
-        hello = ElementTree.Element(_('hello', Hello.NS))
-        caps = ElementTree.Element('capabilities')
-        for uri in capabilities:
-            cap = ElementTree.Element('capability')
-            cap.text = uri
-            caps.append(cap)
-        hello.append(caps)
-        tree = ElementTree.ElementTree(hello)
-        fp = StringIO()
-        tree.write(fp, encoding)
-        return fp.getvalue()
-    
-    @staticmethod
-    def parse(raw):
-        'Returns tuple of (session-id, ["capability_uri", ...])'
-        id, capabilities = 0, []
-        root = ElementTree.fromstring(raw)
-        if root.tag == _('hello', Hello.NS):
-            for child in root.getchildren():
-                if child.tag == _('session-id', Hello.NS):
-                    id = int(child.text)
-                elif child.tag == _('capabilities', Hello.NS):
-                    for cap in child.getiterator(_('capability', Hello.NS)):
-                        capabilities.append(cap.text)
-        return id, capabilities
-
-################################################################################
-
-class RootElementParser:
-    
-    '''Parse the root element of an XML document. The tag and namespace of
-    recognized elements, and attributes of interest can be customized.
-    
-    RootElementParser does not parse any sub-elements.
-    '''
-    
-    def __init__(self, recognize=[]):
-        self._recognize = recognize
-    
-    def recognize(self, element):
-        '''Specify an element that should be successfully parsed.
-        
-        element should be a string that represents a qualified name of the form
-        *{namespace}tag*.
-        '''
-        self._recognize.append((element, attrs))
-    
-    def parse(self, raw):
-        '''Parse the root element from a string representing an XML document.
-        
-        Returns a (tag, attributes) tuple. tag is a string representing
-        the qualified name of the recognized element. attributes is a
-        {'attr': value} dictionary.
-        '''
-        fp = StringIO(raw)
-        for event, element in ElementTree.iterparse(fp, events=('start',)):
-            for e in self._recognize:
-                if element.tag == e:
-                    return (element.tag, element.attrib)
-            break
-        return None
-
-
-################################################################################
-
-class XMLBuilder:
-    
-    @staticmethod
-    def _element(spec):
-        element = ElementTree.Element(spec['tag'], spec.get('attrib', {}))
-        for child in spec.get('children', []):
-            element.append(XMLBuilder._element(child))
-        return element
-    
-    @staticmethod
-    def _etree(spec):
-        return ElementTree.ElementTree(XMLBuilder._element(spec))
-    
-    @staticmethod
-    def build(spec, encoding='utf-8'):
-        fp = StringIO()
-        XMLBuilder._etree(spec).write(fp, encoding)
-        return fp.get_value()
diff --git a/ncclient/content/__init__.py b/ncclient/content/__init__.py
new file mode 100644 (file)
index 0000000..496c4cf
--- /dev/null
@@ -0,0 +1,26 @@
+# Copyright 2009 Shikhar Bhushan
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+'This module serves as an XML abstraction layer'
+
+class ContentError(Exception):
+    pass
+
+def qualify(tag, namespace=None):
+    'Returns qualified name of form `{namespace}tag`'
+    if namespace is None:
+        return tag
+    else:
+        return '{%s}%s' % (namespace, tag)
+_ = qualify
similarity index 91%
rename from ncclient/rpc.py
rename to ncclient/operations/rpc.py
index 2fe5ffb..4135cde 100644 (file)
@@ -39,9 +39,9 @@ class RPC:
         self._reply = reply
         self._event.set()
     
-    def _do_request(self, op):
-        self._session.send(content.make_rpc(self._id, op))
-        # content.make(RPC, attrs={'message-id': self._id}, children=(op,))
+    def _do_request(self, operation):
+        'operation is xml string'
+        self._session.send(content.RPC.make(self._id, operation))
         if not self._async:
             self._reply_event.wait()
         return self._reply
similarity index 100%
rename from ncclient/ssh.py
rename to ncclient/session/ssh.py