Skip to content

Commit 792f347

Browse files
committed
chore: Remove unused keyword arguments from native_stringify_dict and to_native_str
1 parent f144395 commit 792f347

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

scrapyd/launcher.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def get_crawl_args(message):
1919
args = [to_native_str(msg["_spider"])]
2020
del msg["_project"], msg["_spider"]
2121
settings = msg.pop("settings", {})
22-
for k, v in native_stringify_dict(msg, keys_only=False).items():
22+
for k, v in native_stringify_dict(msg).items():
2323
args += ["-a"]
2424
args += [f"{k}={v}"]
25-
for k, v in native_stringify_dict(settings, keys_only=False).items():
25+
for k, v in native_stringify_dict(settings).items():
2626
args += ["-s"]
2727
args += [f"{k}={v}"]
2828
return args
@@ -57,12 +57,12 @@ def _spawn_process(self, message, slot):
5757
environ = self.app.getComponent(IEnvironment)
5858
message.setdefault("settings", {})
5959
message["settings"].update(environ.get_settings(message))
60-
msg = native_stringify_dict(message, keys_only=False)
60+
msg = native_stringify_dict(message)
6161
project = msg["_project"]
6262
args = [sys.executable, "-m", self.runner, "crawl"]
6363
args += get_crawl_args(msg)
6464
env = environ.get_environment(msg, slot)
65-
env = native_stringify_dict(env, keys_only=False)
65+
env = native_stringify_dict(env)
6666
pp = ScrapyProcessProtocol(project, msg["_spider"], msg["_job"], env, args)
6767
pp.deferred.addBoth(self._process_finished, slot)
6868
reactor.spawnProcess(pp, sys.executable, args=args, env=env)

scrapyd/utils.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,25 @@ def get_project_list(config):
4747
return projects
4848

4949

50-
def native_stringify_dict(dct_or_tuples, encoding="utf-8", *, keys_only=True):
51-
"""Return a (new) dict with unicode keys (and values when "keys_only" is
52-
False) of the given dict converted to strings. `dct_or_tuples` can be a
50+
def native_stringify_dict(dct_or_tuples):
51+
"""Return a (new) dict with unicode keys and values
52+
of the given dict converted to strings. `dct_or_tuples` can be a
5353
dict or a list of tuples, like any dict constructor supports.
5454
"""
5555
d = {}
5656
for k, v in dct_or_tuples.items():
57-
key = to_native_str(k, encoding)
58-
if keys_only:
59-
value = v
60-
elif isinstance(v, dict):
61-
value = native_stringify_dict(v, encoding=encoding, keys_only=keys_only)
57+
key = to_native_str(k)
58+
if isinstance(v, dict):
59+
value = native_stringify_dict(v)
6260
elif isinstance(v, list):
63-
value = [to_native_str(e, encoding) for e in v]
61+
value = [to_native_str(e) for e in v]
6462
else:
65-
value = to_native_str(v, encoding)
63+
value = to_native_str(v)
6664
d[key] = value
6765
return d
6866

6967

70-
def to_native_str(text, encoding="utf-8", errors="strict"):
68+
def to_native_str(text):
7169
if isinstance(text, str):
7270
return text
73-
return text.decode(encoding, errors)
71+
return text.decode()

scrapyd/webservice.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def render_POST(self, txrequest, project, spider, version, jobid, priority, sett
205205
if spider not in spiders:
206206
raise error.Error(code=http.OK, message=b"spider '%b' not found" % spider.encode())
207207

208-
spider_arguments = {k: v[0] for k, v in native_stringify_dict(copy(txrequest.args), keys_only=False).items()}
208+
spider_arguments = {k: v[0] for k, v in native_stringify_dict(copy(txrequest.args)).items()}
209209

210210
self.root.scheduler.schedule(
211211
project,

0 commit comments

Comments
 (0)