Monkey patch configparser module to ease the dropping of py2 support

This commit is contained in:
Eugenio Lacuesta 2019-07-13 20:10:06 -03:00
parent 09e27d2d2e
commit 27e63e6890
No known key found for this signature in database
GPG Key ID: DA3EF2D0913E9810
2 changed files with 8 additions and 3 deletions

View File

@ -14,6 +14,11 @@ if sys.version_info[0] == 2:
from urlparse import uses_query
uses_query.append('s3')
# Prevent the DeprecationWarning about SafeConfigParser -> ConfigParser
import configparser
if not getattr(configparser, 'ConfigParser', None):
configparser.ConfigParser = configparser.SafeConfigParser
# Undo what Twisted's perspective broker adds to pickle register
# to prevent bugs like Twisted#7989 while serializing requests

View File

@ -1,10 +1,10 @@
import os
import sys
import numbers
import configparser
from operator import itemgetter
import six
from six.moves.configparser import SafeConfigParser
from scrapy.settings import BaseSettings
from scrapy.utils.deprecate import update_classpath
@ -92,9 +92,9 @@ def init_env(project='default', set_syspath=True):
def get_config(use_closest=True):
"""Get Scrapy config file as a SafeConfigParser"""
"""Get Scrapy config file as a ConfigParser"""
sources = get_sources(use_closest)
cfg = SafeConfigParser()
cfg = configparser.ConfigParser()
cfg.read(sources)
return cfg