From b5f7a4ea7fde58bce37cf3f31ffd33e48bdc11d4 Mon Sep 17 00:00:00 2001 From: rickjms Date: Sat, 6 Mar 2021 16:33:26 -0500 Subject: [PATCH 1/2] upgrading code to work with python 3 --- handler.py | 17 +++++++++++++++-- safeurl.py | 13 ++++++++----- setup.py | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/handler.py b/handler.py index dbc2d26..a511f16 100644 --- a/handler.py +++ b/handler.py @@ -2,13 +2,26 @@ import tornado.ioloop, tornado.web, tornado.autoreload from tornado.escape import json_encode, json_decode -import safeurl, types, sys, re, mimetypes, glob, jsbeautifier, urlparse, pycurl +import safeurl, types, sys, re, mimetypes, glob, jsbeautifier, pycurl + +# Python 2.7/3 urlparse +try: + # Python 2.7 + from urlparse import urlparse + # from urllib import quote +except: + # Python 3 + from urllib.parse import urlparse + # from urllib.parse import quote + + import calendar, time, datetime from netaddr import * from collections import defaultdict from bs4 import BeautifulSoup -from cgi import escape +# from cgi import escape +from html import escape #------------------------------------------------------------ # Base / Status Code Handlers diff --git a/safeurl.py b/safeurl.py index a9be918..3915df5 100644 --- a/safeurl.py +++ b/safeurl.py @@ -15,8 +15,9 @@ import re import netaddr import pycurl -import StringIO - +# import StringIO + # This is python3 +import io # Python 2.7/3 urlparse try: # Python 2.7 @@ -673,7 +674,7 @@ def execute(self, url): """ # Backup the existing URL originalUrl = url - + print("User entered URL:" + url) # Execute, catch redirects and validate the URL redirected = False redirectCount = 0 @@ -707,7 +708,8 @@ def execute(self, url): self._handle.setopt(pycurl.URL, url["cleanUrl"]) # Execute the cURL request - response = StringIO.StringIO() + # response = io.StringIO.StringIO() + response = io.BytesIO() self._handle.setopt(pycurl.WRITEFUNCTION, response.write) self._handle.perform() @@ -729,4 +731,5 @@ def execute(self, url): if not redirected: break - return response.getvalue() + # return response.getvalue() # Python 2 + return response.getvalue().decode('utf-8') diff --git a/setup.py b/setup.py index 87c8cbc..fd53ebd 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,6 @@ long_description=open('README.md').read(), author='Ben Sadeghipour', url='https://github.com/nahamsec/JSParser', - install_requires=['safeurl', 'tornado', 'jsbeautifier', + install_requires=['safeurl', 'tornado<=5.1', 'jsbeautifier', 'netaddr', 'pycurl', 'BeautifulSoup4'], ) From e07064838e5929f2effd57340e2e645d0ee50e1d Mon Sep 17 00:00:00 2001 From: "rickjms1337@gmail.com" Date: Sat, 6 Mar 2021 16:50:59 -0500 Subject: [PATCH 2/2] removing message --- safeurl.py | 1 - 1 file changed, 1 deletion(-) diff --git a/safeurl.py b/safeurl.py index 3915df5..a5a529b 100644 --- a/safeurl.py +++ b/safeurl.py @@ -674,7 +674,6 @@ def execute(self, url): """ # Backup the existing URL originalUrl = url - print("User entered URL:" + url) # Execute, catch redirects and validate the URL redirected = False redirectCount = 0