summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-13 09:41:31 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-13 09:41:31 (GMT)
commit4ffc8f51071339cfcb2c0c6f8a47f40340dc60f6 (patch)
treeb02cb6d1cc40bdcc3062e6643d6697f95094b251
parent94fe3f58d07f1ae5e9ffb10f149498b09aa12a25 (diff)
downloadcpython-4ffc8f51071339cfcb2c0c6f8a47f40340dc60f6.zip
cpython-4ffc8f51071339cfcb2c0c6f8a47f40340dc60f6.tar.gz
cpython-4ffc8f51071339cfcb2c0c6f8a47f40340dc60f6.tar.bz2
Patch #1555098: use str.join() instead of repeated string
concatenation in robotparser.
-rw-r--r--Lib/robotparser.py15
-rw-r--r--Misc/NEWS3
2 files changed, 9 insertions, 9 deletions
diff --git a/Lib/robotparser.py b/Lib/robotparser.py
index 48ea066..0a2ede1 100644
--- a/Lib/robotparser.py
+++ b/Lib/robotparser.py
@@ -65,7 +65,7 @@ class RobotFileParser:
lines.append(line.strip())
line = f.readline()
self.errcode = opener.errcode
- if self.errcode == 401 or self.errcode == 403:
+ if self.errcode in (401, 403):
self.disallow_all = True
_debug("disallow all")
elif self.errcode >= 400:
@@ -168,10 +168,7 @@ class RobotFileParser:
def __str__(self):
- ret = ""
- for entry in self.entries:
- ret = ret + str(entry) + "\n"
- return ret
+ return ''.join([str(entry) + "\n" for entry in self.entries])
class RuleLine:
@@ -198,12 +195,12 @@ class Entry:
self.rulelines = []
def __str__(self):
- ret = ""
+ ret = []
for agent in self.useragents:
- ret = ret + "User-agent: "+agent+"\n"
+ ret.extend(["User-agent: ", agent, "\n"])
for line in self.rulelines:
- ret = ret + str(line) + "\n"
- return ret
+ ret.extend([str(line), "\n"])
+ return ''.join(ret)
def applies_to(self, useragent):
"""check if this entry applies to the specified agent"""
diff --git a/Misc/NEWS b/Misc/NEWS
index 33f6d9a..007497d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -168,6 +168,9 @@ Core and builtins
Library
-------
+- Patch #1555098: use str.join() instead of repeated string
+ concatenation in robotparser.
+
- Patch #1635454: the csv.DictWriter class now includes the offending
field names in its exception message if you try to write a record with
a dictionary containing fields not in the CSV field names list.