From 9668556b33b52633807b8a39972b85cd765fcf10 Mon Sep 17 00:00:00 2001 From: Jason Peacock Date: Wed, 15 Mar 2023 08:37:31 -0500 Subject: [PATCH] Replace long() with int(). The long() and int() were made equivalent in Python 2.4 and long() and the 'long' type was removed in Python 3. --- Products/DataCollector/CommandParsers/Unix_df_k.py | 6 +++--- Products/DataCollector/plugins/zenoss/cmd/df.py | 2 +- .../plugins/zenoss/snmp/HRFileSystemMap.py | 4 ++-- Products/ZenEvents/tests/test_zentrap.py | 2 +- Products/ZenHub/services/DiscoverService.py | 2 +- Products/ZenModel/Commandable.py | 2 +- Products/ZenModel/Fan.py | 2 +- Products/ZenModel/FileSystem.py | 6 +++--- Products/ZenModel/GraphPoint.py | 4 ++-- Products/ZenModel/IpNetwork.py | 10 +++++----- Products/ZenModel/PowerSupply.py | 2 +- Products/ZenModel/RRDDataPoint.py | 2 +- Products/ZenModel/RRDDataSource.py | 4 ++-- Products/ZenModel/TemperatureSensor.py | 4 ++-- Products/ZenModel/ZenStatus.py | 6 +++--- Products/ZenModel/actions.py | 2 +- Products/ZenRRD/utils.py | 4 +--- Products/ZenReports/plugins/interface.py | 2 +- Products/ZenReports/tests/testInterfacePlugin.py | 2 +- Products/ZenUtils/Utils.py | 12 +++++++----- Products/ZenUtils/jsonutils.py | 2 +- Products/ZenUtils/tests/testNaturalSort.py | 4 ++-- Products/Zuul/catalog/indexable.py | 4 ++-- Products/Zuul/infos/component/fan.py | 2 +- Products/Zuul/infos/component/powersupply.py | 2 +- 25 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Products/DataCollector/CommandParsers/Unix_df_k.py b/Products/DataCollector/CommandParsers/Unix_df_k.py index 9e296c1fe8..6322f30290 100644 --- a/Products/DataCollector/CommandParsers/Unix_df_k.py +++ b/Products/DataCollector/CommandParsers/Unix_df_k.py @@ -32,9 +32,9 @@ def parse(self, device, results, log): try: om = self.newObjectMap("ZenModel.FileSystem") om["storageDevice"] = aline[0] - om["totalBytes"] = long(aline[1]) * 1024 - om["usedBytes"] = long(aline[2]) * 1024 - om["availBytes"] = long(aline[3]) * 1024 + om["totalBytes"] = int(aline[1]) * 1024 + om["usedBytes"] = int(aline[2]) * 1024 + om["availBytes"] = int(aline[3]) * 1024 cap = aline[4][-1] == "%" and aline[4][:-1] or aline[4] om["capacity"] = cap om["mount"] = aline[5] diff --git a/Products/DataCollector/plugins/zenoss/cmd/df.py b/Products/DataCollector/plugins/zenoss/cmd/df.py index cb2a74aec9..9bddb3fe82 100644 --- a/Products/DataCollector/plugins/zenoss/cmd/df.py +++ b/Products/DataCollector/plugins/zenoss/cmd/df.py @@ -58,7 +58,7 @@ def process(self, device, results, log): om.totalBlocks = 0 else: try: - om.totalBlocks = long(tblocks) + om.totalBlocks = int(tblocks) except ValueError: # Ignore this filesystem if what we thought was total # blocks isn't a number. diff --git a/Products/DataCollector/plugins/zenoss/snmp/HRFileSystemMap.py b/Products/DataCollector/plugins/zenoss/snmp/HRFileSystemMap.py index c686c4a74a..cfc2123e62 100644 --- a/Products/DataCollector/plugins/zenoss/snmp/HRFileSystemMap.py +++ b/Products/DataCollector/plugins/zenoss/snmp/HRFileSystemMap.py @@ -111,13 +111,13 @@ def process(self, device, results, log): totalBlocks = unsigned(totalBlocks) fs["totalBlocks"] = totalBlocks - size = long(fs["blockSize"] * totalBlocks) + size = int(fs["blockSize"] * totalBlocks) if size <= 0: log.info("Skipping %s. 0 total blocks.", fs["mount"]) continue fs["type"] = self.typemap.get(fs["type"], "other") - size = long(fs["blockSize"] * totalBlocks) + size = int(fs["blockSize"] * totalBlocks) # Handle file systems that need to be mapped into other parts of # the model such as total memory or total swap. diff --git a/Products/ZenEvents/tests/test_zentrap.py b/Products/ZenEvents/tests/test_zentrap.py index c9e0a2c6a6..964940f84f 100644 --- a/Products/ZenEvents/tests/test_zentrap.py +++ b/Products/ZenEvents/tests/test_zentrap.py @@ -130,7 +130,7 @@ def test_decode_value_ipv6(self): ) def test_decode_long_values(self): - value = long(555) + value = int(555) self.assertEqual( decode_snmp_value(value), int(555) diff --git a/Products/ZenHub/services/DiscoverService.py b/Products/ZenHub/services/DiscoverService.py index 06d12e4ec4..c5af7406b8 100644 --- a/Products/ZenHub/services/DiscoverService.py +++ b/Products/ZenHub/services/DiscoverService.py @@ -72,7 +72,7 @@ def fullIpList(self): net = IPNetwork(ipunwrap(self.id)) if self.netmask == net.max_prefixlen: return [ipunwrap(self.id)] - ipnumb = long(int(net)) + ipnumb = int(net) maxip = math.pow(2, net.max_prefixlen - self.netmask) start = int(ipnumb + 1) end = int(ipnumb + maxip - 1) diff --git a/Products/ZenModel/Commandable.py b/Products/ZenModel/Commandable.py index fe8f230f41..957ad7e764 100644 --- a/Products/ZenModel/Commandable.py +++ b/Products/ZenModel/Commandable.py @@ -155,7 +155,7 @@ def manage_doUserCommand(self, commandId=None, REQUEST=None): self.write(out, '') self.write(out, '') self.write(out, 'DONE in %s seconds on %s targets' % - (long(time.time() - startTime), numTargets)) + (int(time.time() - startTime), numTargets)) REQUEST.RESPONSE.write(str(footer)) diff --git a/Products/ZenModel/Fan.py b/Products/ZenModel/Fan.py index 998a232a49..d60a25d7f4 100644 --- a/Products/ZenModel/Fan.py +++ b/Products/ZenModel/Fan.py @@ -82,7 +82,7 @@ def rpm(self, default=None): """ rpm = self.cacheRRDValue('rpm', default) if rpm is not None and not isnan(rpm): - return long(rpm) + return int(rpm) return None diff --git a/Products/ZenModel/FileSystem.py b/Products/ZenModel/FileSystem.py index 304504ba05..38bd8302a1 100644 --- a/Products/ZenModel/FileSystem.py +++ b/Products/ZenModel/FileSystem.py @@ -207,14 +207,14 @@ def usedBlocks(self, default = None): blocks = self.cacheRRDValue('usedBlocks', default) if blocks is not None and not isnan(blocks): - return long(blocks) + return int(blocks) elif self.blockSize: # no usedBlocks datapoint, so this is probably a Windows device # using perfmon for data collection and therefore we'll look for # the freeMegabytes datapoint freeMB = self.cacheRRDValue('FreeMegabytes', default) if freeMB is not None and not isnan(freeMB): - usedBytes = self.totalBytes() - long(freeMB) * 1024 * 1024 + usedBytes = self.totalBytes() - int(freeMB) * 1024 * 1024 return usedBytes / self.blockSize return None @@ -225,7 +225,7 @@ def availBlocks(self, default = None): """ blocks = self.cacheRRDValue('availBlocks', default) if blocks is not None and not isnan(blocks): - return long(blocks) + return int(blocks) usedBlocks = self.usedBlocks() if usedBlocks is None: return None diff --git a/Products/ZenModel/GraphPoint.py b/Products/ZenModel/GraphPoint.py index 52cf67881c..88bd9176ce 100644 --- a/Products/ZenModel/GraphPoint.py +++ b/Products/ZenModel/GraphPoint.py @@ -113,7 +113,7 @@ def manage_editProperties(self, REQUEST): def IsHex(s): try: - _ = long(color, 16) + _ = int(color, 16) except ValueError: return False return True @@ -178,7 +178,7 @@ def getColor(self, index): if self.color: color = self.color try: - _ = long(color.replace("#", ""), 16) + _ = int(color.replace("#", ""), 16) except ValueError: color = None if not color: diff --git a/Products/ZenModel/IpNetwork.py b/Products/ZenModel/IpNetwork.py index 6be2d2ff45..fab6abc0d7 100644 --- a/Products/ZenModel/IpNetwork.py +++ b/Products/ZenModel/IpNetwork.py @@ -167,8 +167,8 @@ def get_subnets_paths(self, net_obj): subnets = [] if net_obj: net = IPNetwork(ipunwrap(net_obj.id)) # addr.IPNetwork - first_decimal_ip = long(int(net.network)) - last_decimal_ip = long(first_decimal_ip + math.pow(2, net.max_prefixlen - net_obj.netmask) - 1) + first_decimal_ip = int(net.network) + last_decimal_ip = int(first_decimal_ip + math.pow(2, net.max_prefixlen - net_obj.netmask) - 1) for net_uids in self.cache.values(min=first_decimal_ip, max=last_decimal_ip, excludemin=True, excludemax=True): subnets.extend(net_uids) return subnets @@ -522,7 +522,7 @@ def get_net_from_catalog(self, ip): if result.total > 0: # networks found. if more than network is found, return the one # whose lastDecimalIp - firstDecimalIp is the smallest - net_brains_tuples = [ ( net_brain, long(net_brain.lastDecimalIp) - long(net_brain.firstDecimalIp) ) for net_brain in result.results ] + net_brains_tuples = [ ( net_brain, int(net_brain.lastDecimalIp) - int(net_brain.firstDecimalIp) ) for net_brain in result.results ] net_brain_tuple = min(net_brains_tuples, key=lambda x: x[1]) net = net_brain_tuple[0].getObject() return net @@ -575,7 +575,7 @@ def hasIp(self, ip): Could this network contain this IP? """ net = IPNetwork(ipunwrap(self.id)) - start = long(int(net.network)) + start = int(net.network) end = start + math.pow(2, net.max_prefixlen - self.netmask) return start <= numbip(ip) < end @@ -584,7 +584,7 @@ def fullIpList(self): """ net = IPNetwork(ipunwrap(self.id)) if (self.netmask == net.max_prefixlen): return [self.id] - ipnumb = long(int(net)) + ipnumb = int(net) maxip = math.pow(2, net.max_prefixlen - self.netmask) start = int(ipnumb+1) end = int(ipnumb+maxip-1) diff --git a/Products/ZenModel/PowerSupply.py b/Products/ZenModel/PowerSupply.py index fcb4a3769b..71cfa499e6 100644 --- a/Products/ZenModel/PowerSupply.py +++ b/Products/ZenModel/PowerSupply.py @@ -84,7 +84,7 @@ def millivolts(self, default=None): """ millivolts = self.cacheRRDValue('millivolts', default) if millivolts is not None: - return long(millivolts) + return int(millivolts) return None diff --git a/Products/ZenModel/RRDDataPoint.py b/Products/ZenModel/RRDDataPoint.py index efedc57cb2..9b8f8e47e1 100644 --- a/Products/ZenModel/RRDDataPoint.py +++ b/Products/ZenModel/RRDDataPoint.py @@ -231,7 +231,7 @@ def zmanage_editProperties(self, REQUEST=None, redirect=False): v = REQUEST.form.get(optional, None) if v: try: - REQUEST.form[optional] = long(v) + REQUEST.form[optional] = int(v) except ValueError: msgs.append('Unable to convert "%s" to a number' % v) msgs = ', '.join(msgs) diff --git a/Products/ZenModel/RRDDataSource.py b/Products/ZenModel/RRDDataSource.py index d23d4b27a0..b950cec203 100644 --- a/Products/ZenModel/RRDDataSource.py +++ b/Products/ZenModel/RRDDataSource.py @@ -343,7 +343,7 @@ def zmanage_editProperties(self, REQUEST=None): value = REQUEST['rrdmin'] if value != '': try: - value = long(value) + value = int(value) except ValueError: messaging.IMessageSender(self).sendToBrowser( 'Error', @@ -357,7 +357,7 @@ def zmanage_editProperties(self, REQUEST=None): value = REQUEST['rrdmax'] if value != '': try: - value = long(value) + value = int(value) except ValueError: messaging.IMessageSender(self).sendToBrowser( 'Error', diff --git a/Products/ZenModel/TemperatureSensor.py b/Products/ZenModel/TemperatureSensor.py index 9b7132c2db..972123492a 100644 --- a/Products/ZenModel/TemperatureSensor.py +++ b/Products/ZenModel/TemperatureSensor.py @@ -76,7 +76,7 @@ def temperatureCelsius(self, default=None): if tempF is not None and not isnan(tempF): tempC = (tempF - 32) / 9.0 * 5 if tempC is not None and not isnan(tempC): - return long(tempC) + return int(tempC) return None temperature = temperatureCelsius @@ -87,7 +87,7 @@ def temperatureFahrenheit(self, default=None): tempC = self.temperatureCelsius(default) if tempC is not None and not isnan(tempC): tempF = tempC * 9 / 5 + 32.0 - return long(tempF) + return int(tempF) return None def temperatureCelsiusString(self): diff --git a/Products/ZenModel/ZenStatus.py b/Products/ZenModel/ZenStatus.py index 7993cb5ee6..12882b8e08 100644 --- a/Products/ZenModel/ZenStatus.py +++ b/Products/ZenModel/ZenStatus.py @@ -93,11 +93,11 @@ def incr(self): if self.failstart == 0: self.failstart = self.failincr = DateTime() if self.status < 0: self.status = 1 - delta = long((DateTime() - self.failincr) * 86400) + delta = int((DateTime() - self.failincr) * 86400) if not self.failincr.isCurrentDay(): yavail = self._getYearlyData(self.failstart.year()) now = DateTime() - newdaydown = long((now.earliestTime() - now) * 86400) + newdaydown = int((now.earliestTime() - now) * 86400) yesterdaydown = self.todaydown + (delta - newdaydown) yavail.addDaily(yesterdaydown) self.todaydown = 0 @@ -138,7 +138,7 @@ def getAvailPercent(self, start, end=None): """get availability for a date range as a float between 100.0 and 0.0""" if self.status < 0: return -1 if not end: end = DateTime() - delta = long((end - start) * 86400.0) + delta = int((end - start) * 86400.0) dt = self.getDownTime(start,end) if dt < 0: return dt return 100.0 - ((self.getDownTime(start, end) / delta)*100) diff --git a/Products/ZenModel/actions.py b/Products/ZenModel/actions.py index 8bb03f8475..6459ee0eca 100644 --- a/Products/ZenModel/actions.py +++ b/Products/ZenModel/actions.py @@ -419,7 +419,7 @@ def _adjustToTimezone(self, millis, timezone): """ Convert event timestamp to timezone from user property. """ - return long(isoToTimestamp(convertTimestampToTimeZone( + return int(isoToTimestamp(convertTimestampToTimeZone( millis / 1000, timezone, "%Y-%m-%d %H:%M:%S" ))) * 1000 diff --git a/Products/ZenRRD/utils.py b/Products/ZenRRD/utils.py index 61af99f392..ac995c8a0c 100644 --- a/Products/ZenRRD/utils.py +++ b/Products/ZenRRD/utils.py @@ -47,10 +47,8 @@ def loadargs(obj, args): if obj._properties[i]["type"] == "lines": value = map(string.strip, arg.split(",")) att = "_" + att - elif obj._properties[i]["type"] == "int": + elif obj._properties[i]["type"] in ("int", "long"): value = int(arg) - elif obj._properties[i]["type"] == "long": - value = long(arg) elif obj._properties[i]["type"] == "float": value = float(arg) elif obj._properties[i]["type"] == "boolean": diff --git a/Products/ZenReports/plugins/interface.py b/Products/ZenReports/plugins/interface.py index 053512c1b3..b96cc2e084 100644 --- a/Products/ZenReports/plugins/interface.py +++ b/Products/ZenReports/plugins/interface.py @@ -104,7 +104,7 @@ def getCompositeColumns(self): "percentUsed", PythonColumnHandler( # total == total is False if total is NaN - "((long(total) if total == total else total) * 8)" + "((int(total) if total == total else total) * 8)" "* 100.0 / speed" ), ), diff --git a/Products/ZenReports/tests/testInterfacePlugin.py b/Products/ZenReports/tests/testInterfacePlugin.py index 165887f62c..7ba9f081bb 100644 --- a/Products/ZenReports/tests/testInterfacePlugin.py +++ b/Products/ZenReports/tests/testInterfacePlugin.py @@ -46,7 +46,7 @@ def assertInterfaceRowIsCorrect( interface.id ] testTotal = testInputOctets + testOutputOctets - testPercentUsed = long(testTotal) * 8 * 100.0 / testSpeed + testPercentUsed = int(testTotal) * 8 * 100.0 / testSpeed assertRecordIsCorrect( test, record, diff --git a/Products/ZenUtils/Utils.py b/Products/ZenUtils/Utils.py index 64232d5b11..46639686c9 100644 --- a/Products/ZenUtils/Utils.py +++ b/Products/ZenUtils/Utils.py @@ -980,7 +980,7 @@ def resequence(context, objects, seqmap, origseq, REQUEST): """ if seqmap and origseq: try: - origseq = tuple(long(s) for s in origseq) + origseq = tuple(int(s) for s in origseq) seqmap = tuple(float(s) for s in seqmap) except ValueError: origseq = () @@ -1409,18 +1409,20 @@ def unsigned(v): >>> str(unsigned(-1)) '4294967295' >>> unsigned(1) - 1L + 1 >>> unsigned(1e6) - 1000000L + 1000000 >>> unsigned(1e10) - 10000000000L + 10000000000 + >>> unsigned(0 - ((2 ** 32) - 1)) + 1 @param v: number @type v: negative 32-bit number @return: 2's complement unsigned value @rtype: unsigned int """ - v = long(v) + v = int(v) if v < 0: return int(ctypes.c_uint32(v).value) return v diff --git a/Products/ZenUtils/jsonutils.py b/Products/ZenUtils/jsonutils.py index e4743d4312..ca34718e50 100644 --- a/Products/ZenUtils/jsonutils.py +++ b/Products/ZenUtils/jsonutils.py @@ -130,7 +130,7 @@ def json(value, **kw): If C{value} is callable, a decorated version of C{value} that serializes its return value will be returned. - >>> value = (dict(a=1L), u"123", 123) + >>> value = (dict(a=1), u"123", 123) >>> print json(value) [{"a": 1}, "123", 123] >>> @json diff --git a/Products/ZenUtils/tests/testNaturalSort.py b/Products/ZenUtils/tests/testNaturalSort.py index 86a070e1a6..ec475d684f 100644 --- a/Products/ZenUtils/tests/testNaturalSort.py +++ b/Products/ZenUtils/tests/testNaturalSort.py @@ -113,11 +113,11 @@ def test(self): '1000','824','770','666', '633','619','1','991', '77H','PIER-7','47', - '29','9','77L','433' + '29','9','77','433' ], [ '01', '1', '4','9','29', '42','44','47','77H', - '77L','87','433','480', + '77','87','433','480', '485','619','633','666', '745','756','770','771', '776','779','824','951', diff --git a/Products/Zuul/catalog/indexable.py b/Products/Zuul/catalog/indexable.py index 4dab77006f..fdc1004fc4 100644 --- a/Products/Zuul/catalog/indexable.py +++ b/Products/Zuul/catalog/indexable.py @@ -489,8 +489,8 @@ def idx_lastDecimalIp(self): last_decimal_ip = None if isip(self.id): net = IPNetwork(ipunwrap(self.id)) - first_decimal_ip = long(int(net.network)) - last_decimal_ip = str(long(first_decimal_ip + math.pow(2, net.max_prefixlen - self.netmask) - 1)) + first_decimal_ip = int(net.network) + last_decimal_ip = str(int(first_decimal_ip + math.pow(2, net.max_prefixlen - self.netmask) - 1)) return last_decimal_ip class ProductIndexable(object): diff --git a/Products/Zuul/infos/component/fan.py b/Products/Zuul/infos/component/fan.py index 1b86b983a2..a0668b7680 100644 --- a/Products/Zuul/infos/component/fan.py +++ b/Products/Zuul/infos/component/fan.py @@ -25,5 +25,5 @@ class FanInfo(ComponentInfo): def rpm(self): rpm = self.getFetchedDataPoint('rpm') if rpm is not None and not isnan(rpm): - rpm = long(rpm) + rpm = int(rpm) return rpm diff --git a/Products/Zuul/infos/component/powersupply.py b/Products/Zuul/infos/component/powersupply.py index 4e667b6e38..7f6764c3c6 100644 --- a/Products/Zuul/infos/component/powersupply.py +++ b/Products/Zuul/infos/component/powersupply.py @@ -27,5 +27,5 @@ class PowerSupplyInfo(ComponentInfo): def millivolts(self): millivolts = self.getFetchedDataPoint('millivolts') if millivolts is not None: - millivolts = long(millivolts) + millivolts = int(millivolts) return millivolts