Skip to content

Commit 612ed10

Browse files
committed
Remove last xrange - no more in scapy
1 parent 1434144 commit 612ed10

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ guidelines for new code.
7272
- [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html)
7373
is a nice read!
7474
- Avoid creating unnecessary `list` objects, particularly if they
75-
can be huge (e.g., when possible, use `xrange()` instead of
75+
can be huge (e.g., when possible, use `scapy.modules.six.range()` instead of
7676
`range()`, `for line in fdesc` instead of `for line in
7777
fdesc.readlines()`; more generally prefer generators over lists).
7878

@@ -118,9 +118,9 @@ The project aims to provide code that works both on Python 2 and Python 3. There
118118
- lambdas must be written using a single argument when using tuples: use `lambda x_y: x_y[0] + f(x_y[1])` instead of `lambda (x, y): x + f(y)`.
119119
- use int instead of long
120120
- use list comprehension instead of map() and filter()
121-
- use six.range instead of xrange and range
122-
- use six.itervalues(dict) instead of dict.values() or dict.itervalues()
123-
- use six.string_types instead of basestring
121+
- use scapy.modules.six.range instead of xrange and range
122+
- use scapy.modules.six.itervalues(dict) instead of dict.values() or dict.itervalues()
123+
- use scapy.modules.six.string_types instead of basestring
124124

125125
### Code review
126126

scapy/base_classes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, values, _iterpacket=1):
2828
self.values = list(values)
2929
elif (isinstance(values, tuple) and (2 <= len(values) <= 3) and \
3030
all(hasattr(i, "__int__") for i in values)):
31-
# We use values[1] + 1 as stop value for xrange to maintain
31+
# We use values[1] + 1 as stop value for (x)range to maintain
3232
# the behavior of using tuples as field `values`
3333
self.values = [range(*((int(values[0]), int(values[1]) + 1)
3434
+ tuple(int(v) for v in values[2:])))]
@@ -40,7 +40,7 @@ def __iter__(self):
4040
for i in self.values:
4141
if (isinstance(i, Gen) and
4242
(self._iterpacket or not isinstance(i,BasePacket))) or (
43-
isinstance(i, (xrange, types.GeneratorType))):
43+
isinstance(i, (range, types.GeneratorType))):
4444
for j in i:
4545
yield j
4646
else:

scapy/layers/dns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def RRlist2bitmap(lst):
470470
b"B",
471471
sum(2 ** (7 - (x - 256 * wb) + (tmp * 8)) for x in rrlist
472472
if 256 * wb + 8 * tmp <= x < 256 * wb + 8 * tmp + 8),
473-
) for tmp in xrange(bytes_count)
473+
) for tmp in range(bytes_count)
474474
)
475475

476476
return bitmap

scapy/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,13 @@ def randstring(l):
351351
"""
352352
Returns a random string of length l (l >= 0)
353353
"""
354-
return b"".join(struct.pack('B', random.randint(0, 255)) for _ in xrange(l))
354+
return b"".join(struct.pack('B', random.randint(0, 255)) for _ in range(l))
355355

356356
def zerofree_randstring(l):
357357
"""
358358
Returns a random string of length l (l >= 0) without zero in it.
359359
"""
360-
return b"".join(struct.pack('B', random.randint(1, 255)) for _ in xrange(l))
360+
return b"".join(struct.pack('B', random.randint(1, 255)) for _ in range(l))
361361

362362
def strxor(s1, s2):
363363
"""

scapy/volatile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def _fix(self):
343343
if i == "*":
344344
oid.append(str(self.idnum))
345345
elif i == "**":
346-
oid += [str(self.idnum) for i in xrange(1 + self.depth)]
346+
oid += [str(self.idnum) for i in range(1 + self.depth)]
347347
elif isinstance(i, tuple):
348348
oid.append(str(random.randrange(*i)))
349349
else:
@@ -377,7 +377,7 @@ def choice_expand(s): #XXX does not support special sets like (ex ':alnum:')
377377
s = s[:p-1]+rng+s[p+1:]
378378
res = m+s
379379
if invert:
380-
res = "".join(chr(x) for x in xrange(256) if chr(x) not in res)
380+
res = "".join(chr(x) for x in range(256) if chr(x) not in res)
381381
return res
382382

383383
@staticmethod

0 commit comments

Comments
 (0)