当前位置: 首页>>代码示例>>Python>>正文


Python sre.compile函数代码示例

本文整理汇总了Python中sre.compile函数的典型用法代码示例。如果您正苦于以下问题:Python compile函数的具体用法?Python compile怎么用?Python compile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了compile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self):
     """Create our main helpers and compile RE patterns"""
     self.S = Syllabizer()
     self.P = Positioner()
     self.SD = ScanDict(self)
     self.vowelRE = sre.compile('[aeiouyAEIOUY]')
     self.wordBoundsRE = sre.compile(r"([-.,;:?!\(\)\"\s]+)")
     self.possIambRE = sre.compile('(x[x/])+')
开发者ID:COHartman,项目名称:Scandroid,代码行数:8,代码来源:scanfuncs.py

示例2: createCluster

def createCluster(clusterNode, cellName):
    cellConfigNode = getChild(clusterNode, "CellConfig")
    if cellConfigNode:
        createCellConfig(cellConfigNode, cellName)

    for nodeConfigNode in getChildElements(clusterNode, "NodeConfig"):
        createNodeConfig(nodeConfigNode)

    clusterName = clusterNode.attributes['name'].value

    nodesNodeList = getChildElements(clusterNode, 'Node')
    if len(nodesNodeList) > 0:
        clusterId, serverIds, nodeNames = createClusterMembers(clusterName, nodesNodeList, cellName)
        for nodesNode in nodesNodeList:
            nodeName = nodesNode.attributes["name"].value
            for serverNode in getChildElements(nodesNode, "Server"):
                serverName = serverNode.attributes["name"].value
                for serverPortNode in getChildElements(serverNode, "ServerPort"):
                    modifyServerPorts(nodeName, serverName, serverPortNode)
    else:
        clusterId = AdminConfig.getid('/ServerCluster:%s/' % clusterName)
        serverIds, nodeNames = getClusterMembers(clusterId)

    clusterConfigNode = getChild(clusterNode, "ClusterConfig")
    if clusterConfigNode:
        resourcesNode = getChild(clusterConfigNode, "Resources")
        if resourcesNode:
            clusterScope = "Cluster=%s" % clusterName
            clusterPath = "/ServerCluster:%s/" % clusterName
            createResources(clusterPath, clusterScope, resourcesNode)
        modifyServices(clusterConfigNode, clusterId)
        modifyAttributes(clusterConfigNode, clusterId)

    for serverConfigNode in getChildElements(clusterNode, "ServerConfig"):
        if serverConfigNode.getAttributeNode("match"):
            match = sre.compile(serverConfigNode.attributes["match"].value)
        else:
            match = sre.compile(".*")
        for serverItem in serverIds:
            if match.match(serverItem["server"]):
                print "Applying ServerConfig to " + serverItem["server"]
                serverId = serverItem["serverId"]
                modifyServices(serverConfigNode, serverId)
                modifyAttributes(serverConfigNode, serverId)

                resourcesNode = getChild(serverConfigNode, "Resources")
                if resourcesNode:
                    serverScope = "Node=%(node)s,Server=%(server)s" % serverItem
                    serverPath = "/Node:%(node)s/Server:%(server)s/" % serverItem
                    createResources(serverPath, serverScope, resourcesNode)

    print "Saving Config..."
    AdminConfig.save()
    print "Config saved."
    print "Refresh and sync..."
    refreshAndSync(cellName, clusterName, nodeNames)
开发者ID:ammula88,项目名称:WebsphereConfigLib,代码行数:56,代码来源:createServer.py

示例3: main

