From 25f7acba421408b9dcb3df4df64669e1b849cf7b Mon Sep 17 00:00:00 2001 From: Michel Oosterhof Date: Wed, 4 Nov 2015 23:52:32 +0400 Subject: [PATCH] move open to with open. tabs to spaces --- cowrie/core/auth.py | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/cowrie/core/auth.py b/cowrie/core/auth.py index 188e263..b00b75f 100644 --- a/cowrie/core/auth.py +++ b/cowrie/core/auth.py @@ -24,30 +24,28 @@ class UserDB(object): load the user db """ - f = open(self.userdb_file, 'r') - while True: - line = f.readline() - if not line: - break + with open(self.userdb_file, 'r') as f: + while True: + line = f.readline() + if not line: + break - line = string.strip(line) - if not line: - continue + line = string.strip(line) + if not line: + continue - if line.startswith('#'): - continue + if line.startswith('#'): + continue - (login, uid_str, passwd) = line.split(':', 2) + (login, uid_str, passwd) = line.split(':', 2) - uid = 0 - try: - uid = int(uid_str) - except ValueError: - uid = 1001 + uid = 0 + try: + uid = int(uid_str) + except ValueError: + uid = 1001 - self.userdb.append((login, uid, passwd)) - - f.close() + self.userdb.append((login, uid, passwd)) def save(self): """ @@ -55,10 +53,9 @@ class UserDB(object): """ # Note: this is subject to races between cowrie instances, but hey ... - f = open(self.userdb_file, 'w') - for (login, uid, passwd) in self.userdb: - f.write('%s:%d:%s\n' % (login, uid, passwd)) - f.close() + with open(self.userdb_file, 'w') as f: + for (login, uid, passwd) in self.userdb: + f.write('%s:%d:%s\n' % (login, uid, passwd)) def checklogin(self, thelogin, thepasswd, src_ip='0.0.0.0'): """