Commits

pystew committed 0a45f82

upd

  • Participants
  • Parent commits 7088c86

Comments (0)

Files changed (3)

 
  You shouldn't have to worry about tcp.py, api.Protocol is the class where you would implement missing parts of the low level Citadel Protocol and citadel.py should be the only module you need to import and adapt to your needs.
 
- When you instenciate the Citadel class, you must pass it a config object (this is typically a module, but it doesn't have to).
- The config obect may the following attributes:
-  . server_adr  : the Citadel server adr  (mandatory)
-  . server_prt  : the Citadel server port (mandatory)
-  . admin_login : admin login             (optionnal)
-  . admin_psw   : admin password          (optionnal)
-  . log         : log file                (optionnal)
+ When you instenciate the Citadel class, you may pass it a config object (typically a module).
+ The config obect may have the following attributes:
+  . server_adr  : the Citadel server adr
+  . server_prt  : the Citadel server port
+  . admin_login : admin login           
+  . admin_psw   : admin password       
+  . log         : log file            
+If server_adr is omitted localhost will be used, server_prt defaults to 504.
 If admin login or password are not specified, you will be asked for them as needed.
 If log is not specified (or evaluate to False) nothing will be logged.
 import tpl
 
 class Citadel(api.Protocol):
-    def __init__(self, config):
+    def __init__(self, config=None):
         self.config = config
         api.Protocol.__init__(self)
     @property
 
 class Client(object):
     def __init__(self):
+        cfg = self.config
+        self.logf = hasattr(cfg, 'log') and cfg.log
+        self.sadr = hasattr(cfg, 'server_adr') and cfg.server_adr or '127.0.0.1'
+        self.sprt = hasattr(cfg, 'server_prt') and cfg.server_prt or 504
         self.sock = self.connect(self.config.server_adr, self.config.server_prt)
         rf = self.sock.makefile('rb', -1)
         wf = self.sock.makefile('wb', 0)
         self.read = rf.readline
         self.write = wf.write
-        self.logfil = hasattr(self.config, 'log') and self.config.log
         c, a = self.get()
         self.log(a[0], 'w')
     def log(self, txt, mode='a'):
-        if hasattr(self, 'logfil'):
-            log = open(self.logfil, mode)
+        if hasattr(self, 'logf'):
+            log = open(self.logf, mode)
             log.write('%s\n'%txt)
             log.close
     def connect(self, adr, port):