Ticket #28863: updateFallbackDirs.py-python3.patch

File updateFallbackDirs.py-python3.patch, 2.0 KB (added by starlight, 5 months ago)

touch up to apply after 2to3.7

  • updateFallbackDirs.py

    old new  
    2626# https://trac.torproject.org/projects/tor/attachment/ticket/8374/dir_list.2.py
    2727# Modifications by teor, 2015
    2828
     29# BEGIN hack to disable certificate checking
     30import ssl
     31ssl._create_default_https_context = ssl._create_unverified_context
     32# END hack to disable certificate checking
     33
    2934import io
    3035import string
    3136import re
     
    388393
    389394def load_possibly_compressed_response_json(response):
    390395    if response.info().get('Content-Encoding') == 'gzip':
    391       buf = io.StringIO( response.read() )
     396      buf = io.BytesIO( response.read() )
    392397      f = gzip.GzipFile(fileobj=buf)
    393398      return json.load(f)
    394399    else:
     
    431436
    432437  # Unfortunately, the URL is too long for some OS filenames,
    433438  # but we still don't want to get files from different URLs mixed up
    434   base_file_name = what + '-' + hashlib.sha1(url).hexdigest()
     439  base_file_name = what + '-' + hashlib.sha1(url.encode('utf-8')).hexdigest()
    435440
    436441  full_url_file_name = base_file_name + '.full_url'
    437442  MAX_FULL_URL_LENGTH = 1024
     
    16631668    # use the low-median when there are an evan number of fallbacks,
    16641669    # for consistency with the bandwidth authorities
    16651670    if len(self.fallbacks) > 0:
    1666       median_position = (len(self.fallbacks) - 1) / 2
     1671      median_position = int((len(self.fallbacks) - 1) / 2)
    16671672      if not require_advertised_bandwidth:
    16681673        return self.fallbacks[median_position]
    16691674      # if we need advertised_bandwidth but this relay doesn't have it,
     
    18291834    # descriptors
    18301835    #
    18311836    # add an attempt for every MAX_FINGERPRINTS (or part thereof) in the list
    1832     max_retries += (len(fingerprint_list) + MAX_FINGERPRINTS - 1) / MAX_FINGERPRINTS
     1837    max_retries += int((len(fingerprint_list) + MAX_FINGERPRINTS - 1) / MAX_FINGERPRINTS)
    18331838    remaining_list = fingerprint_list
    18341839    desc_list = []
    18351840    for _ in range(max_retries):