Some py3 bugs fixed

This commit is contained in:
VakarisZ 2019-10-11 10:22:39 +03:00
parent fcd43b9fa0
commit cefaacabab
6 changed files with 15 additions and 16 deletions

View File

@ -1,6 +1,7 @@
import json import json
import re import re
import urllib2 import urllib.request
import urllib.error
import logging import logging
@ -25,18 +26,18 @@ class AwsInstance(object):
self.account_id = None self.account_id = None
try: try:
self.instance_id = urllib2.urlopen( self.instance_id = urllib.request.urlopen(
AWS_LATEST_METADATA_URI_PREFIX + 'meta-data/instance-id', timeout=2).read() AWS_LATEST_METADATA_URI_PREFIX + 'meta-data/instance-id', timeout=2).read()
self.region = self._parse_region( self.region = self._parse_region(
urllib2.urlopen(AWS_LATEST_METADATA_URI_PREFIX + 'meta-data/placement/availability-zone').read()) urllib.request.urlopen(AWS_LATEST_METADATA_URI_PREFIX + 'meta-data/placement/availability-zone').read())
except urllib2.URLError as e: except urllib.error.URLError as e:
logger.debug("Failed init of AwsInstance while getting metadata: {}".format(e.message)) logger.debug("Failed init of AwsInstance while getting metadata: {}".format(e))
try: try:
self.account_id = self._extract_account_id( self.account_id = self._extract_account_id(
urllib2.urlopen( urllib.request.urlopen(
AWS_LATEST_METADATA_URI_PREFIX + 'dynamic/instance-identity/document', timeout=2).read()) AWS_LATEST_METADATA_URI_PREFIX + 'dynamic/instance-identity/document', timeout=2).read())
except urllib2.URLError as e: except urllib.error.URLError as e:
logger.debug("Failed init of AwsInstance while getting dynamic instance data: {}".format(e)) logger.debug("Failed init of AwsInstance while getting dynamic instance data: {}".format(e))
@staticmethod @staticmethod

View File

@ -17,8 +17,8 @@ class VictimHostGeneratorTester(TestCase):
generator = VictimHostGenerator(test_ranges, '10.0.0.1', []) generator = VictimHostGenerator(test_ranges, '10.0.0.1', [])
victims = generator.generate_victims(chunk_size) victims = generator.generate_victims(chunk_size)
for i in range(5): # quickly check the equally sided chunks for i in range(5): # quickly check the equally sided chunks
self.assertEqual(len(victims.next()), chunk_size) self.assertEqual(len(next(victims)), chunk_size)
victim_chunk_last = victims.next() victim_chunk_last = next(victims)
self.assertEqual(len(victim_chunk_last), 1) self.assertEqual(len(victim_chunk_last), 1)
def test_remove_blocked_ip(self): def test_remove_blocked_ip(self):

View File

@ -85,7 +85,7 @@ class NetworkScanner(object):
return return
results = pool.map(self.scan_machine, victim_chunk) results = pool.map(self.scan_machine, victim_chunk)
resulting_victims = filter(lambda x: x is not None, results) resulting_victims = [x for x in results if x is not None]
for victim in resulting_victims: for victim in resulting_victims:
LOG.debug("Found potential victim: %r", victim) LOG.debug("Found potential victim: %r", victim)
victims_count += 1 victims_count += 1

View File

@ -3,7 +3,7 @@ import os.path
import select import select
import socket import socket
import threading import threading
import urllib.request, urllib.parse, urllib.error import urllib
from logging import getLogger from logging import getLogger
from urllib.parse import urlsplit from urllib.parse import urlsplit

View File

@ -4,7 +4,7 @@ import abc
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class AutoNewUser: class AutoNewUser(metaclass=abc.ABCMeta):
""" """
RAII object to use for creating and using a new user. Use with `with`. RAII object to use for creating and using a new user. Use with `with`.
User will be created when the instance is instantiated. User will be created when the instance is instantiated.
@ -19,7 +19,6 @@ class AutoNewUser:
# Logged off and deleted # Logged off and deleted
... ...
""" """
__metaclass__ = abc.ABCMeta
def __init__(self, username, password): def __init__(self, username, password):
self.username = username self.username = username

View File

@ -1,6 +1,6 @@
bson bson
python-dateutil python-dateutil
tornado==5.1.1 tornado
werkzeug werkzeug
jinja2 jinja2
markupsafe markupsafe
@ -10,10 +10,9 @@ flask
Flask-Pymongo Flask-Pymongo
Flask-Restful Flask-Restful
Flask-JWT Flask-JWT
jsonschema==2.6.0 jsonschema
netifaces netifaces
ipaddress ipaddress
enum34
pycryptodome pycryptodome
boto3 boto3
botocore botocore