Skip to content

Commit

Permalink
Revert "py2-3: more stage2 fixes (#406). (#472)" (#476)
Browse files Browse the repository at this point in the history
This reverts commit 107a665.
  • Loading branch information
oliverchang committed May 21, 2019
1 parent ec7d790 commit 80dac9a
Show file tree
Hide file tree
Showing 36 changed files with 103 additions and 181 deletions.
1 change: 1 addition & 0 deletions bot/resources/fuchsia/README.md
@@ -0,0 +1 @@
Placeholder for external resources for fuzzing on Fuchsia.
2 changes: 0 additions & 2 deletions docker/oss-fuzz/host/start_host.py
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.
"""Start host."""
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
from builtins import range
import os
import shutil
Expand Down
1 change: 0 additions & 1 deletion src/appengine/handlers/cron/oss_fuzz_setup.py
Expand Up @@ -15,7 +15,6 @@
from __future__ import absolute_import

from builtins import object
from past.builtins import basestring
import base64
import copy
import json
Expand Down
14 changes: 6 additions & 8 deletions src/appengine/handlers/fuzzers.py
Expand Up @@ -13,10 +13,8 @@
# limitations under the License.
"""Manage fuzzers types."""

from future import standard_library
standard_library.install_aliases()
import datetime
import io
import StringIO

from base import utils
from datastore import data_handler
Expand Down Expand Up @@ -76,13 +74,13 @@ def get(self):
class BaseEditHandler(base_handler.GcsUploadHandler):
"""Base edit handler."""

def _read_to_bytesio(self, gcs_path):
"""Return a bytesio representing a GCS object."""
def _read_to_stringio(self, gcs_path):
"""Return a StringIO representing a GCS object."""
data = storage.read_data(gcs_path)
if not data:
raise helpers.EarlyExitException('Failed to read uploaded archive.', 500)

return io.BytesIO(data)
return StringIO.StringIO(data)

def _get_executable_path(self, upload_info):
"""Get executable path."""
Expand All @@ -96,7 +94,7 @@ def _get_executable_path(self, upload_info):
if not executable_path:
executable_path = 'run' # Check for default.

reader = self._read_to_bytesio(upload_info.gcs_path)
reader = self._read_to_stringio(upload_info.gcs_path)
return archive.get_first_file_matching(executable_path, reader,
upload_info.filename)

Expand All @@ -112,7 +110,7 @@ def _get_launcher_script(self, upload_info):
if upload_info.size > ARCHIVE_READ_SIZE_LIMIT:
return launcher_script

reader = self._read_to_bytesio(upload_info.gcs_path)
reader = self._read_to_stringio(upload_info.gcs_path)
launcher_script = archive.get_first_file_matching(launcher_script, reader,
upload_info.filename)
if not launcher_script:
Expand Down
22 changes: 10 additions & 12 deletions src/appengine/handlers/upload_testcase.py
Expand Up @@ -13,14 +13,12 @@
# limitations under the License.
"""Handler that uploads a testcase"""

from future import standard_library
standard_library.install_aliases()
from builtins import object
import ast
import cgi
import datetime
import io
import json
import StringIO

from base import external_users
from base import tasks
Expand Down Expand Up @@ -107,19 +105,19 @@ def get_result(this):
return result, params


def _read_to_bytesio(gcs_path):
"""Return a bytesio representing a GCS object."""
def _read_to_stringio(gcs_path):
"""Return a StringIO representing a GCS object."""
data = storage.read_data(gcs_path)
if not data:
raise helpers.EarlyExitException('Failed to read uploaded archive.', 500)

return io.BytesIO(data)
return StringIO.StringIO(data)


def guess_input_file(uploaded_file, filename):
"""Guess the main test case file from an archive."""
for file_pattern in RUN_FILE_PATTERNS:
blob_reader = _read_to_bytesio(uploaded_file.gcs_path)
blob_reader = _read_to_stringio(uploaded_file.gcs_path)
file_path_input = archive.get_first_file_matching(file_pattern, blob_reader,
filename)
if file_path_input:
Expand Down Expand Up @@ -527,12 +525,12 @@ def post(self):
self.do_post()


class NamedBytesIO(io.BytesIO):
"""Named bytesio."""
class NamedStringIO(StringIO.StringIO):
"""Named StringIO."""

def __init__(self, name, value):
self.name = name
io.BytesIO.__init__(self, value)
StringIO.StringIO.__init__(self, value)


class UploadHandlerOAuth(base_handler.Handler, UploadHandlerCommon):
Expand All @@ -549,8 +547,8 @@ def get_upload(self):
if not isinstance(uploaded_file, cgi.FieldStorage):
raise helpers.EarlyExitException('File upload not found.', 400)

string_io = NamedBytesIO(uploaded_file.filename,
uploaded_file.file.getvalue())
string_io = NamedStringIO(uploaded_file.filename,
uploaded_file.file.getvalue())
key = blobs.write_blob(string_io)
return blobs.get_blob_info(key)

Expand Down
5 changes: 2 additions & 3 deletions src/local/butler/common.py
Expand Up @@ -19,12 +19,11 @@
from builtins import object
from future import standard_library
standard_library.install_aliases()
from past.builtins import basestring
import datetime
import io
import os
import platform
import shutil
import StringIO
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -213,7 +212,7 @@ def _install_chromedriver():
archive_request = urllib.request.urlopen(
constants.CHROMEDRIVER_DOWNLOAD_PATTERN.format(
version=version, archive_name=archive_name))
archive_io = io.BytesIO(archive_request.read())
archive_io = StringIO.StringIO(archive_request.read())
chromedriver_archive = zipfile.ZipFile(archive_io)

chromedriver_path = get_chromedriver_path()
Expand Down
3 changes: 1 addition & 2 deletions src/local/butler/generate_datastore_models.py
Expand Up @@ -16,7 +16,6 @@
"""Script to convert python Datastore types to Go and protobufs."""

from builtins import object
from past.builtins import basestring
import ast
import inspect
import os
Expand Down Expand Up @@ -188,7 +187,7 @@ def capitalize_acronyms(name):

def py_to_go_type(py_type):
"""Return the Go equivalent for a python type."""
if isinstance(py_type, basestring):
if py_type in [str, unicode, basestring]:
return 'string'

if py_type in six.integer_types:
Expand Down
8 changes: 3 additions & 5 deletions src/local/butler/py_unittest.py
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.
"""py_unittest.py runs tests under src/appengine and butler/tests"""
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
from builtins import object
from builtins import range
import coverage
Expand All @@ -23,13 +21,13 @@
COV = coverage.Coverage(config_file='.coveragerc')
COV.start()

import io
import itertools
import logging
import multiprocessing
import os
import platform
import signal
import StringIO
import sys
import time
import unittest
Expand Down Expand Up @@ -104,7 +102,7 @@ def __exit__(self, exc_type, value, traceback):
COV.html_report(directory='coverage')

print('The tests cover %0.2f%% of the source code.' %
COV.report(file=io.BytesIO()))
COV.report(file=StringIO.StringIO()))
print('The test coverage by lines can be seen at ./coverage/index.html')


