Scrapy, a fast high-level web crawling & scraping framework for Python.
PY3 port scrapy.utils.misc.arg_to_iter; fix scrapy.utils.misc.md5sum doctest
Mikhail Korobov444052a2f931
diff --git a/scrapy/utils/misc.py b/scrapy/utils/misc.pyindex a16d42eae..e72a5d042 100644--- a/scrapy/utils/misc.py+++ b/scrapy/utils/misc.py@@ -1,15 +1,19 @@"""Helper functions which doesn't fit anywhere else"""-import reimport hashlib-from importlib import import_modulefrom pkgutil import iter_modules+import sixfrom w3lib.html import remove_entities+from scrapy.utils.python import flattenfrom scrapy.item import BaseItem++_ITERABLE_SINGLE_VALUES = dict, BaseItem, six.text_type, bytes++def arg_to_iter(arg):"""Convert an argument to an iterable. The argument can be a None, singlevalue, or an iterable.@@ -18,11 +22,12 @@ def arg_to_iter(arg):"""if arg is None:return []- elif not isinstance(arg, (dict, BaseItem)) and hasattr(arg, '__iter__'):+ elif not isinstance(arg, _ITERABLE_SINGLE_VALUES) and hasattr(arg, '__iter__'):return argelse:return [arg]+def load_object(path):"""Load an object given its absolute object path, and return it.@@ -48,6 +53,7 @@ def load_object(path):return obj+def walk_modules(path, load=False):"""Loads a module and all its submodules from a the given module path andreturns them. If *any* module throws an exception while importing, that@@ -69,6 +75,7 @@ def walk_modules(path, load=False):mods.append(submod)return mods+def extract_regex(regex, text, encoding='utf-8'):"""Extract a list of unicode strings from the given text/encoding using the following policies:@@ -91,12 +98,13 @@ def extract_regex(regex, text, encoding='utf-8'):else:return [remove_entities(unicode(s, encoding), keep=['lt', 'amp']) for s in strings]+def md5sum(file):"""Calculate the md5 checksum of a file-like object without reading itswhole content in memory.- >>> from StringIO import StringIO- >>> md5sum(StringIO('file content to hash'))+ >>> from io import BytesIO+ >>> md5sum(BytesIO(b'file content to hash'))'784406af91dd5a54fbb9c84c2236595a'"""m = hashlib.md5()diff --git a/tests/py3-ignores.txt b/tests/py3-ignores.txtindex 6340ad683..685dbc17d 100644--- a/tests/py3-ignores.txt+++ b/tests/py3-ignores.txt@@ -57,7 +57,6 @@ tests/test_toplevel.pytests/test_utils_defer.pytests/test_utils_iterators.pytests/test_utils_jsonrpc.py-tests/test_utils_misc/__init__.pytests/test_utils_python.pytests/test_utils_reqser.pytests/test_utils_request.py