• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sre.compile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: auto_complete

 def auto_complete(self):
     pos =  self._sc.get_current_pos()
     wpos = self._sc.word_start_position(pos, True)
     linepos, line = self._sc.get_cur_line()
     word = line[linepos - (pos - wpos):linepos]
     if word:
         pattern = sre.compile(r'\W(%s.+?)\W' % word)
         text = self._sc.get_text()
         words = set(pattern.findall(text))
         self._sc.auto_c_set_choose_single(True)
         self._sc.auto_c_set_drop_rest_of_word(True)
         self._sc.auto_c_show(len(word), ' '.join(sorted(list(words))))
开发者ID:BackupTheBerlios,项目名称:pida-svn,代码行数:12,代码来源:pscyntilla.py


示例17: __init__

 def __init__(self, hunk):
     self.hunk = hunk
     self.lines = self.hunk.split("\n")
     self.linecount = len(self.lines)
     self.insertions = 0
     self.deletions = 0
     self.added = []
     self.removed = []
     self.ID = sre.compile("\$Id:{0,1}.*\$")
     self.Revision = sre.compile("\$Revision:{0,1}.*\$")
     self.Author = sre.compile("\$Author:{0,1}.*\$")
     self.Date = sre.compile("\$Date:{0,1}.*\$")
     self.ok = 0
     for i in range(0, self.linecount):
         if self.lines[i].startswith("+"):
             self.insertions += 1
             self.added.append(self.lines[i])
         if self.lines[i].startswith("-"):
             self.deletions += 1
             self.removed.append(self.lines[i])
     self.checkhunk()
开发者ID:hackndev,项目名称:tools,代码行数:21,代码来源:splitpatch.py


示例18: getSuggestionListFile

def getSuggestionListFile(word, filename):
    try:
        f = file(filename, 'r')
    except IOError:
        return []
    pattern = sre.compile(word+r'.*?\b')
    matches = []
    for line in f.readlines():
        for match in pattern.findall(line):
            if match != word and match not in matches:
                matches.append(match)
    matches.sort()
    return matches
开发者ID:ThomRosario,项目名称:as,代码行数:13,代码来源:pythonCompletion.py


示例19: from_one_line

def from_one_line(msg):
    # (?<!\\) is a lookbehind assertion which asks anything but '\'
    # to match the regexp that follows it

    # So here match '\\n' but not if you have a '\' before that
    re = sre.compile(r"(?<!\\)\\n")
    msg = re.sub("\n", msg)
    msg = msg.replace("\\\\", "\\")
    # s12 = 'test\\ntest\\\\ntest'
    # s13 = re.sub('\n', s12)
    # s14 s13.replace('\\\\', '\\')
    # s14
    # 'test\ntest\\ntest'
    return msg
开发者ID:pacoqueen,项目名称:bbinn,代码行数:14,代码来源:helpers.py


示例20: loadurl

def loadurl(urlname,context={}):
    """resolves a url and returns the results
    if the url starts with file:// then it will try to find a static file
    if it starts with python:// then it will try to find a python object"""
    parameter_re = "\s*(\w+\s*=|)\s*\w+\s*"
    namedparameter_re = "\s*((?P<key>\w+)\s*=|)\s*(?P<value>\w+)\s*"
    identifier_re = "(\w+[.])+\w+"
    module_re = "(?P<module>(%s))" % identifier_re
    parameters_re = "(?P<params>(%s,)*%s)" % (parameter_re, parameter_re)
    innerid_re = "[.]\w+"
    import_re = "\s*%s\s*(\(%s\)\s*|)" % (module_re, parameters_re)
    import_matcher = sre.compile(import_re)
    import_match = import_matcher.match(urlname)
    if not import_match:
        raise ValueError("Invalid overlay definition: %s" % urlname)
    module = import_match.group("module")
    moduleparts = module.split(".")
    
    #load the first part as that should be a module
    modulename = moduleparts.pop(0)
    includeobject = imp.load_module(modulename,*imp.find_module(modulename))

    #cycle through the rest of the url parts gathering objects as we go
    for part in moduleparts:
        if hasattr(includeobject,part):
            includeobject = getattr(includeobject,part)

    if callable(includeobject):
        parameters = import_match.group("params")
        includeargs = []
        includekwargs = {}
        if parameters:
            for parameterdef in parameters.split(","):
                namedparameter_match = sre.match(namedparameter_re, parameterdef)
                key = namedparameter_match.group("key")
                value = namedparameter_match.group("value")
                value = context.get(value)
                if key:
                    if isinstance(key, unicode):
                        key = key.encode("utf-8")
                    includekwargs[key] = context.get(value,value)
                else:
                    includeargs.append(context.get(value,value))
        includeobject = includeobject(*includeargs, **includekwargs)
    return str(includeobject)

    includesource = open(os.path.join(namespacedir, filename), "r").read()
    return includesource
开发者ID:cc-archive,项目名称:jtoolkit,代码行数:48,代码来源:DOMOverlay.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sre_compile.compile函数代码示例发布时间:2022-05-27
下一篇:
Python srctools.Vec类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap