[Python-checkins] r54328 - in python/trunk: Lib/robotparser.py Misc/NEWS
georg.brandl
python-checkins at python.org
Tue Mar 13 10:41:39 CET 2007
Author: georg.brandl
Date: Tue Mar 13 10:41:31 2007
New Revision: 54328
Modified:
python/trunk/Lib/robotparser.py
python/trunk/Misc/NEWS
Log:
Patch #1555098: use str.join() instead of repeated string
concatenation in robotparser.
Modified: python/trunk/Lib/robotparser.py
==============================================================================
--- python/trunk/Lib/robotparser.py (original)
+++ python/trunk/Lib/robotparser.py Tue Mar 13 10:41:31 2007
@@ -65,7 +65,7 @@
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 @@
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 @@
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"""
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Tue Mar 13 10:41:31 2007
@@ -168,6 +168,9 @@
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.
More information about the Python-checkins
mailing list