commit 68ac4439a429c8bb4141792c6cb76a2a0d891415
Author: Shikhar Bhushan <shikhar@schmizz.net>
Date:   Wed Sep 23 16:15:07 2009 +0000

    miscellaneous code changes & removal of inline docu some places
    
    git-svn-id: http://ncclient.googlecode.com/svn/trunk@188 6dbcf712-26ac-11de-a2f3-1373824ab735

diff --git a/ncclient/capabilities.py b/ncclient/capabilities.py
index 0905708..3b9fcda 100644
--- a/ncclient/capabilities.py
+++ b/ncclient/capabilities.py
@@ -36,18 +36,19 @@ def schemes(url_uri):
 
 class Capabilities:
 
-    """Represents the set of capabilities for a NETCONF client or server.
-    Initialised with a list of capability URI's.
-
-    Presence of a capability can be checked with the *in* operations. In addition
+    """Represents the set of capabilities available to a NETCONF client or
+    server.
+    
+    Presence of a capability can be checked with the *in* operation. In addition
     to the URI, for capabilities of the form
     *urn:ietf:params:netconf:capability:$name:$version* their shorthand can be
     used as a key. For example, for
     *urn:ietf:params:netconf:capability:candidate:1.0* the shorthand would be
     *:candidate*. If version is significant, use *:candidate:1.0* as key.
     """
-
+    
     def __init__(self, capabilities):
+        "Initializes with a list of capability URI's"
         self._dict = {}
         for uri in capabilities:
             self._dict[uri] = _abbreviate(uri)
@@ -80,35 +81,8 @@ class Capabilities:
         "Remove a capability"
         if key in self._dict:
             del self._dict[key]
-
-    def check(self, key):
-        """Whether specified capability is present.
-
-        :arg key: URI or shorthand
-
-        .. note:
-            The *in* operation is the preferred form.
-        """
-        return key in self
-
+    
     def get_uri(self, shorthand):
         for uri, abbrs in self._dict.items():
             if shorthand in abbrs:
                 return uri
-
-#: :class:`Capabilities` object representing the capabilities currently supported by NCClient
-CAPABILITIES = Capabilities([
-    "urn:ietf:params:netconf:base:1.0",
-    "urn:ietf:params:netconf:capability:writable-running:1.0",
-    "urn:ietf:params:netconf:capability:candidate:1.0",
-    "urn:ietf:params:netconf:capability:confirmed-commit:1.0",
-    "urn:ietf:params:netconf:capability:rollback-on-error:1.0",
-    "urn:ietf:params:netconf:capability:startup:1.0",
-    "urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file,https,sftp",
-    "urn:ietf:params:netconf:capability:validate:1.0",
-    "urn:ietf:params:netconf:capability:xpath:1.0",
-    "urn:liberouter:params:netconf:capability:power-control:1.0"
-    "urn:ietf:params:netconf:capability:interleave:1.0"
-    #'urn:ietf:params:netconf:capability:notification:1.0', # TODO
-    
-])
diff --git a/ncclient/manager.py b/ncclient/manager.py
index 0705b9e..9a92b70 100644
--- a/ncclient/manager.py
+++ b/ncclient/manager.py
@@ -21,19 +21,23 @@ import transport
 import logging
 logger = logging.getLogger('ncclient.manager')
 
-def connect_ssh(*args, **kwds):
-    """Connect to NETCONF server over SSH. See :meth:`SSHSession.connect()
-    <ncclient.transport.SSHSession.connect>` for argument details.
 
