[Nym3-commit] r354 - trunk/nymbaron/Server

laurent at conuropsis.org laurent at conuropsis.org
Fri Oct 14 22:12:06 CEST 2005


Author: laurent
Date: 2005-10-14 22:12:05 +0200 (Fri, 14 Oct 2005)
New Revision: 354

Modified:
   trunk/nymbaron/Server/Main.py
   trunk/nymbaron/Server/User.py
Log:
Load config only in Main and make it an argument to the User constructor.


Modified: trunk/nymbaron/Server/Main.py
===================================================================
--- trunk/nymbaron/Server/Main.py	2005-10-14 19:52:49 UTC (rev 353)
+++ trunk/nymbaron/Server/Main.py	2005-10-14 20:12:05 UTC (rev 354)
@@ -45,12 +45,13 @@
     import os
     os.stat(Config.SYSFILE)
     config = Config.Config(Config.SYSFILE)
-except:
+except OSError:
     try:
 	import os
 	os.stat(Config.userfile())
 	config = Config.Config(Config.userfile())
-    except: pass
+    except OSError:
+	config = Config.Config()
 
 def processIncoming(localpart, msg):
     """Process incoming mail from the MTA
@@ -58,7 +59,7 @@
     - checks whether the new mail violates its quota
     - finally stores the message """
     try:
-	nymuser = User.User(localpart)
+	nymuser = User.User(localpart, config)
     except User.NoSuchUser:
 	print "No such user " + localpart
 	sys.exit(73)
@@ -99,11 +100,11 @@
 			#the Create command
 			for pnym in com.list:
 			    try:
-				nymUser = User.User(pnym,1)
+				nymUser = User.User(pnym, config, 1)
 			    except User.AlreadySuchUser:
 				#a nym pnym has been created : check it
 				#doesn't relate to the creat being processed
-				nymUser = User.User(pnym, 0)
+				nymUser = User.User(pnym, config, 0)
 				if nymUser['inidgst'] == mdgst:
 				    #it does: we resend the challenge
 				    #and quit
@@ -173,7 +174,7 @@
 		   sys.exit(2) #TODO smart error code
 	else: # NYM is not empty
 	    try:
-		nymUser = User.User(h.nym)
+		nymUser = User.User(h.nym, config)
 	    except User.NoSuchUser:
 		print "No such user %s" % h.nym
 		sys.exit(73) #TODO is it the smart error code

Modified: trunk/nymbaron/Server/User.py
===================================================================
--- trunk/nymbaron/Server/User.py	2005-10-14 19:52:49 UTC (rev 353)
+++ trunk/nymbaron/Server/User.py	2005-10-14 20:12:05 UTC (rev 354)
@@ -46,8 +46,6 @@
               'sent-in-full' : 2, 'deleted' : 3 }
 """The life cycle of a mail received by a nym"""
 
-config = Config.Config()
-
 class NoSuchUser(Exception): pass
 """Exception thrown when a user account identified by its nym can't be found
 """
@@ -108,12 +106,13 @@
     
 class User:
     """Hold user data"""
-    def __init__(self, username, create = 0):
+    def __init__(self, username, config, create = 0):
         """0 : load user data throw an error if the user doesn't exist
         1 : create user data throw an error if the user exists
         _ : load a user data, if it doesn't exist create a new user silently
 	"""
         self.datafile = config.path + os.sep + username + '.dat'
+	self.config = config
 	self.username = username
 	self.index = None
 	self.mbox = None
@@ -158,7 +157,7 @@
 
     def _lock(self):
 	"""Lock the user. For well behaved functions."""
-	self.lock = mixminion.Common.Lockfile(config.path + os.sep + 
+	self.lock = mixminion.Common.Lockfile(self.config.path + os.sep + 
 					      self.username + '.lck')
 	self.lock.acquire(blocking = 1)
 
@@ -271,7 +270,7 @@
     def surbfile(self):
 	"""Gets the path to file containing the surbs to send messages to the nymholder
 	"""
-	return config.path + os.sep + self.data['username'] + '.surbs'
+	return self.config.path + os.sep + self.data['username'] + '.surbs'
 
     def advanced_send(self, msg, add_status = True):
 	"""Sends a message to the nymholder through the mixminion network,
@@ -320,7 +319,7 @@
     def send(self, msg):
 	"""Sends a message to the nymholder through the mixminion network,
 	using the surbs provided by the nymholder"""
-        if config.DEBUG:
+        if self.config.DEBUG:
             print msg
             return 0
         else:
@@ -414,7 +413,7 @@
 
     def mboxfile(self):
 	"""Gets the mailbox file name"""
-	return config.path + os.sep + self.data['username'] + '.mbox'
+	return self.config.path + os.sep + self.data['username'] + '.mbox'
 
     def _save_mbox(self):
 	"""Flushs the mailbox to the disk"""
@@ -426,11 +425,11 @@
 
     def synboxfile(self):
 	"""Gets the synbox file name"""
-	return config.path + os.sep + self.data['username'] + '.syn'
+	return self.config.path + os.sep + self.data['username'] + '.syn'
 
     def indexfile(self):
 	"""Gets the index filename"""
-	return config.path + os.sep + self.data['username'] + '.idx'
+	return self.config.path + os.sep + self.data['username'] + '.idx'
 	
     def load_synbox(self):
 	"""Loads the synbox, structure containing synopses, from the disk"""



More information about the Nym3-commit mailing list