def main():
	gaia = wikipedia.getSite(code=u'en', fam=u'gaia')
	plot = wikipedia.getSite(code=u'en', fam=u'plotwiki')
	
	wikipedia.setAction(wikipedia.translate(gaia, msg))
	wikipedia.setAction(wikipedia.translate(plot, msg))
	
	final = u'<noinclude><!-- Do not edit this page, this page is automatically created by a Bot. -->\n'
	final+= u'==Most Recent Events==</noinclude>\n'
	
	nonrecent = u'<noinclude>==Older Events==\n'
	end = u'\n\'\'View everything here on the [[Plotwiki:|plotwiki...]]\'\'</noinclude>'
	
	moreYears = True
	year = 04
	
	events = []
	temp = []
	while moreYears:
		y = str(year)
		page = wikipedia.Page(plot, u'Template:Pnav%s' % y.zfill(2))
		
		try:
			text = page.get()
			
			r = sre.compile(u'^.*<span style=".*normal.*">(.*)</span>.*$', sre.UNICODE | sre.MULTILINE | sre.DOTALL)
			text = sre.sub(r, u'\\1', text)
			r = sre.compile(u'\s+\|\s+', sre.UNICODE | sre.MULTILINE | sre.DOTALL)
			pages = sre.split(r, text)
			
			r = sre.compile(u'\[\[([^|]*)(\|.*)?\]\]', sre.UNICODE)
			for p in pages:
				temp.append(sre.sub(r, u'\\1', p))
			
			year+=1
		except wikipedia.NoPage:
			moreYears = False
	for e in temp:
		if not e in events:
			events.append(e)
	
	events = reversed(list(events));
	x = 1
	for e in events:
		final+=u'* [[Plotwiki:%s|]]\n' % e
		x+=1
		if x==6:
			final+=nonrecent
	if x<=6:
		final+=end
	final+=end
	
	page = wikipedia.Page(gaia, u'Plotwiki Current Events')
	page.put(final)
开发者ID:VisualEffects,项目名称:pywikia,代码行数:54,代码来源:GaiaplotBot.py

示例4: __init__

 def __init__(self):
     self.suffixes = sre.compile(
         r""" [^aeiouhr]y\b | er\b | age | est |
             ing | ness\b | less | ful | ment\b | time\b | [st]ion |
             [ia]ble\b | [ct]ial | [ctg]iou | [ctg]ious
         """,
         sre.VERBOSE,
     )
     # 	| ical\b | icle\b | ual\b | ism \b | [ae]ry\b		# don't work (as 2-syl)
     # Note: left out special-character "*ag$" and "tim$" -- don't understand!
     # final syllable spelled with liquid or nasal and silent 'e'
     self.liquidterm = sre.compile(r" [^aeiouy] [rl] e \b", sre.X)
     # the collection of special-character groups
     self.finalE = sre.compile(r" [^aeiouy] e \b ", sre.X)
     self.CiVcomb = sre.compile(r" [st] i [aeiouy] ", sre.X)
     self.CCpair = sre.compile(r" [cgprstw] h | gn |  gu[aeiouy] | qu | ck", sre.X)
     self.VyVcomb = sre.compile(r" [aeiou] y [aeiou]", sre.X)
     # vowel pairs reliably disyllabic (not 'ui' ('juice' vs 'intuition'! some
     # 'ue' missed ('constituent'), some 'oe' ('poem'))
     self.sylvowels = sre.compile(r" [aeiu] o | [iu] a | iu", sre.X)
     # divisions should fall before or after, not within, these consonant pairs
     self.splitLeftPairs = sre.compile(
         r""" [bdfk%02] [rl] | g [rln] |
                                       [tw] r | p [rlsn] s [nml]""",
         sre.X,
     )
开发者ID:Thirteen09,项目名称:Scandroid,代码行数:26,代码来源:syllables.py

示例5: appendTargets

def appendTargets(doc, moduleElement, moduleTargetLine):
    nodeServerRegexp = sre.compile("WebSphere:cell=.*,node=(.*),server=(.*)")
    clusterRegexp = sre.compile("WebSphere:cell=.*,cluster=(.*)")
    for moduleTargetId in moduleTargetLine.split("+"):
        clusterMatch = clusterRegexp.match(moduleTargetId)
        if clusterMatch:
            targetElement = doc.createElement("Target")
            moduleElement.appendChild(targetElement)
            targetElement.setAttribute("cluster", clusterMatch.group(1))
        else:
            nodeServerMatch = nodeServerRegexp.match(moduleTargetId)
            if nodeServerMatch:
                targetElement = doc.createElement("Target")
                moduleElement.appendChild(targetElement)
                targetElement.setAttribute("node", nodeServerMatch.group(1))
                targetElement.setAttribute("server", nodeServerMatch.group(2))
开发者ID:ammula88,项目名称:WebsphereConfigLib,代码行数:16,代码来源:listConfig.py

示例6: add_expression

	def add_expression(self, expression, state, action, next_state, flags=0):
		"""Adds a transition that activates if the input symbol matches the
		regular expression. The action callable gets a match object instead of
		the symbol."""
		cre = sre.compile(expression, flags)
		self._expressions.append( (cre, state, action, next_state) )
		self._transitions[(SREType, state)] = (self._check_expression, None)
