All Samples(15664) | Call(15566) | Derive(0) | Import(98)
Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it's passed the match object and must return a replacement string to be used.
def sub(pattern, repl, string, count=0, flags=0):
"""Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the match object and must return
a replacement string to be used."""
return _compile(pattern, flags).sub(repl, string, count)
def _get_quoted_name(self):
from re import sub
def handle_match(m):
return '(%s)' % m.group(0)
name = self.name.replace(' ', '_')
return sub(r'(\%([A-F0-9]{2}))+', handle_match, name)
quoted_name = property(_get_quoted_name)
src/i/n/inflect-0.2.1/inflect.py inflect(Download)
from re import match, search, subn, IGNORECASE, VERBOSE from re import split as splitre from re import error as reerror from re import sub as resub from os.path import dirname, isfile, expanduser from os.path import join as pathjoin
def ud_match(self, word, wordlist):
for i in range(len(wordlist)-2, -2, -2): # backwards through even elements
mo = search(r'^%s$' % wordlist[i], word, IGNORECASE)
if mo:
if wordlist[i+1] is None:
return None
pl = resub(r'\$(\d+)',r'\\1',wordlist[i+1]) # change $n to \n for expand
mo = search(r"(%s)\Z" % ordinal_suff, num)
try:
post = ordinal[mo.group(1)]
return resub(r"(%s)\Z" % ordinal_suff, post, num)
except AttributeError:
return "%sth" % num
def enword(self, num, group):
#import pdb
#pdb.set_trace()
if group==1:
num = resub(r"(\d)", self.group1sub, num)
elif group==2:
num = resub(r"(\d)(\d)", self.group2sub, num)
num = resub(r"(\d)", self.group1bsub, num, 1) #
#
# No. This is a bug. Fixed. TODO: report upstream.
elif group==3:
num = resub(r"(\d)(\d)(\d)", self.group3sub, num)
num = resub(r"(\d)(\d)", self.group2sub, num, 1)
num = resub(r"(\d)", self.group1sub, num, 1)
elif int(num) == 0:
# surely there's a better way to do the next bit
mo = search(r"(\d)(\d)(\d)(?=\D*\Z)", num)
while mo:
num = resub(r"(\d)(\d)(\d)(?=\D*\Z)", self.hundsub, num, 1)
mo = search(r"(\d)(\d)(\d)(?=\D*\Z)", num)
num = resub(r"(\d)(\d)(?=\D*\Z)", self.tensub, num, 1)
num = resub(r"(\d)(?=\D*\Z)", self.unitsub, num, 1)
for i in range(loopstart, len(chunks)):
chunk = chunks[i]
#remove all non numeric \D
chunk = resub(r"\D", self.blankfn, chunk)
if chunk == "":
chunk = "0"
if chunk[-2:] == ', ':
chunk = chunk[:-2]
chunk = resub(r"\s+,", self.commafn, chunk)
if group == 0 and first:
chunk = resub(r", (\S+)\s+\Z", " %s \\1" % andword, chunk)
chunk = resub(r"\s+", self.spacefn, chunk)
#TODO: can this be just one re as it is in perl?
mo = search(r"(%s)\Z" % ordinal_suff, numchunks[-1])
if mo:
numchunks[-1] = resub(r"(%s)\Z" % ordinal_suff , ordinal[mo.group(1)],
numchunks[-1])
else:
numchunks[-1] += 'th'
src/p/y/py-mycms-HEAD/trunk/MyCMS/WRAPPERS.py py-mycms(Download)
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from re import findall, sub, subn from MyCMS.CONSTANTS import BASEURL, BASE, STRIPPRE
def percentOut(txt): for x in findall( P, txt ): txt = sub( P, PS+x, txt, 1 ) return txt def percentIn(txt):
src/p/y/py-mycms-HEAD/MyCMS/WRAPPERS.py py-mycms(Download)
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from re import findall, sub, subn from MyCMS.CONSTANTS import BASEURL, BASE, STRIPPRE
def percentOut(txt): for x in findall( P, txt ): txt = sub( P, PS+x, txt, 1 ) return txt def percentIn(txt):
src/t/o/topographica-HEAD/releases/0.9.5/trunk/topographica/topo/misc/gendocs.py topographica(Download)
import pydoc, glob, os from os.path import isdir from re import search, sub from copy import copy
If the path name ends in a .py, then it is cut off. If there is no
extension, the name is assumed to be a directory.
"""
f = sub('/','.',f)
if search('.py$',f):
f = sub('.py$','.html',f)
else:
extension, the name is assumed to be a directory, and nothing is done
other than to replace the '/' with '.'
"""
f = sub('/','.',f)
if search('.py$',f):
f = sub('.py$','',f)
return f
src/g/i/gimini-HEAD/trunk/new_stuff/gimini2/src/log4py.py gimini(Download)
from time import time, strftime, localtime from types import StringType, ClassType, InstanceType, FileType, TupleType from string import zfill, atoi, lower, upper, join, replace, split, strip from re import sub from ConfigParser import ConfigParser, NoOptionError from os import stat, rename
home_directory = get_homedirectory()
if (os.sep == "\\"):
home_directory = replace(home_directory, "\\", "\\\\")
filename = sub("\$HOME", home_directory, filename)
if (os.path.exists(filename)):
configfilename = filename
break
timedifflaststep = "%.3f" % (currenttime - self.__Logger_timelaststep)
self.__Logger_timelaststep = currenttime
milliseconds = int(round((currenttime - long(currenttime)) * 1000))
timeformat = sub("%S", "%S." + (zfill(milliseconds, 3)), self.__Logger_timeformat)
currentformattedtime = strftime(timeformat, localtime(currenttime))
line = self.__Logger_formatstring
line = sub("%C", str(self.__Logger_classname), line)
line = sub("%D", timedifference, line)
line = sub("%d", timedifflaststep, line)
line = sub("%F", self.__Logger_functionname, line)
line = sub("%f", self.__Logger_filename, line)
line = sub("%U", self.__Logger_module, line)
line = sub("%u", os.path.split(self.__Logger_module)[-1], line)
line = sub("%u", os.path.split(self.__Logger_module)[-1], line)
ndc = self.__Logger_get_ndc()
if (ndc != ""):
line = sub("%x", "%s - " % ndc, line)
else:
line = sub("%x", "", line)
message = replace(message, "\\", "\\\\")
if (self.__Logger_useansicodes == TRUE):
line = sub("%L", self.__Logger_ansi(LOG_MSG[messagesource], messagesource), line)
line = sub("%M", self.__Logger_ansi(message, messagesource), line)
else:
line = sub("%L", LOG_MSG[messagesource], line)
line = sub("%M", message, line)
line = sub("%N", str(self.__Logger_linenumber), line)
line = sub("%L", LOG_MSG[messagesource], line)
line = sub("%M", message, line)
line = sub("%N", str(self.__Logger_linenumber), line)
line = sub("%T", currentformattedtime, line)
line = sub("%t", `currenttime`, line)
for i in range(len(self.__Logger_targets)):
target = self.__Logger_targets[i]
if (target == TARGET_MYSQL):
sqltime = strftime("'%Y-%m-%d', '%H:%M:%S'", localtime(currenttime))
sqlStatement = "INSERT INTO %s (host, facility, level, date, time, program, msg) VALUES ('%s', '%s', '%s', %s, '%s', '%s')" % (self.__Logger_mysql_tablename, self.hostname, self.__Logger_functionname, LOG_MSG[messagesource], sqltime, str(self.__Logger_classname), sub("'", "`", message + " " + ndc))
def __init__(self, filename, rotation = ROTATE_NONE):
""" **(private)** Class initalization & customization. """
self.__FileAppender_filename = sub("\$HOME", get_homedirectory(), filename)
self.__FileAppender_filename = os.path.expanduser(self.__FileAppender_filename)
self.__FileAppender_filename = os.path.expandvars(self.__FileAppender_filename)
self.__FileAppender_rotation = rotation
src/t/o/topographica-HEAD/releases/0.9.7/topographica/topo/misc/gendocs.py topographica(Download)
import pydoc, glob, os from os.path import isdir from re import search, sub from copy import copy
If the path name ends in a .py, then it is cut off. If there is no
extension, the name is assumed to be a directory.
"""
f = sub('/','.',f)
if search('.py$',f):
f = sub('.py$','.html',f)
else:
extension, the name is assumed to be a directory, and nothing is done
other than to replace the '/' with '.'
"""
f = sub('/','.',f)
if search('.py$',f):
f = sub('.py$','',f)
return f
src/t/o/topographica-HEAD/releases/0.9.6/topographica/topo/misc/gendocs.py topographica(Download)
import pydoc, glob, os from os.path import isdir from re import search, sub from copy import copy
If the path name ends in a .py, then it is cut off. If there is no
extension, the name is assumed to be a directory.
"""
f = sub('/','.',f)
if search('.py$',f):
f = sub('.py$','.html',f)
else:
extension, the name is assumed to be a directory, and nothing is done
other than to replace the '/' with '.'
"""
f = sub('/','.',f)
if search('.py$',f):
f = sub('.py$','',f)
return f
src/t/o/topographica-HEAD/releases/0.9.5/topographica/topo/misc/gendocs.py topographica(Download)
import pydoc, glob, os from os.path import isdir from re import search, sub from copy import copy
If the path name ends in a .py, then it is cut off. If there is no
extension, the name is assumed to be a directory.
"""
f = sub('/','.',f)
if search('.py$',f):
f = sub('.py$','.html',f)
else:
extension, the name is assumed to be a directory, and nothing is done
other than to replace the '/' with '.'
"""
f = sub('/','.',f)
if search('.py$',f):
f = sub('.py$','',f)
return f
src/t/o/topographica-HEAD/releases/0.9.4/topographica/topo/misc/gendocs.py topographica(Download)
import pydoc, glob, os from os.path import isdir from re import search, sub from copy import copy
If the path name ends in a .py, then it is cut off. If there is no
extension, the name is assumed to be a directory.
"""
f = sub('/','.',f)
if search('.py$',f):
f = sub('.py$','.html',f)
else:
extension, the name is assumed to be a directory, and nothing is done
other than to replace the '/' with '.'
"""
f = sub('/','.',f)
if search('.py$',f):
f = sub('.py$','',f)
return f
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next