Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 00f9fea

Browse files
committed
Use string.replace instead of regsub.[g]sub.
1 parent b9b50eb commit 00f9fea

5 files changed

Lines changed: 13 additions & 17 deletions

File tree

Lib/CGIHTTPServer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ def run_cgi(self):
148148
if ua:
149149
env['HTTP_USER_AGENT'] = ua
150150
# XXX Other HTTP_* headers
151-
import regsub
152-
decoded_query = regsub.gsub('+', ' ', query)
151+
decoded_query = string.replace(query, '+', ' ')
153152
try:
154153
os.setuid(nobody)
155154
except os.error:

Lib/binhex.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def openrsrc(name, *mode):
7676
#
7777
# Glue code for non-macintosh useage
7878
#
79-
import regsub
8079

8180
class FInfo:
8281
def __init__(self):
@@ -99,7 +98,7 @@ def getfileinfo(name):
9998
dsize = fp.tell()
10099
fp.close()
101100
dir, file = os.path.split(name)
102-
file = regsub.sub(':', '-', file)
101+
file = string.replace(file, ':', '-', 1)
103102
return file, finfo, dsize, 0
104103

105104
class openrsrc:

Lib/cgi.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@
420420
import sys
421421
import os
422422
import urllib
423-
import regsub
424423
import mimetools
425424
import rfc822
426425
from StringIO import StringIO
@@ -564,8 +563,8 @@ def parse_qs(qs, keep_blank_values=0, strict_parsing=0):
564563
if strict_parsing:
565564
raise ValueError, "bad query field: %s" % `name_value`
566565
continue
567-
name = urllib.unquote(regsub.gsub('+', ' ', nv[0]))
568-
value = urllib.unquote(regsub.gsub('+', ' ', nv[1]))
566+
name = urllib.unquote(string.replace(nv[0], '+', ' '))
567+
value = urllib.unquote(string.replace(nv[1], '+', ' '))
569568
if len(value) or keep_blank_values:
570569
if dict.has_key (name):
571570
dict[name].append(value)
@@ -1317,11 +1316,11 @@ def print_environ_usage():
13171316

13181317
def escape(s, quote=None):
13191318
"""Replace special characters '&', '<' and '>' by SGML entities."""
1320-
s = regsub.gsub("&", "&amp;", s) # Must be done first!
1321-
s = regsub.gsub("<", "&lt;", s)
1322-
s = regsub.gsub(">", "&gt;", s)
1319+
s = string.replace(s, "&", "&amp;") # Must be done first!
1320+
s = string.replace(s, "<", "&lt;")
1321+
s = string.replace(s, ">", "&gt;",)
13231322
if quote:
1324-
s = regsub.gsub('"', "&quot;", s)
1323+
s = string.replace(s, '"', "&quot;")
13251324
return s
13261325

13271326

Lib/mhlib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ def getbody(self):
773773
# - the string used to initialize the set (default ''),
774774
# - the separator between ranges (default ',')
775775
# - the separator between begin and end of a range (default '-')
776-
# The separators may be regular expressions and should be different.
776+
# The separators must be strings (not regexprs) and should be different.
777777
#
778778
# The tostring() function yields a string that can be passed to another
779779
# IntSet constructor; __repr__() is a valid IntSet constructor itself.
@@ -882,11 +882,11 @@ def addpair(self, xlo, xhi):
882882
self.normalize()
883883

884884
def fromstring(self, data):
885-
import string, regsub
885+
import string
886886
new = []
887-
for part in regsub.split(data, self.sep):
887+
for part in string.splitfields(data, self.sep):
888888
list = []
889-
for subp in regsub.split(part, self.rng):
889+
for subp in string.splitfields(part, self.rng):
890890
s = string.strip(subp)
891891
list.append(string.atoi(s))
892892
if len(list) == 1:

Lib/telnetlib.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import socket
3939
import select
4040
import string
41-
import regsub
4241

4342
# Tunable parameters
4443
DEBUGLEVEL = 0
@@ -185,7 +184,7 @@ def write(self, buffer):
185184
186185
"""
187186
if IAC in buffer:
188-
buffer = regsub.gsub(IAC, IAC+IAC, buffer)
187+
buffer = string.replace(buffer, IAC, IAC+IAC)
189188
self.sock.send(buffer)
190189

191190
def read_until(self, match, timeout=None):

0 commit comments

Comments
 (0)