summaryrefslogtreecommitdiff
path: root/mail/pyzor/files/patch-7afe0ae.patch
blob: 21cfd2b76adc9e6e014a9d359a8a8972498e39e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
partial:

From 7afe0aedc320dd2689bfbf45e97fdb09adb89686 Mon Sep 17 00:00:00 2001
From: Alexandru Chirila <alex@alexkiro.com>
Date: Fri, 15 Jan 2016 12:30:39 +0200
Subject: [PATCH] Refs. #46. Fix all unitest for Python3.

Adjust all the unittest and code to pass on  Python3
without any 2to3 conversion (even without the
python-future library installed).
---
 pyzor/client.py                            |  6 ++--
 pyzor/digest.py                            |  2 +-
 pyzor/engines/common.py                    |  4 +--
 pyzor/engines/gdbm_.py                     |  2 +-
 pyzor/engines/mysql.py                     |  2 +-
 pyzor/server.py                            |  4 +--
 scripts/pyzor                              |  4 +--
 scripts/pyzord                             |  2 +-

| ------------------------------------------ |
| removed from original patch:
|
| scripts/run_tests                          |  5 ++--
| tests/benchmark/measure_server_response.py |  8 ++---
| tests/functional/test_pyzor.py             | 22 +++++++-------
| tests/unit/test_account.py                 | 35 +++++++++++-----------
| tests/unit/test_config.py                  |  7 +++--
| tests/unit/test_engines/test_gdbm.py       |  2 +-
| tests/unit/test_forwarder.py               |  2 +-
| tests/unit/test_server.py                  |  9 ++++--
| tests/util/__init__.py                     |  8 ++---
| web/application.py                         |  4 +--
| ------------------------------------------ |
 18 files changed, 67 insertions(+), 61 deletions(-)

diff --git a/pyzor/client.py b/pyzor/client.py
index 82d6361..07daba2 100644
--- pyzor/client.py
+++ pyzor/client.py
@@ -78,7 +78,7 @@ def __init__(self, accounts=None, timeout=None, spec=None):
         if accounts is None:
             accounts = {}
         self.accounts = dict(((host, int(port)), account)
-                             for (host, port), account in accounts.iteritems())
+                             for (host, port), account in accounts.items())
         if spec is None:
             spec = pyzor.digest.digest_spec
         self.spec = spec
@@ -227,12 +227,12 @@ def flush(self):
 
     def force(self):
         """Force send any remaining reports."""
-        for address, msg in self.r_requests.iteritems():
+        for address, msg in self.r_requests.items():
             try:
                 self.send(msg, address)
             except:
                 continue
-        for address, msg in self.w_requests.iteritems():
+        for address, msg in self.w_requests.items():
             try:
                 self.send(msg, address)
             except:
diff --git a/pyzor/digest.py b/pyzor/digest.py
index 100a4c6..058c208 100644
--- pyzor/digest.py
+++ pyzor/digest.py
@@ -105,7 +105,7 @@ def handle_atomic(self, lines):
     def handle_pieced(self, lines, spec):
         """Digest stuff according to the spec."""
         for offset, length in spec:
-            for i in xrange(length):
+            for i in range(length):
                 try:
                     line = lines[int(offset * len(lines) // 100) + i]
                 except IndexError:
diff --git a/pyzor/engines/common.py b/pyzor/engines/common.py
index a96c656..17f083c 100644
--- pyzor/engines/common.py
+++ pyzor/engines/common.py
@@ -31,7 +31,7 @@ def __init__(self, r_count=0, wl_count=0, r_entered=None,
 
     def wl_increment(self):
         # overflow prevention
-        if self.wl_count < sys.maxint:
+        if self.wl_count < sys.maxsize:
             self.wl_count += 1
         if self.wl_entered is None:
             self.wl_entered = datetime.datetime.now()
@@ -39,7 +39,7 @@ def wl_increment(self):
 
     def r_increment(self):
         # overflow prevention
-        if self.r_count < sys.maxint:
+        if self.r_count < sys.maxsize:
             self.r_count += 1
         if self.r_entered is None:
             self.r_entered = datetime.datetime.now()
diff --git a/pyzor/engines/gdbm_.py b/pyzor/engines/gdbm_.py
index d9415ba..e75fbd3 100644
--- pyzor/engines/gdbm_.py
+++ pyzor/engines/gdbm_.py
@@ -75,7 +75,7 @@ def items(self):
     def apply_method(self, method, varargs=(), kwargs=None):
         if kwargs is None:
             kwargs = {}
-        return apply(method, varargs, kwargs)
+        return method(*varargs, **kwargs)
 
     def __getitem__(self, key):
         return self.apply_method(self._really_getitem, (key,))
diff --git a/pyzor/engines/mysql.py b/pyzor/engines/mysql.py
index baef14d..f8d893d 100644
--- pyzor/engines/mysql.py
+++ pyzor/engines/mysql.py
@@ -294,7 +294,7 @@ def _safe_call(self, name, method, args):
     def reconnect(self):
         if not self.bound:
             return
-        for _ in xrange(self.bound):
+        for _ in range(self.bound):
             self.db_queue.put(self._get_new_connection())
 
     def _reconnect(self, db):
diff --git a/pyzor/server.py b/pyzor/server.py
index abae192..b342222 100644
--- pyzor/server.py
+++ pyzor/server.py
@@ -137,7 +137,7 @@ def __init__(self, address, database, passwd_fn, access_fn, prefork=4):
     def serve_forever(self, poll_interval=0.5):
         """Fork the current process and wait for all children to finish."""
         pids = []
-        for dummy in xrange(self._prefork):
+        for dummy in range(self._prefork):
             database = self.database.next()
             pid = os.fork()
             if not pid:
@@ -312,7 +312,7 @@ def handle_pong(self, digests):
         This command returns maxint for report counts and 0 whitelist.
         """
         self.server.log.debug("Request pong for %s", digests[0])
-        self.response["Count"] = "%d" % sys.maxint
+        self.response["Count"] = "%d" % sys.maxsize
         self.response["WL-Count"] = "%d" % 0
 
     def handle_check(self, digests):
diff --git a/scripts/pyzor b/scripts/pyzor
index 19b1d21..040b4c5 100755
--- scripts/pyzor
+++ scripts/pyzor
@@ -110,7 +110,7 @@ def load_configuration():
     config = ConfigParser.ConfigParser()
     # Set the defaults.
     config.add_section("client")
-    for key, value in defaults.iteritems():
+    for key, value in defaults.items():
         config.set("client", key, value)
     # Override with the configuration.
     config.read(os.path.join(options.homedir, "config"))
@@ -372,7 +372,7 @@ def genkey(client, servers, config, hash_func=hashlib.sha1):
         return False
     # pylint: disable-msg=W0612
     salt = "".join([chr(random.randint(0, 255))
-                    for unused in xrange(hash_func(b"").digest_size)])
+                    for unused in range(hash_func(b"").digest_size)])
     if sys.version_info >= (3, 0):
         salt = salt.encode("utf8")
     salt_digest = hash_func(salt)
diff --git a/scripts/pyzord b/scripts/pyzord
index 7b073a7..3ac7a2c 100755
--- scripts/pyzord
+++ scripts/pyzord
@@ -244,7 +244,7 @@ def load_configuration():
     config = ConfigParser.ConfigParser()
     # Set the defaults.
     config.add_section("server")
-    for key, value in defaults.iteritems():
+    for key, value in defaults.items():
         config.set("server", key, value)
     # Override with the configuration.
     config.read(os.path.join(options.homedir, "config"))