]> granicus.if.org Git - python/commitdiff
Patch #1555098: use str.join() instead of repeated string
authorGeorg Brandl <georg@python.org>
Tue, 13 Mar 2007 09:41:31 +0000 (09:41 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 13 Mar 2007 09:41:31 +0000 (09:41 +0000)
concatenation in robotparser.

Lib/robotparser.py
Misc/NEWS

index 48ea066682e1878d3402c4275cbcf45276ff5fae..0a2ede13e6292eaf1a746ff2b8b98851755230b0 100644 (file)
@@ -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"""
index 33f6d9a09c366c5de04c3343ae3b59f6e68a57a9..007497db52da7bd760b33a066f47a22c21826442 100644 (file)
--- 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.