more doc updates
[ncclient] / ncclient / operations / retrieve.py
index ddea328..2c155a9 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from ncclient.rpc import RPC, RPCReply
+from rpc import RPC, RPCReply
 
-from ncclient import content
+from ncclient.xml_ import *
 
 import util
 
-# NOTES
-# - consider class for helping define <filter> for Get/GetConfig??
-
 class GetReply(RPCReply):
-    
-    'Adds data attribute'
-    
-    # tested: no
-    # combed: yes
-    
+
+    """Adds attributes for the *data* element to `RPCReply`."""
+
     def _parsing_hook(self, root):
         self._data = None
         if not self._errors:
-            self._data = content.namespaced_find(root, 'data')
+            self._data = root.find(qualify("data"))
     
     @property
-    def data_element(self):
+    def data_ele(self):
+        "*data* element as an :class:`~xml.etree.ElementTree.Element`"
         if not self._parsed:
             self.parse()
         return self._data
-    
+
     @property
     def data_xml(self):
-        return content.element2string(self.data_element)
+        "*data* element as an XML string"
+        if not self._parsed:
+            self.parse()
+        return to_xml(self._data)
     
-    data = data_element
+    data = data_ele
+    "Same as :attr:`data_ele`"
+
 
 class Get(RPC):
-    
-    # tested: no
-    # combed: yes
-    
-    SPEC = {
-        'tag': 'get',
-        'subtree': []
-    }
-    
+
+    "The *get* RPC."
+
     REPLY_CLS = GetReply
-    
+    "See :class:`GetReply`."
+
     def request(self, filter=None):
-        spec = Get.SPEC.copy()
+        """Retrieve running configuration and device state information.
+
+        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
+
+        :seealso: :ref:`filter_params`
+        """
+        node = new_ele("get")
         if filter is not None:
-            spec['subtree'].append(util.build_filter(*filter))
-        return self._request(spec)
+            node.append(util.build_filter(filter))
+        return self._request(node)
+
 
 class GetConfig(RPC):
 
-    # tested: no
-    # combed: yes
-    
-    SPEC = {
-        'tag': 'get-config',
-        'subtree': []
-    }
-    
+    "The *get-config* RPC."
+
     REPLY_CLS = GetReply
-    
-    def request(self, source=None, source_url=None, filter=None):
-        """
-        `filter` has to be a tuple of (type, criteria)
-        The type may be one of 'xpath' or 'subtree'
-        The criteria may be an ElementTree.Element, an XML fragment, or tree specification
-        """
-        spec = GetConfig.SPEC.copy()
-        spec['subtree'].append({
-            'tag': 'source',
-            'subtree': util.store_or_url(source, source_url)
-            })
+    "See :class:`GetReply`."
+
+    def request(self, source, filter=None):
+        """Retrieve all or part of a specified configuration.
+
+        *source* name of the configuration datastore being queried
+
+        *filter* specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)
+
+        :seealso: :ref:`filter_params`"""
+        node = new_ele("get-config")
+        node.append(util.datastore_or_url("source", source, self._assert))
         if filter is not None:
-            spec['subtree'].append(util.build_filter(*filter))
-        return self._request(spec)
+            node.append(util.build_filter(filter))
+        return self._request(node)
\ No newline at end of file