开发者ID:pruan,项目名称:TestDepot,代码行数:7,代码来源:fsm.py

示例7: substitute

	def substitute(self,*args):
		for color in colors:
			self.txt.tag_remove(color,"1.0","end")
			self.txt.tag_remove("emph"+color,"1.0","end")
		self.rex = sre.compile("") # default value in case of misformed regexp
		self.rex = sre.compile(self.fld.get("1.0","end")[:-1],sre.MULTILINE)
		try:
			sre.compile("(?P<emph>%s)" % self.fld.get(tk.SEL_FIRST,tk.SEL_LAST))
			self.rexSel = sre.compile("%s(?P<emph>%s)%s" % (
				self.fld.get("1.0",tk.SEL_FIRST),
				self.fld.get(tk.SEL_FIRST,tk.SEL_LAST),
				self.fld.get(tk.SEL_LAST,"end")[:-1],
			),sre.MULTILINE)
		except:
			self.rexSel = self.rex
		self.rexSel.sub(self.addTags,self.txt.get("1.0","end"))
开发者ID:bhramoss,项目名称:code,代码行数:16,代码来源:recipe-496783.py

示例8: _setOkay

 def _setOkay(self, okay):
     if type(okay) == str:
         self.okay = sre.compile(okay)
     elif type(okay) in (LambdaType, ListType, NoneType):
         self.okay = okay
     else:
         raise TypeError, "okay must be lambda, list, or string"
开发者ID:elmore,项目名称:sixthdev,代码行数:7,代码来源:Attribute.py

示例9: init_pattern

def init_pattern(key):
    """Return a SRE compiled pattern; the match can be accessed in the
    match object as
      m = P[key].match(string)
      m.group(key)
    """
    return sre.compile('^init\(\): %(key)s: *(?P<%(key)s>.*)$' % locals())
开发者ID:CTCNano,项目名称:GromacsWrapper,代码行数:7,代码来源:cleanup.py

示例10: __init__

 def __init__(self, parent, ID, title):
     wd, ht, fnt = self._setSizes()
     wx.Frame.__init__(self, parent, ID, title, size=(wd, ht))
     # our panels, top to bottom
     self.ScanLine = MyScanTC(self, fnt)
     self.TextLine = MyLineTC(self, fnt)
     self.NotesWindow = MyNotesTC(self, fnt)
     self.WholeText = MyTextSTC(self, -1)
     # line numbers
     self.WholeText.SetMarginType(0, stc.STC_MARGIN_NUMBER)
     self.WholeText.SetMarginType(1, stc.STC_MARGIN_SYMBOL)
     self.WholeText.StyleSetBackground(stc.STC_STYLE_LINENUMBER,
                                                   (246,246,246))
     # initialize our data members and helpers
     self.SM = ScansionMachine()		# central engine of scansion work
     self.E = Explainer(self.NotesWindow)
     self.lineNum = 0			# where to put its scansion when done
     self.Metron = 2				# initial assumption:
     self.LineFeet = 5			#   iambic pentameter
     self.LineFeetSet = True
     self.SM.SetLineFeet(5, True)
     self.forceiamb, self.forceanap = False, False
     self.SetupGUI()			# buttons, menus . . .
     self.SetupScansionSteps()		# inc some more data items
     self.WholeText.DisplayText(InitialText)		# as a startup . . .
     self.loadedtext = True
     self.WholeText.SetReadOnly(0)	# but allow editing
     self.DisableAllScanButtons()
     self.loadPath, self.savePath = '', ''
     wx.FutureCall(100, self.WholeText.SetFocus)	# Robin Dunn's fix!
     self.leadSpaceRE = sre.compile(r'[ |\t]+')
     self.newFindDialog, self.oldFindDialog = [None for i in range(2)]
     # icon
     ico = robIcon.getrobIcon()
     self.SetIcon(ico)
开发者ID:joconno2,项目名称:Scandroid,代码行数:35,代码来源:Scandroid.py