Expand Down Expand Up @@ -133,7 +131,7 @@ def run_one_test_parallel(args):
test_modules, suppress_output = args
suite = unittest.loader.TestLoader().loadTestsFromNames(test_modules)

stream = io.BytesIO()
stream = StringIO.StringIO()

# Verbosity=0 since we cannot see real-time test execution order when tests
# are executed in parallel.
Expand Down
7 changes: 3 additions & 4 deletions src/python/base/utils.py
Expand Up @@ -13,10 +13,9 @@
# limitations under the License.
"""Common utility functions."""

from builtins import range
from future import standard_library
standard_library.install_aliases()
from past.builtins import basestring
from builtins import range
import ast
import datetime
import functools
Expand All @@ -28,8 +27,8 @@
import requests
import sys
import time
import urllib.parse
import urllib.request
import urlparse
import weakref

from base import errors
Expand Down Expand Up @@ -152,7 +151,7 @@ def file_path_to_file_url(path):
return ''

path = path.lstrip(WINDOWS_PREFIX_PATH)
return urllib.parse.urljoin(u'file:', urllib.request.pathname2url(path))
return urlparse.urljoin('file:', urllib.request.pathname2url(path))


def filter_file_list(file_list):
Expand Down
15 changes: 6 additions & 9 deletions src/python/bot/fuzzers/options.py
Expand Up @@ -13,10 +13,8 @@
# limitations under the License.
"""Fuzzer options."""

from future import standard_library
standard_library.install_aliases()
from builtins import object
import configparser
import ConfigParser
import os
import random
import re
Expand Down Expand Up @@ -90,12 +88,11 @@ def __init__(self, options_file_path, cwd=None):
else:
self._cwd = os.path.dirname(options_file_path)