-    :rtype: :class:`Manager`
-    """
-    session = transport.SSHSession(capabilities.CAPABILITIES)
-    session.load_known_hosts()
-    session.connect(*args, **kwds)
-    return Manager(session)
+#: :class:`Capabilities` object representing the capabilities currently supported by NCClient
+CAPABILITIES = capabilities.Capabilities([
+    "urn:ietf:params:netconf:base:1.0",
+    "urn:ietf:params:netconf:capability:writable-running:1.0",
+    "urn:ietf:params:netconf:capability:candidate:1.0",
+    "urn:ietf:params:netconf:capability:confirmed-commit:1.0",
+    "urn:ietf:params:netconf:capability:rollback-on-error:1.0",
+    "urn:ietf:params:netconf:capability:startup:1.0",
+    "urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file,https,sftp",
+    "urn:ietf:params:netconf:capability:validate:1.0",
+    "urn:ietf:params:netconf:capability:xpath:1.0",
+    "urn:liberouter:params:netconf:capability:power-control:1.0"
+    "urn:ietf:params:netconf:capability:interleave:1.0"
+    #'urn:ietf:params:netconf:capability:notification:1.0', # TODO    
+])
 
-#: Same as :meth:`connect_ssh`
-connect = connect_ssh
 
 OPERATIONS = {
     "get": operations.Get,
@@ -52,12 +56,18 @@ OPERATIONS = {
     "reboot_machine": operations.RebootMachine
 }
 
-class Manager(object):
 
-    """API for NETCONF operations.
+def connect_ssh(*args, **kwds):
+    session = transport.SSHSession(capabilities.CAPABILITIES)
+    session.load_known_hosts()
+    session.connect(*args, **kwds)
+    return Manager(session)
+
+#: Same as :meth:`connect_ssh`
+connect = connect_ssh
+
 
-    It is also a context manager, so a :class:`Manager` instance can be used
-    with the *with* statement. The session is closed when the context ends. """
+class Manager(object):
 
     def __init__(self, session):
         self._session = session
@@ -69,7 +79,7 @@ class Manager(object):
         return self
 
     def __exit__(self, *argss):
-        self.close()
+        self.close_session()
         return False
 
     def __getattr__(self, name):
@@ -83,56 +93,31 @@ class Manager(object):
                       raise_mode=self._raise_mode).request
     
     def locked(self, target):
-        """Returns a context manager for the *with* statement.
-
-        :arg target: name of the datastore to lock
-        :type target: `string`
-        :rtype: :class:`~ncclient.operations.LockContext`
-        """
         return operations.LockContext(self._session, target)
-
-    def close(self):
-        """Closes the NETCONF session. First does *<close-session>* RPC."""
-        try: # try doing it clean
-            self._async_mode = False
-            self.close_session()
-        except Exception as e:
-            logger.debug('error doing <close-session> -- %r' % e)
-        if self._session.connected: # if that didn't work, this sure will :)
-            self._session.close()
-
-    @property
-    def session(self):
-        ":class:`~ncclient.transport.Session` instance"
-        return self._session
-
+    
     @property
     def client_capabilities(self):
-        ":class:`~ncclient.capabilities.Capabilities` object for client"
         return self._session._client_capabilities
 
     @property
     def server_capabilities(self):
-        ":class:`~ncclient.capabilities.Capabilities` object for server"
         return self._session._server_capabilities
 
     @property
     def session_id(self):
-        "*<session-id>* as assigned by NETCONF server"
         return self._session.id
 
     @property
     def connected(self):
-        "Whether currently connected to NETCONF server"
         return self._session.connected
 
-    def set_async_mode(self, bool=True):
-        self._async_mode = bool
+    def set_async_mode(self, mode):
+        self._async_mode = mode
 
     def set_raise_mode(self, mode):
-        assert(choice in ('all', 'errors', 'none'))
+        assert(choice in ("all", "errors", "none"))
         self._raise_mode = mode
 
     async_mode = property(fget=lambda self: self._async_mode, fset=set_async_mode)
 
-    raise_mode = property(fget=set_raise_mode, fset=set_raise_mode)
+    raise_mode = property(fget=lambda self: self._raise_mode, fset=set_raise_mode)
diff --git a/ncclient/transport/ssh.py b/ncclient/transport/ssh.py
index 2391c73..bb1133f 100644
--- a/ncclient/transport/ssh.py
+++ b/ncclient/transport/ssh.py
@@ -178,8 +178,8 @@ class SSHSession(Session):
         """
 
         if username is None:
-            raise SSHError("No username specified")
-
+            username = getpass.getuser()
+        
         sock = None
         for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, socket.SOCK_STREAM):
             af, socktype, proto, canonname, sa = res
@@ -340,4 +340,3 @@ class SSHSession(Session):
         object. This makes it possible to call methods like set_keepalive on it.
         """
         return self._transport
-