示例11: parse

	def parse(self, text):
		linesplitter = sre.compile(r"[ \t=]")
		self.lines = []
		state = 0
		currenttitle = None
		for line in text.splitlines():
			line = line.strip()
			if line.startswith("#"):
				self.lines.append(GrubComment(line[1:]))
				continue
			if not line:
				continue
			if state == 0:
				cmd, rest = linesplitter.split(line, 1)
				CMD = COMMANDS[cmd]
				if CMD.flags & BUILTIN_TITLE:
					state = 1
					currenttitle = GrubTitleEntry(rest)
					self.lines.append(currenttitle)
					continue
				elif CMD.flags & BUILTIN_MENU:
					self.lines.append(GrubEntry(CMD, rest))
			if state == 1:
				cmd, rest = linesplitter.split(line, 1)
				CMD = COMMANDS[cmd]
				if CMD.flags & BUILTIN_TITLE:
					currenttitle = GrubTitleEntry(rest)
					self.lines.append(currenttitle)
				elif CMD.flags & (BUILTIN_CMDLINE | BUILTIN_MENU):
					currenttitle.lines.append(GrubEntry(CMD, rest))
开发者ID:pruan,项目名称:TestDepot,代码行数:30,代码来源:grublib.py

示例12: __init__

 def __init__(self, parent, ID, title, poem):
     wd, ht, fnt = self._setSizes()
     wx.Frame.__init__(self, parent, ID, title, size=(wd, ht))
     # our panels, top to bottom
     self.ScanLine = MyScanTC(self, fnt)
     self.TextLine = MyLineTC(self, fnt)
     self.NotesWindow = MyNotesTC(self, fnt)
     self.WholeText = MyTextSTC(self, -1)
     
     # line numbers
     self.WholeText.SetMarginType(0, stc.STC_MARGIN_NUMBER)
     self.WholeText.SetMarginType(1, stc.STC_MARGIN_SYMBOL)
     self.WholeText.SetMarginWidth(0, 1)
     self.WholeText.SetMarginWidth(1, 10)
     self.WholeText.StyleSetBackground(stc.STC_STYLE_LINENUMBER, (246,246,246))
     # initialize our data members and helpers
     self.SM = ScansionMachine()		# central engine of scansion work
     self.E = Explainer(self.NotesWindow)
     self.lineNum = 0			# where to put its scansion when done
     self.loaddir = ''				# where user gets textfiles to Load
     self.Metron = 2				# initial assumption:
     self.LineFeet = 5			#   iambic pentameter
     self.LineFeetSet = True
     self.SM.SetLineFeet(5, True)
     self.SetupGUI()			# buttons, menus . . .
     # self.dwds = []
     self.SetupScansionSteps()		# inc some more data items
     self.WholeText.DisplayText(InitialText)		# as a startup . . .
     self.WholeText.SetReadOnly(0)	# but allow editing
     self.EnableScanButtons(False)
     wx.FutureCall(100, self.WholeText.SetFocus)	# Robin Dunn's fix!
     self.leadSpaceRE = sre.compile(r'[ |\t]+')
     self.poem = poem
开发者ID:bryanpaget,项目名称:graph_poetry,代码行数:33,代码来源:Scandroid.py

示例13: listCellConfig

def listCellConfig(doc, cellConfigElement):
    security = AdminConfig.getid('/Cell:/Security:/')
    securityElement = doc.createElement("Security")
    cellConfigElement.appendChild(securityElement)
    for configClass in ConfigClasses.CellConfigSecurity:
        for configObj in AdminConfig.list(configClass.classname, security).splitlines():
            configElement = doc.createElement(configClass.classname)
            securityElement.appendChild(configElement)
            for attribute in configClass.requiredAttributes():
                configElement.setAttribute(attribute.attributeName,
                    AdminConfig.showAttribute(configObj, attribute.attributeName))
    signerCertRegExp = sre.compile(
        "\[ \[issuedTo (.*)\] \[fingerPrint .*\] \[signatureAlgorithm .*\] \[serialNumber .*\] \[alias (.*)\] \[validity (.*)\] \[version .*\] \[issuedBy .*\] \[size .*\] \]")
    for keystoreName in ['CellDefaultKeyStore', 'CellDefaultTrustStore']:
        keystoreElement = doc.createElement(keystoreName)
        securityElement.appendChild(keystoreElement)
        for line in AdminTask.listSignerCertificates('[-keyStoreName %s]' % keystoreName).splitlines():
            signerCertMatch = signerCertRegExp.match(line)
            if signerCertMatch:
                signerCertElement = doc.createElement('SignerCertificate')
                keystoreElement.appendChild(signerCertElement)
                signerCertElement.setAttribute("alias", signerCertMatch.group(2))
                signerCertElement.setAttribute("issuedTo", signerCertMatch.group(1))
                signerCertElement.setAttribute("validity", signerCertMatch.group(3))
        for line in AdminTask.listPersonalCertificates('[-keyStoreName %s]' % keystoreName).splitlines():
            signerCertMatch = signerCertRegExp.match(line)
            if signerCertMatch:
                signerCertElement = doc.createElement('PersonalCertificate')
                keystoreElement.appendChild(signerCertElement)
                signerCertElement.setAttribute("alias", signerCertMatch.group(2))
                signerCertElement.setAttribute("issuedTo", signerCertMatch.group(1))
                signerCertElement.setAttribute("validity", signerCertMatch.group(3))
    cellResourcesElement = doc.createElement('Resources')
    cellConfigElement.appendChild(cellResourcesElement)
    listCellResources(doc, cellResourcesElement, AdminConfig.getid('/Cell:/'))
