Skip to content

Commit

Permalink
xrange is gone
Browse files Browse the repository at this point in the history
  • Loading branch information
rbiasini committed Sep 25, 2019
1 parent 982c4c9 commit 5a7aeba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/can_bit_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, message_id):

def printBitDiff(self, other):
"""Prints bits that transition from always zero to always 1 and vice versa."""
for i in xrange(len(self.ones)):
for i in range(len(self.ones)):
zero_to_one = other.zeros[i] & self.ones[i]
if zero_to_one:
print 'id %s 0 -> 1 at byte %d bitmask %d' % (self.message_id, i, zero_to_one)
Expand Down Expand Up @@ -56,7 +56,7 @@ def load(self, filename, start, end):
new_message = True
message = self.messages[message_id]
bytes = bytearray.fromhex(data)
for i in xrange(len(bytes)):
for i in range(len(bytes)):
ones = int(bytes[i])
message.ones[i] = ones if new_message else message.ones[i] & ones
# Inverts the data and masks it to a byte to get the zeros as ones.
Expand Down
4 changes: 2 additions & 2 deletions examples/can_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, message_id):

def printBitDiff(self, other):
"""Prints bits that are set or cleared compared to other background."""
for i in xrange(len(self.ones)):
for i in range(len(self.ones)):
new_ones = ((~other.ones[i]) & 0xff) & self.ones[i]
if new_ones:
print 'id %s new one at byte %d bitmask %d' % (
Expand Down Expand Up @@ -67,7 +67,7 @@ def load(self, filename):
if data not in self.messages[message_id].data:
message.data[data] = True
bytes = bytearray.fromhex(data)
for i in xrange(len(bytes)):
for i in range(len(bytes)):
message.ones[i] = message.ones[i] | int(bytes[i])
# Inverts the data and masks it to a byte to get the zeros as ones.
message.zeros[i] = message.zeros[i] | ( (~int(bytes[i])) & 0xff)
Expand Down
16 changes: 8 additions & 8 deletions python/esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def command(self, op=None, data=None, chk=0):
# same operation as the request or a retries limit has
# exceeded. This is needed for some esp8266s that
# reply with more sync responses than expected.
for retry in xrange(100):
for retry in range(100):
p = self.read()
if len(p) < 8:
continue
Expand All @@ -156,14 +156,14 @@ def command(self, op=None, data=None, chk=0):
""" Perform a connection test """
def sync(self):
self.command(ESPROM.ESP_SYNC, '\x07\x07\x12\x20' + 32 * '\x55')
for i in xrange(7):
for i in range(7):
self.command()

""" Try connecting repeatedly until successful, or giving up """
def connect(self):
print 'Connecting...'

for _ in xrange(4):
for _ in range(4):
# issue reset-to-bootloader:
# RTS = either CH_PD or nRESET (both active low = chip in reset)
# DTR = GPIO0 (active low = boot to flasher)
Expand All @@ -180,7 +180,7 @@ def connect(self):

# worst-case latency timer should be 255ms (probably <20ms)
self._port.timeout = 0.3
for _ in xrange(4):
for _ in range(4):
try:
self._port.flushInput()
self._slip_reader = slip_reader(self._port)
Expand Down Expand Up @@ -452,7 +452,7 @@ def __init__(self, load_file=None):
if magic != ESPROM.ESP_IMAGE_MAGIC or segments > 16:
raise FatalError('Invalid firmware image magic=%d segments=%d' % (magic, segments))

for i in xrange(segments):
for i in range(segments):
self.load_segment(load_file)
self.checksum = self.read_checksum(load_file)

Expand Down Expand Up @@ -501,7 +501,7 @@ def __init__(self, load_file=None):
raise FatalError('Invalid V2 second header magic=%d segments=%d' % (magic, segments))

# load all the usual segments
for _ in xrange(segments):
for _ in range(segments):
self.load_segment(load_file)
self.checksum = self.read_checksum(load_file)

Expand Down Expand Up @@ -865,7 +865,7 @@ def write_mem(esp, args):

def dump_mem(esp, args):
f = file(args.filename, 'wb')
for i in xrange(args.size / 4):
for i in range(args.size / 4):
d = esp.read_reg(args.address + (i * 4))
f.write(struct.pack('<I', d))
if f.tell() % 1024 == 0:
Expand Down Expand Up @@ -1053,7 +1053,7 @@ def _verify_flash(flasher, args, flash_params=None):

flash = flasher.flash_read(address, image_size)
assert flash != image
diff = [i for i in xrange(image_size) if flash[i] != image[i]]
diff = [i for i in range(image_size) if flash[i] != image[i]]
print '-- verify FAILED: %d differences, first @ 0x%08x' % (len(diff), address + diff[0])
for d in diff:
print ' %08x %02x %02x' % (address + d, ord(flash[d]), ord(image[d]))
Expand Down

0 comments on commit 5a7aeba

Please sign in to comment.