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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
From 1a1cd4c8caab91469de61d162bc503aade2dfdaa Mon Sep 17 00:00:00 2001
From: Python3pkg <raliclo@gmail.com>
Date: Sun, 21 May 2017 05:42:48 -0700
Subject: [PATCH] Convert to Python3
---
darts/lib/utils/lru.py | 22 +++++++++++-----------
doc/conf.py | 12 ++++++------
test.py | 10 +++++-----
3 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/darts/lib/utils/lru.py b/darts/lib/utils/lru.py
index 2ad0c35..7c8a6f7 100644
--- a/darts/lib/utils/lru.py
+++ b/darts/lib/utils/lru.py
@@ -24,7 +24,7 @@
"""Trivial LRU-Dictionary implementation
"""
-from __future__ import with_statement
+
import sys
from threading import RLock, Lock, Condition, Thread
@@ -234,7 +234,7 @@ def __iter__(self):
See `iterkeys`.
"""
- return self.__index.iterkeys()
+ return iter(self.__index.keys())
def iterkeys(self):
@@ -249,7 +249,7 @@ def iterkeys(self):
priority in any way.
"""
- return self.__index.iterkeys()
+ return iter(self.__index.keys())
def itervalues(self):
@@ -264,7 +264,7 @@ def itervalues(self):
priority in any way.
"""
- for item in self.__index.itervalues():
+ for item in self.__index.values():
yield item._value
def iteritems(self):
@@ -280,7 +280,7 @@ def iteritems(self):
*not* reflect the LRU priority in any way.
"""
- for key, item in self.__index.iteritems():
+ for key, item in self.__index.items():
yield key, item._value
def __delitem__(self, key):
@@ -629,7 +629,7 @@ def __iter__(self):
See `iterkeys`.
"""
- return self.iterkeys()
+ return iter(self.keys())
def iterkeys(self):
@@ -649,7 +649,7 @@ def iterkeys(self):
"""
with self.__lock:
- return iter(tuple(self.__dict.iterkeys()))
+ return iter(tuple(self.__dict.keys()))
def itervalues(self):
"""Iterator for all values of this dictionary
@@ -668,7 +668,7 @@ def itervalues(self):
"""
with self.__lock:
- return iter(tuple(self.__dict.itervalues()))
+ return iter(tuple(self.__dict.values()))
def iteritems(self):
@@ -688,7 +688,7 @@ def iteritems(self):
"""
with self.__lock:
- return iter(tuple(self.__dict.iteritems()))
+ return iter(tuple(self.__dict.items()))
def __getitem__(self, key):
@@ -846,7 +846,7 @@ def clear(self, discard_loads=False):
self.__cache.clear()
if discard_loads:
conditions = list()
- keys = tuple(self.__loading.iterkeys())
+ keys = tuple(self.__loading.keys())
for k in keys:
placeholder = self.__loading.pop(k)
if placeholder._state is loading:
@@ -1037,7 +1037,7 @@ def clear(self, discard_loads=False):
self.__cache.clear()
if discard_loads:
conditions = list()
- keys = tuple(self.__loading.iterkeys())
+ keys = tuple(self.__loading.keys())
for k in keys:
placeholder = self.__loading.pop(k)
if placeholder._state is loading:
diff --git a/doc/conf.py b/doc/conf.py
index a526c1b..fe792fa 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -40,8 +40,8 @@
master_doc = 'index'
# General information about the project.
-project = u'dart.utils.lru'
-copyright = u'2010, Deterministic Arts'
+project = 'dart.utils.lru'
+copyright = '2010, Deterministic Arts'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
@@ -178,8 +178,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
- ('index', 'dartutilslru.tex', u'dart.utils.lru Documentation',
- u'Deterministic Arts', 'manual'),
+ ('index', 'dartutilslru.tex', 'dart.utils.lru Documentation',
+ 'Deterministic Arts', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@@ -211,6 +211,6 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
- ('index', 'dartutilslru', u'dart.utils.lru Documentation',
- [u'Deterministic Arts'], 1)
+ ('index', 'dartutilslru', 'dart.utils.lru Documentation',
+ ['Deterministic Arts'], 1)
]
diff --git a/test.py b/test.py
index 6bd254a..4a1b531 100644
--- a/test.py
+++ b/test.py
@@ -56,7 +56,7 @@ def test_concurrent_access(self):
iterations_per_thread = 1000
number_of_threads = 100
- key_range = range(4)
+ key_range = list(range(4))
loads_lock = RLock()
loads = dict()
@@ -92,7 +92,7 @@ def reader():
with start_lock:
while not start_now:
start_condition.wait()
- for k in xrange(iterations_per_thread):
+ for k in range(iterations_per_thread):
for i in shuffled(key_range):
answer = cache.load(i)
self.assertEqual("R(%r)" % (i,), answer)
@@ -102,7 +102,7 @@ def reader():
with start_lock:
- for k in xrange(number_of_threads):
+ for k in range(number_of_threads):
thr = Thread(target=reader)
thr.start()
@@ -124,7 +124,7 @@ def reader():
# Make sure, that all keys have actually been requested
# at least once.
- self.assertEqual(set(key_range), set(loads.iterkeys()))
+ self.assertEqual(set(key_range), set(loads.keys()))
# The cache has a capacity such, that it can hold all
# elements nominally ever requested by the readers. So,
@@ -132,7 +132,7 @@ def reader():
# once (due to the cache keeping track of what it is
# currently loading).
- for key,count in loads.iteritems():
+ for key,count in loads.items():
self.assertEqual(1, count)
self.assertTrue(key in key_range)
|