Added GPL notice to Python code.
[doldaconnect.git] / lib / python / dolcon / __init__.py
index 0cb26ba..5ee9e40 100644 (file)
@@ -1,3 +1,20 @@
+#  Dolda Connect - Modular multiuser Direct Connect-style client
+#  Copyright (C) 2007 Fredrik Tolf <fredrik@dolda2000.com>
+#  
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#  
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#  
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
 from dolmod import *
 import os
 
@@ -25,7 +42,7 @@ def login(useauthless = True, **kw):
         select()
     return result[0]
 
-def mustconnect(host, port = -1):
+def mustconnect(host, revision = latest):
     """A convenience function for connect.
 
     This function will connect to the given host, perform a select
@@ -33,17 +50,19 @@ def mustconnect(host, port = -1):
     any of these steps fail, an exception is raised. If successful,
     the file descriptor for the server connection is returned.
     """
-    fd = connect(host, port)
+    fd = connect(host)
     while True:
         resp = getresp()
         if resp is not None and resp.getcmd() == u".connect":
             break
         select()
-    if resp.getcode() != 200:
+    if resp.getcode() != 201:
         raise RuntimeError, resp.intresp()[0][0]
+    if not checkproto(resp, revision):
+        raise RuntimeError, resp
     return fd
 
-def cnl(host = None, port = -1, useauthless = True, **kw):
+def cnl(host = None, useauthless = True, revision = latest, **kw):
     """A convenience function for connect and loginasync.
 
     This function will connect to the given server, or the server in
@@ -55,7 +74,7 @@ def cnl(host = None, port = -1, useauthless = True, **kw):
         host = os.getenv("DCSERVER")
     if host is None:
         host = "localhost"
-    fd = mustconnect(host, port)
+    fd = mustconnect(host, revision)
     err, reason = login(useauthless, **kw)
     if err != "success":
         raise RuntimeError, (err, reason)