开发者ID:ammula88,项目名称:WebsphereConfigLib,代码行数:35,代码来源:listConfig.py

示例14: logall

def logall(start, xtra_args=None, verbose=False, dry_run=False):
    paths = []    
    
    svn = Popen(['svn', 'info', start], stdout=PIPE)
    url_p = sre.compile(r'^URL: (.*)')
    url = None
    for line in svn.stdout:
        m = url_p.match(line)
        if m:
            url = m.group(1)
    assert url is not None, "svn info: could not find URL:"
    
    paths = []
    svn = Popen(['svn', 'list', '--recursive', url], stdout=PIPE)
    [paths.append(L.strip()) for L in svn.stdout]
    r = svn.wait()
    if r != 0:
        print "\n".join(paths)
        sys.exit(r)
    
    cmd = ['svn']
    if xtra_args:
        cmd.extend(xtra_args)
    cmd.extend( ['log', url] )
    cmd.extend(paths)
    
    # if verbose or dry_run:
    #     print ' '.join(cmd)
    if dry_run:
        sys.exit(0)
        
    svn = Popen(cmd, stdout=PIPE)
    for line in svn.stdout:
        print line,
开发者ID:kumar303,项目名称:toolbox,代码行数:34,代码来源:svn-logall.py

示例15: main

def main():
	#Setup Familys for Wikia Involved
	anime = wikipedia.getSite(code=u'en', fam=u'anime')
	wikipedia.setAction(wikipedia.translate(anime, msg))
	siteList = []
	
	#Get Project Wiki Listing
	wikiaIds = []
	page = wikipedia.Page(anime, u'Bots/Wiki', None, None, 4)#4=Project Namespace
	try:
		text = page.get()
		r = sre.compile(u'^.*<!-- \|\|START\|\| -->\n?', sre.UNICODE | sre.DOTALL)
		text = sre.sub(r, u'', text)
		r = sre.compile(u'\n?<!-- \|\|END\|\| -->.*$', sre.UNICODE | sre.DOTALL)
		text = sre.sub(r, u'', text)
		r = sre.compile(u'\n', sre.UNICODE | sre.MULTILINE | sre.DOTALL)
		wikilist = sre.split(r, text)
		for wiki in wikilist:
			if wiki != u'':
				wikiaIds.append(wiki)
	except wikipedia.NoPage:
		moreYears = False
	
	for wiki in wikiaIds:
		siteList.append(wikipedia.getSite(code=u'en', fam=wiki))
	
	commonstart = u'@import "http://en.anime.wikia.com/index.php?title=MediaWiki:Anime-Common.css&action=raw&ctype=text/css";'
	monobookstart = u'@import "http://en.anime.wikia.com/index.php?title=MediaWiki:Anime-Monobook.css&action=raw&ctype=text/css";'
	
	for site in siteList:
		common = wikipedia.Page(site, u'Common.css', None, None, 8)#8=MediaWiki Namespace
		monobook = wikipedia.Page(site, u'Monobook.css', None, None, 8)#8=MediaWiki Namespace

				siteSource = u''
				try:
					siteSource = sitePage.get()
				except wikipedia.NoPage:
					wikipedia.output(u'Site %s has no %s template, creating it' % (site, template))
				if siteSource != templateSource:
					wikipedia.output(u'Site \'%s\' template status: Needs Updating' % site)
					wikipedia.output(u'Updating template on %s' % site)
					sitePage.put(templateSource)
				else:
					wikipedia.output(u'Site \'%s\' template status: Ok' % site)
开发者ID:VisualEffects,项目名称:pywikia,代码行数:44,代码来源:GE-Style-Bot.py


注:本文中的sre.compile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。