Skip to content

Commit 1a1cd4c

Browse files
committed
Convert to Python3
1 parent 5ef01b1 commit 1a1cd4c

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

darts/lib/utils/lru.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"""Trivial LRU-Dictionary implementation
2525
"""
2626

27-
from __future__ import with_statement
27+
2828

2929
import sys
3030
from threading import RLock, Lock, Condition, Thread
@@ -234,7 +234,7 @@ def __iter__(self):
234234
See `iterkeys`.
235235
"""
236236

237-
return self.__index.iterkeys()
237+
return iter(self.__index.keys())
238238

239239
def iterkeys(self):
240240

@@ -249,7 +249,7 @@ def iterkeys(self):
249249
priority in any way.
250250
"""
251251

252-
return self.__index.iterkeys()
252+
return iter(self.__index.keys())
253253

254254
def itervalues(self):
255255

@@ -264,7 +264,7 @@ def itervalues(self):
264264
priority in any way.
265265
"""
266266

267-
for item in self.__index.itervalues():
267+
for item in self.__index.values():
268268
yield item._value
269269

270270
def iteritems(self):
@@ -280,7 +280,7 @@ def iteritems(self):
280280
*not* reflect the LRU priority in any way.
281281
"""
282282

283-
for key, item in self.__index.iteritems():
283+
for key, item in self.__index.items():
284284
yield key, item._value
285285

286286
def __delitem__(self, key):
@@ -629,7 +629,7 @@ def __iter__(self):
629629
See `iterkeys`.
630630
"""
631631

632-
return self.iterkeys()
632+
return iter(self.keys())
633633

634634
def iterkeys(self):
635635

@@ -649,7 +649,7 @@ def iterkeys(self):
649649
"""
650650

651651
with self.__lock:
652-
return iter(tuple(self.__dict.iterkeys()))
652+
return iter(tuple(self.__dict.keys()))
653653

654654
def itervalues(self):
655655
"""Iterator for all values of this dictionary
@@ -668,7 +668,7 @@ def itervalues(self):
668668
"""
669669

670670
with self.__lock:
671-
return iter(tuple(self.__dict.itervalues()))
671+
return iter(tuple(self.__dict.values()))
672672

673673
def iteritems(self):
674674

@@ -688,7 +688,7 @@ def iteritems(self):
688688
"""
689689

690690
with self.__lock:
691-
return iter(tuple(self.__dict.iteritems()))
691+
return iter(tuple(self.__dict.items()))
692692

693693
def __getitem__(self, key):
694694

@@ -846,7 +846,7 @@ def clear(self, discard_loads=False):
846846
self.__cache.clear()
847847
if discard_loads:
848848
conditions = list()
849-
keys = tuple(self.__loading.iterkeys())
849+
keys = tuple(self.__loading.keys())
850850
for k in keys:
851851
placeholder = self.__loading.pop(k)
852852
if placeholder._state is loading:
@@ -1037,7 +1037,7 @@ def clear(self, discard_loads=False):
10371037
self.__cache.clear()
10381038
if discard_loads:
10391039
conditions = list()
1040-
keys = tuple(self.__loading.iterkeys())
1040+
keys = tuple(self.__loading.keys())
10411041
for k in keys:
10421042
placeholder = self.__loading.pop(k)
10431043
if placeholder._state is loading:

doc/conf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
master_doc = 'index'
4141

4242
# General information about the project.
43-
project = u'dart.utils.lru'
44-
copyright = u'2010, Deterministic Arts'
43+
project = 'dart.utils.lru'
44+
copyright = '2010, Deterministic Arts'
4545

4646
# The version info for the project you're documenting, acts as replacement for
4747
# |version| and |release|, also used in various other places throughout the
@@ -178,8 +178,8 @@
178178
# Grouping the document tree into LaTeX files. List of tuples
179179
# (source start file, target name, title, author, documentclass [howto/manual]).
180180
latex_documents = [
181-
('index', 'dartutilslru.tex', u'dart.utils.lru Documentation',
182-
u'Deterministic Arts', 'manual'),
181+
('index', 'dartutilslru.tex', 'dart.utils.lru Documentation',
182+
'Deterministic Arts', 'manual'),
183183
]
184184

185185
# The name of an image file (relative to this directory) to place at the top of
@@ -211,6 +211,6 @@
211211
# One entry per manual page. List of tuples
212212
# (source start file, name, description, authors, manual section).
213213
man_pages = [
214-
('index', 'dartutilslru', u'dart.utils.lru Documentation',
215-
[u'Deterministic Arts'], 1)
214+
('index', 'dartutilslru', 'dart.utils.lru Documentation',
215+
['Deterministic Arts'], 1)
216216
]

test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_concurrent_access(self):
5656

5757
iterations_per_thread = 1000
5858
number_of_threads = 100
59-
key_range = range(4)
59+
key_range = list(range(4))
6060

6161
loads_lock = RLock()
6262
loads = dict()
@@ -92,7 +92,7 @@ def reader():
9292
with start_lock:
9393
while not start_now:
9494
start_condition.wait()
95-
for k in xrange(iterations_per_thread):
95+
for k in range(iterations_per_thread):
9696
for i in shuffled(key_range):
9797
answer = cache.load(i)
9898
self.assertEqual("R(%r)" % (i,), answer)
@@ -102,7 +102,7 @@ def reader():
102102

103103
with start_lock:
104104

105-
for k in xrange(number_of_threads):
105+
for k in range(number_of_threads):
106106
thr = Thread(target=reader)
107107
thr.start()
108108

@@ -124,15 +124,15 @@ def reader():
124124
# Make sure, that all keys have actually been requested
125125
# at least once.
126126

127-
self.assertEqual(set(key_range), set(loads.iterkeys()))
127+
self.assertEqual(set(key_range), set(loads.keys()))
128128

129129
# The cache has a capacity such, that it can hold all
130130
# elements nominally ever requested by the readers. So,
131131
# we expect, that every requested key is loaded exactly
132132
# once (due to the cache keeping track of what it is
133133
# currently loading).
134134

135-
for key,count in loads.iteritems():
135+
for key,count in loads.items():
136136
self.assertEqual(1, count)
137137
self.assertTrue(key in key_range)
138138

0 commit comments

Comments
 (0)