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

View File

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

View File

@ -85,7 +85,7 @@ class NetworkScanner(object):
return
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:
LOG.debug("Found potential victim: %r", victim)
victims_count += 1

View File

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

View File

@ -4,7 +4,7 @@ import abc
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`.
User will be created when the instance is instantiated.
@ -19,7 +19,6 @@ class AutoNewUser:
# Logged off and deleted
...
"""
__metaclass__ = abc.ABCMeta
def __init__(self, username, password):
self.username = username

View File

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