[Nym3-commit] r451 - trunk/nymbaron/Server
laurent at conuropsis.org
laurent at conuropsis.org
Sun Feb 5 19:16:22 CET 2006
Author: laurent
Date: 2006-02-05 19:16:21 +0100 (Sun, 05 Feb 2006)
New Revision: 451
Modified:
trunk/nymbaron/Server/User.py
Log:
Style issues, remove unused modules / variables.
Modified: trunk/nymbaron/Server/User.py
===================================================================
--- trunk/nymbaron/Server/User.py 2006-02-05 17:58:58 UTC (rev 450)
+++ trunk/nymbaron/Server/User.py 2006-02-05 18:16:21 UTC (rev 451)
@@ -42,7 +42,6 @@
from nymbaron.Common import binsearch
from nymbaron.Message import intToStrBE
-import nymbaron.Server.Config as Config
import nymbaron.Mail as Mail
import nymbaron.Crypto as Crypto
import nymbaron.Message as Message
@@ -54,11 +53,13 @@
'sent-in-full' : 2, 'deleted' : 3 }
"""The life cycle of a mail received by a nym"""
-class NoSuchUser(Exception): pass
+class NoSuchUser(Exception):
+ pass
"""Exception thrown when a user account identified by its nym can't be found
"""
-class AlreadySuchUser(Exception): pass
+class AlreadySuchUser(Exception):
+ pass
"""Exception thrown when a user account identified by its nym already exists
"""
@@ -162,7 +163,8 @@
self.data = None
self.lock = None
self._abort = False
- try: self._lock()
+ try:
+ self._lock()
except OSError: # Can happen for invalid usernames.
# TODO : validate username against sensible pattern.
raise NoSuchUser()
@@ -175,7 +177,8 @@
self.data = pickle.load(f)
f.close()
except IOError:
- if create == 0: raise NoSuchUser()
+ if create == 0:
+ raise NoSuchUser()
self.data = config.default_settings
self.data['username'] = username
self.data['received'] = []
@@ -209,7 +212,8 @@
def _release(self):
"""Releases the lock"""
- if self.lock: self.lock.release()
+ if self.lock:
+ self.lock.release()
def abort(self):
"""permit to destroy a User object without saving its data
@@ -260,7 +264,8 @@
def blobify(self, l):
"""encrypts a set of synopses
l is a list of tuples (mid, status, synopsis) """
- if len(l) == 0: return None
+ if len(l) == 0:
+ return None
s = ""
m = []
for mid, status, syn in l:
@@ -277,7 +282,8 @@
too."""
self.load_synbox()
for i, (midlist, status, synblob) in enumerate(self.syn):
- if mid in midlist: return i, (midlist, status, synblob)
+ if mid in midlist:
+ return i, (midlist, status, synblob)
raise ValueError()
def getMail(self, mid):
@@ -297,18 +303,21 @@
ret = []
#TODO if the mid can't be found in the index tab, what do we do?
- if mid == Mail.oldestMid: ret = self.index.keys()
+ if mid == Mail.oldestMid:
+ ret = self.index.keys()
else:
midtime = self.index[mid]['time']
for msg in self.index.keys():
- if self.index[msg]['time'] > midtime: ret.append(msg)
+ if self.index[msg]['time'] > midtime:
+ ret.append(msg)
ret.sort(self.timecmp)
return ret
def _save_data(self):
"""Flush to the disk the non message related data contained by this User object
"""
- if self.data == None: return
+ if self.data == None:
+ return
f = open(self.datafile, 'w')
pickle.dump(self.data, f)
f.close()
@@ -333,7 +342,7 @@
#determine the status elements, the number of surbs is assumed
#to stay equal to its value
self.load_index()
- for mid, v in self.index.iteritems():
+ for _, v in self.index.iteritems():
if v['status'] in [lifeCycle['nothing-sent'], lifeCycle['synopsis-sent']]:
nMsg += 1
usage = self.usage()
@@ -448,7 +457,8 @@
def load_mbox(self):
"""Loads the mailbox from the disk"""
- if not self.mbox == None: return
+ if not self.mbox == None:
+ return
mbox = self.mboxfile()
try:
f = open(mbox, 'r')
@@ -463,7 +473,8 @@
def _save_mbox(self):
"""Flushs the mailbox to the disk"""
- if self.mbox == None: return
+ if self.mbox == None:
+ return
mbox = self.mboxfile()
f = open(mbox, 'w')
pickle.dump(self.mbox, f)
@@ -479,7 +490,8 @@
def load_synbox(self):
"""Loads the synbox, structure containing synopses, from the disk"""
- if not self.syn == None: return
+ if not self.syn == None:
+ return
synbox = self.synboxfile()
try:
f = open(synbox, 'r')
@@ -490,7 +502,8 @@
def _save_synbox(self):
"""Flushs the synbox to the disk"""
- if self.syn == None: return
+ if self.syn == None:
+ return
synbox = self.synboxfile()
f = open(synbox, 'w')
pickle.dump(self.syn, f)
@@ -499,7 +512,8 @@
def load_index(self):
"""Loads the index, a structure associating to a message of given mid
the time of its arrival and its position in the lifecycle"""
- if not self.index == None: return
+ if not self.index == None:
+ return
index = self.indexfile()
try:
f = open(index, 'r')
@@ -510,7 +524,8 @@
def _save_index(self):
"""Flushes the index to the disk"""
- if self.index == None: return
+ if self.index == None:
+ return
index = self.indexfile()
f = open(index, 'w')
pickle.dump(self.index, f)
@@ -524,8 +539,9 @@
self.load_mbox()
self.load_index()
mid = Mail.genMid()
- while self.index.has_key(mid): mid = Mail.genMid()
- self.mbox[mid] = Crypto.nym_encrypt(msg,self.data['encKey'])
+ while self.index.has_key(mid):
+ mid = Mail.genMid()
+ self.mbox[mid] = Crypto.nym_encrypt(msg, self.data['encKey'])
# store the synopsis
self.load_synbox()
self.syn.append(([mid], 'clear', syn))
@@ -538,14 +554,16 @@
"""Deletes a stored message. Delete the synopsis if possible"""
self.load_index()
- if not self.index.has_key(mid): return
+ if not self.index.has_key(mid):
+ return
self.load_mbox()
- if self.mbox.has_key(mid): del self.mbox[mid]
+ if self.mbox.has_key(mid):
+ del self.mbox[mid]
self.index[mid]['status'] = lifeCycle['deleted']
self.load_synbox()
try:
- i, (sl, enc, blurb) = self.getSyn(mid)
+ i, (sl, _, _) = self.getSyn(mid)
except ValueError: return
candelete = True
for omid in sl:
@@ -554,7 +572,8 @@
break
if candelete:
del self.syn[i]
- for omid in sl: del self.index[omid]
+ for omid in sl:
+ del self.index[omid]
def setKeys(self, kid, kenc):
"""Set the identity and encryption key of the user, ASN.1 encoded"""
@@ -603,14 +622,14 @@
offset = firstclear
last = len(self.syn)
size = last - offset
- lastchunk = size % maxSynPerBlob
while offset + maxSynPerBlob < last:
self.encryptSyn(offset, offset + maxSynPerBlob)
offset = offset + 1
last = last - maxSynPerBlob
- if offset + 1 >= last: return
+ if offset + 1 >= last:
+ return
# See if among the few remaining synopses, some are considered
# too old
try:
@@ -622,7 +641,7 @@
fyoung = last
self.encryptSyn(offset, fyoung)
- def markMid(self,l,mark):
+ def markMid(self, l, mark):
"""The status of the mids in l which had a status
previous to mark in the lifeCycle are set to mark"""
if l:
@@ -645,7 +664,7 @@
no more than `num'. May change the synbox if encryption is
necessary."""
def bfprepare(t):
- bfl = map(self.hasMail, t[0])
+ bfl = [self.hasMail(i) for i in t[0]]
u = (t[0], Mail.bf(bfl), t[2])
return u
#load the structures
@@ -654,7 +673,8 @@
self.load_mbox()
# Prepare the midList.
midList = self.midAfter(after)[:num]
- if len(midList) == 0: return []
+ if len(midList) == 0:
+ return []
ret = []
# Hold the clear syn
clearlist = []
@@ -669,7 +689,7 @@
print str(self.syn)
print "Doh. Exception."
return ret
- if (u[1] == 'clear'):
+ if u[1] == 'clear':
clearlist.append(u)
del self.syn[i]
del midList[0]
@@ -680,11 +700,13 @@
nsyn += 8
clearlist = []
continue
- elif (u[1] == 'encrypted'):
+ elif u[1] == 'encrypted':
for i in u[0]:
- if i in midList: midList.remove(i)
+ if i in midList:
+ midList.remove(i)
# Can we afford to add this blob?
- if len(u[0]) + nsyn + len(clearlist) > num: continue
+ if len(u[0]) + nsyn + len(clearlist) > num:
+ continue
ret.append(bfprepare(u))
if clearlist:
foo = self.blobify(clearlist)
More information about the Nym3-commit
mailing list