All Samples(295) | Call(273) | Derive(0) | Import(22)
Return a 2-tuple containing (new_string, number). new_string is the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. 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 subn(pattern, repl, string, count=0, flags=0):
"""Return a 2-tuple containing (new_string, number).
new_string is the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in the source
string by the replacement repl. number is the number of
substitutions that were made. 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).subn(repl, string, count)
''' 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
inflection = []
for section in sections:
(section, count) = subn(r"num\(\s*?(?:([^),]*)(?:,([^)]*))?)?\)", self.nummo, section)
if not count:
total = -1
while total:
(section, total) = subn(
r"(?x)\bplural \( ([^),]*) (, ([^)]*) )? \) ",
self.plmo, section)
(section, count) = subn(
r"(?x)\bplural_noun \( ([^),]*) (, ([^)]*) )? \) ",
self.plnounmo, section)
total += count
(section, count) = subn(
r"(?x)\bplural_verb \( ([^),]*) (, ([^)]*) )? \) ",
self.plverbmo, section)
total += count
(section, count) = subn(
r"(?x)\bplural_adj \( ([^),]*) (, ([^)]*) )? \) ",
self.pladjmo, section)
total += count
(section, count) = subn(
r"(?x)\bsingular_noun \( ([^),]*) (, ([^)]*) )? \) ",
self.sinounmo, section)
total += count
(section, count) = subn(
r"(?x)\ban? \( ([^),]*) (, ([^)]*) )? \) ",
self.amo, section)
total += count
(section, count) = subn(
r"(?x)\bno \( ([^),]*) (, ([^)]*) )? \) ",
self.nomo, section)
total += count
(section, count) = subn(
r"(?x)\bordinal \( ([^)]*) \) ",
self.ordinalmo, section)
total += count
(section, count) = subn(
r"(?x)\bnumwords \( ([^)]*) \) ",
self.numwordsmo, section)
total += count
(section, count) = subn(
r"(?x)\bpresent_participle \( ([^)]*) \) ",
(r"er$", r"er"),
(r"([^aeiou][aeiouy]([bdgmnprst]))$", "\g<1>\g<2>"),
):
(ans, num) = subn(pat, repl, plv)
if num:
return "%sing" % ans
return "%sing" % ans
float(num) > threshold):
spnum = num.split('.',1)
while (comma):
(spnum[0], n) = subn(r"(\d)(\d{3}(?:,|\Z))",r"\1,\2", spnum[0])
if n==0:
break
try:
src/p/y/py-mycms-HEAD/trunk/MyCMS/tools/__init__.py py-mycms(Download)
from MyCMS.tools import *
from os import getpid, stat
from time import time, ctime
from re import subn, compile, sub, search
DTIME = compile( '^(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})$' )
MOS = ['','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
def spaceOut( text, debug=None ):
try:
if debug: print "try sub<BR>", str(text), "<P>"
return subn( '\n', " <BR>", subn( '\n{2}', " <P>", subn( '\n\r', '\n', str(text) )[0] )[0] )[0]
except Exception, ec:
if debug: print "No substitution<BR>", str(ec)
return text
def replace(oStr,cf,cr):
return subn(cf,cr,oStr)[0]
def replaceChar(oStr,cf,cr):
""" find the specified character in a string and replace it with another character """
nStr = ""
def subString(oStr,sf,sr):
""" find the specified string and replace with another string """
nStr = subn(sf,sr,str(oStr))
return nStr[0]
def makeList(toList):
src/p/y/py-mycms-HEAD/MyCMS/tools/__init__.py py-mycms(Download)
from MyCMS.tools import *
from os import getpid, stat
from time import time, ctime
from re import subn, compile, sub, search
DTIME = compile( '^(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})$' )
MOS = ['','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
def spaceOut( text, debug=None ):
try:
if debug: print "try sub<BR>", str(text), "<P>"
return subn( '\n', " <BR>", subn( '\n{2}', " <P>", subn( '\n\r', '\n', str(text) )[0] )[0] )[0]
except Exception, ec:
if debug: print "No substitution<BR>", str(ec)
return text
def replace(oStr,cf,cr):
return subn(cf,cr,oStr)[0]
def replaceChar(oStr,cf,cr):
""" find the specified character in a string and replace it with another character """
nStr = ""
def subString(oStr,sf,sr):
""" find the specified string and replace with another string """
nStr = subn(sf,sr,str(oStr))
return nStr[0]
def makeList(toList):
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 percentIn(txt): return subn( PS, "%", txt )[0] def tryInsert( dest, arg_tuple, debug=None ): try:
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 percentIn(txt): return subn( PS, "%", txt )[0] def tryInsert( dest, arg_tuple, debug=None ): try:
src/p/y/py-mycms-HEAD/trunk/MyCMS/tools/atlas.py py-mycms(Download)
from MyCMS import BASE, NUL, DATA_LOC, ATLAS import cPickle from re import sub, findall, subn from MyCMS.html.form.field import FormField
def queryLine( value ):
return subn('\<\\\w+\>','+',subn('\<\w+\>','+',subn('\s','+', str(value) )[0])[0])[0]
def mapQuestForm( address, city, state, zip, country='US', zoom=5, debug=None ):
pass
src/p/y/py-mycms-HEAD/MyCMS/tools/atlas.py py-mycms(Download)
from MyCMS import BASE, NUL, DATA_LOC, ATLAS import cPickle from re import sub, findall, subn from MyCMS.html.form.field import FormField
def queryLine( value ):
return subn('\<\\\w+\>','+',subn('\<\w+\>','+',subn('\s','+', str(value) )[0])[0])[0]
def mapQuestForm( address, city, state, zip, country='US', zoom=5, debug=None ):
pass
src/p/y/py-mycms-HEAD/trunk/MyCMS/html/form/field.py py-mycms(Download)
import MyCMS.tools.tools import datetime from re import compile, subn, match from MyCMS.CONSTANTS import * from MyCMS.html.form.FORM_CONSTANTS import * from MyCMS.html.form.uploader import Uploader
name = str(self.name)
if T != FtA and self.value != None and type(self.value) == type(""):
# REPLACE LINE BREAKS WITH <BR> FOR NON-TEXTAREA FIELDS
self.value = subn('[\n\r]','<br>',self.value)[0]
if T in [FsP,FsM]:
chk = "SELECTED"
elif T in [FiC,FiR]:
src/p/y/py-mycms-HEAD/trunk/MyCMS/mail/__init__.py py-mycms(Download)
import smtplib from socket import timeout from random import random as rnd from re import subn, compile, sub, findall from time import time, ctime from os import getpid from MyCMS.tools import spaceOut
if debug: print DOUTS % ".massageFiles()" if self.__attachments: for i in range( len(self.__attachments) ): self.__attachments[i] = ( fname, subn( '=','=3D', percentOut( self.__attachments[i] ) )[0] ) if debug: print DOUTE % ".massageFiles()"
src/p/y/py-mycms-HEAD/MyCMS/html/form/field.py py-mycms(Download)
import MyCMS.tools.tools import datetime from re import compile, subn, match from MyCMS.CONSTANTS import * from MyCMS.html.form.FORM_CONSTANTS import * from MyCMS.html.form.uploader import Uploader
name = str(self.name)
if T != FtA and self.value != None and type(self.value) == type(""):
# REPLACE LINE BREAKS WITH <BR> FOR NON-TEXTAREA FIELDS
self.value = subn('[\n\r]','<br>',self.value)[0]
if T in [FsP,FsM]:
chk = "SELECTED"
elif T in [FiC,FiR]:
1 | 2 | 3 Next