Merge pull request #12 from jaicis/py3convert
Solved issues bytes in the protocal for checkIPAddress
This commit is contained in:
commit
cb883cab1b
|
@ -572,10 +572,23 @@ class sqlThread(threading.Thread):
|
|||
rowcount = 0
|
||||
# print 'item', item
|
||||
# print 'parameters', parameters
|
||||
# print('++++454++++++++++++++++++++++++')
|
||||
# print ('parameters')
|
||||
# print (parameters)
|
||||
# print ('+++++++++++++++++++++++++++++')
|
||||
try:
|
||||
if 'sent' == parameters[1] and 'B' in parameters[0]:
|
||||
item = '''SELECT toaddress, fromaddress, subject, message, status, ackdata, lastactiontime FROM sent WHERE fromaddress = ? ORDER BY lastactiontime DESC '''
|
||||
parameters = (parameters[0],)
|
||||
except (IndexError,TypeError) as e:
|
||||
pass
|
||||
try:
|
||||
self.cur.execute(item, parameters)
|
||||
rowcount = self.cur.rowcount
|
||||
except Exception as err:
|
||||
print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@')
|
||||
print('inside the expectation')
|
||||
print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@')
|
||||
if str(err) == 'database or disk is full':
|
||||
logger.fatal(
|
||||
'(while cur.execute) Alert: Your disk or data storage volume is full.'
|
||||
|
|
|
@ -29,7 +29,6 @@ sqlLock = threading.Lock()
|
|||
def sqlQuery(sqlStatement, *args):
|
||||
"""
|
||||
Query sqlite and return results
|
||||
|
||||
:param str sqlStatement: SQL statement string
|
||||
:param list args: SQL query parameters
|
||||
:rtype: list
|
||||
|
|
|
@ -142,16 +142,14 @@ def network_group(host):
|
|||
|
||||
|
||||
def checkIPAddress(host, private=False):
|
||||
"""
|
||||
Returns hostStandardFormat if it is a valid IP address,
|
||||
otherwise returns False
|
||||
"""
|
||||
if host[0:12] == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF':
|
||||
|
||||
"""Returns hostStandardFormat if it is a valid IP address, otherwise returns False"""
|
||||
if host[0:12] == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF'.encode('raw_unicode_escape'):
|
||||
hostStandardFormat = socket.inet_ntop(socket.AF_INET, host[12:])
|
||||
return checkIPv4Address(host[12:], hostStandardFormat, private)
|
||||
elif host[0:6] == '\xfd\x87\xd8\x7e\xeb\x43':
|
||||
elif host[0:6] == '\xfd\x87\xd8\x7e\xeb\x43'.encode('raw_unicode_escape'):
|
||||
# Onion, based on BMD/bitcoind
|
||||
hostStandardFormat = base64.b32encode(host[6:]).lower() + ".onion"
|
||||
hostStandardFormat = base64.b32encode(host[6:]) + ".onion".encode()
|
||||
if private:
|
||||
return False
|
||||
return hostStandardFormat
|
||||
|
@ -168,22 +166,21 @@ def checkIPAddress(host, private=False):
|
|||
|
||||
|
||||
def checkIPv4Address(host, hostStandardFormat, private=False):
|
||||
"""
|
||||
Returns hostStandardFormat if it is an IPv4 address,
|
||||
otherwise returns False
|
||||
"""
|
||||
if host[0] == '\x7F': # 127/8
|
||||
|
||||
"""Returns hostStandardFormat if it is an IPv4 address, otherwise returns False"""
|
||||
|
||||
if host[0] == '\x7F'.encode('raw_unicode_escape'): # 127/8
|
||||
if not private:
|
||||
logger.debug(
|
||||
'Ignoring IP address in loopback range: %s',
|
||||
hostStandardFormat)
|
||||
return hostStandardFormat if private else False
|
||||
if host[0] == '\x0A': # 10/8
|
||||
if host[0] == '\x0A'.encode('raw_unicode_escape'): # 10/8
|
||||
if not private:
|
||||
logger.debug(
|
||||
'Ignoring IP address in private range: %s', hostStandardFormat)
|
||||
return hostStandardFormat if private else False
|
||||
if host[0:2] == '\xC0\xA8': # 192.168/16
|
||||
if host[0:2] == '\xC0\xA8'.encode('raw_unicode_escape'): # 192.168/16
|
||||
if not private:
|
||||
logger.debug(
|
||||
'Ignoring IP address in private range: %s', hostStandardFormat)
|
||||
|
|
|
@ -28,6 +28,7 @@ class SqliteInventory(InventoryStorage): # pylint: disable=too-many-ancestors
|
|||
self.lock = RLock()
|
||||
|
||||
def __contains__(self, hash_):
|
||||
print('----------contains------------------')
|
||||
with self.lock:
|
||||
if hash_ in self._objects:
|
||||
return True
|
||||
|
@ -38,6 +39,7 @@ class SqliteInventory(InventoryStorage): # pylint: disable=too-many-ancestors
|
|||
return True
|
||||
|
||||
def __getitem__(self, hash_):
|
||||
print('----------__getitem__------------------')
|
||||
with self.lock:
|
||||
if hash_ in self._inventory:
|
||||
return self._inventory[hash_]
|
||||
|
@ -49,25 +51,30 @@ class SqliteInventory(InventoryStorage): # pylint: disable=too-many-ancestors
|
|||
return InventoryItem(*rows[0])
|
||||
|
||||
def __setitem__(self, hash_, value):
|
||||
print('----------__setitem__------------------')
|
||||
with self.lock:
|
||||
value = InventoryItem(*value)
|
||||
self._inventory[hash_] = value
|
||||
self._objects[hash_] = value.stream
|
||||
|
||||
def __delitem__(self, hash_):
|
||||
print('----------__delitem__------------------')
|
||||
raise NotImplementedError
|
||||
|
||||
def __iter__(self):
|
||||
print('----------__iter__------------------')
|
||||
with self.lock:
|
||||
hashes = self._inventory.keys()[:]
|
||||
hashes += (x for x, in sqlQuery('SELECT hash FROM inventory'))
|
||||
return hashes.__iter__()
|
||||
|
||||
def __len__(self):
|
||||
print('----------__len__------------------')
|
||||
with self.lock:
|
||||
return len(self._inventory) + sqlQuery('SELECT count(*) FROM inventory')[0][0]
|
||||
|
||||
def by_type_and_tag(self, objectType, tag):
|
||||
print('----------by_type_and_tag------------------')
|
||||
with self.lock:
|
||||
values = [value for value in self._inventory.values() if value.type == objectType and value.tag == tag]
|
||||
values += (InventoryItem(*value) for value in sqlQuery(
|
||||
|
|
Reference in New Issue
Block a user