self._config = configparser.ConfigParser()
with open(options_file_path, 'r') as f:
try:
self._config.read_file(f)
except configparser.Error:
raise FuzzerOptionsException('Failed to parse fuzzer options file.')
self._config = ConfigParser.ConfigParser()
try:
self._config.read(options_file_path)
except ConfigParser.Error:
raise FuzzerOptionsException('Failed to parse fuzzer options file.')

def _get_dict_path(self, relative_dict_path):
"""Return a full path to the dictionary."""
Expand Down
2 changes: 0 additions & 2 deletions src/python/bot/minimizer/minimizer.py
Expand Up @@ -14,8 +14,6 @@
"""Base classes for other minimizers."""
from __future__ import absolute_import

from future import standard_library
standard_library.install_aliases()
from builtins import object
from builtins import range
import copy
Expand Down
2 changes: 0 additions & 2 deletions src/python/bot/startup/run_bot.py
Expand Up @@ -17,8 +17,6 @@
# We want to use utf-8 encoding everywhere throughout the application
# instead of the default 'ascii' encoding. This must happen before any
# other imports.
from future import standard_library
standard_library.install_aliases()
from builtins import object
import sys
reload(sys)
Expand Down
2 changes: 0 additions & 2 deletions src/python/bot/tasks/analyze_task.py
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.
"""Analyze task for handling user uploads."""

from future import standard_library
standard_library.install_aliases()
import datetime
import os

Expand Down
2 changes: 0 additions & 2 deletions src/python/bot/tasks/fuzz_task.py
Expand Up @@ -14,8 +14,6 @@
"""Fuzz task for handling fuzzing."""
from __future__ import division

from future import standard_library
standard_library.install_aliases()
from builtins import object
import collections
import datetime
Expand Down
10 changes: 4 additions & 6 deletions src/python/bot/webserver/http_server.py
Expand Up @@ -13,9 +13,7 @@
# limitations under the License.
"""Runs http(s) server in the background."""

from future import standard_library
standard_library.install_aliases()
import http.server
import BaseHTTPServer
import mimetypes
import os
import socket
Expand Down Expand Up @@ -70,11 +68,11 @@ def guess_mime_type(filename):
return mimetypes.guess_type(filename)[0]


class BotHTTPServer(http.server.HTTPServer):
class BotHTTPServer(BaseHTTPServer.HTTPServer):
"""Host the bot's test case directories over HTTP."""

def __init__(self, server_address, handler_class):
http.server.HTTPServer.__init__(self, server_address, handler_class)
BaseHTTPServer.HTTPServer.__init__(self, server_address, handler_class)

def _handle_request_noblock(self):
"""Process a single http request."""
Expand All @@ -89,7 +87,7 @@ def _handle_request_noblock(self):
self.close_request(request)


class RequestHandler(http.server.BaseHTTPRequestHandler):
class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""Handler for get requests to test cases."""

def do_GET(self): # pylint: disable=invalid-name
Expand Down
4 changes: 2 additions & 2 deletions src/python/build_management/revisions.py
Expand Up @@ -16,7 +16,6 @@
from future import standard_library
standard_library.install_aliases()
from builtins import range
from past.builtins import basestring
import base64
import bisect
import json
Expand All @@ -26,6 +25,7 @@
import six
import time
import urllib.parse
import urlparse

from base import memoize
from base import utils
Expand Down Expand Up @@ -202,7 +202,7 @@ def _is_clank(url):

def _is_deps(url):
"""Return bool on whether this is a DEPS url or not."""
return urllib.parse.urlparse(url).path.endswith('/DEPS')
return urlparse.urlparse(url).path.endswith('/DEPS')


def _src_map_to_revisions_dict(src_map, default_project_name):
Expand Down
2 changes: 0 additions & 2 deletions src/python/chrome/crash_uploader.py
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.
"""Crash minidump and symbols uploader."""

from future import standard_library
standard_library.install_aliases()
from builtins import object
from builtins import range
import email
Expand Down
1 change: 0 additions & 1 deletion src/python/google_cloud_utils/blobs.py
Expand Up @@ -14,7 +14,6 @@
"""Blobs handling."""
from __future__ import absolute_import

from past.builtins import basestring
import os
import re
import uuid
Expand Down
1 change: 0 additions & 1 deletion src/python/google_cloud_utils/compute_engine_projects.py
Expand Up @@ -14,7 +14,6 @@
"""Load project data."""

from builtins import object
from past.builtins import basestring
import os
import six

Expand Down

0 comments on commit 80dac9a

Please sign in to comment.