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


Python util.escape函数代码示例

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


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

示例1: setProfile

def setProfile(host, vmid, cpus, ram, bandwidth, **other):
	assert getState(host, vmid) == generic.State.PREPARED
	res = {"diskused": 1000000, "lograte": 10000, "events": 10000, "random": 10000}
	res.update({"cpu": float(cpus), "memory": int(ram)*1000000, "netrecv": int(bandwidth), "netsend": int(bandwidth)})
	resConf = "\n".join(["resource %s %s" % (key, value) for (key, value) in res.iteritems()])
	host.execute("echo -e %s > %s" % (util.escape(resConf), util.escape(_profileFile(vmid))) )
	
开发者ID:m3z,项目名称:ToMaTo,代码行数:6,代码来源:repy.py

示例2: unpackdir

def unpackdir(host, archive, dir, args=""):
    assert existsFile(host, archive), "Archive does not exist"
    if archive.endswith(".gz") and not "-z" in args:
        args = args + " -z"
    if archive.endswith(".bz2") and not "-j" in args:
        args = args + " -j"
    return host.execute("tar -xf %s -C %s %s" % (util.escape(archive), util.escape(dir), args))
开发者ID:m3z,项目名称:ToMaTo,代码行数:7,代码来源:fileutil.py

示例3: ping

def ping(host, ip, samples=10, maxWait=5, iface=None):
	assert samples >= 2
	iface = "" if iface is None else "-I %s" % util.escape(iface)
	cmd = "ping" if isIpv4(ip) else "ping6" 
	res = host.execute("%s -A -c %d -n -q -w %d %s %s" % (cmd, samples, maxWait, iface, util.escape(ip)))
	if not res:
		return
	import re
	spattern = re.compile("(\d+) packets transmitted, (\d+) received(, \+(\d+) errors)?, (\d+)% packet loss, time (\d+)(m?s)")
	dpattern = re.compile("rtt min/avg/max/mdev = (\d+\.\d+)/(\d+\.\d+)/(\d+\.\d+)/(\d+\.\d+) (m?s)(, pipe \d+)?, ipg/ewma (\d+\.\d+)/(\d+\.\d+) (m?s)")
	summary = False
	details = False
	for line in res.splitlines():
		if spattern.match(line):
			(transmitted, received, dummy, errors, loss, total, unit) = spattern.match(line).groups()
			(transmitted, received, errors, loss, total) = (int(transmitted), int(received), int(errors) if errors else None, float(loss)/100.0, float(total))
			summary = True
		if dpattern.match(line):
			(rttmin, rttavg, rttmax, rttstddev, rttunit, dummy, ipg, ewma, ipg_ewma_unit) = dpattern.match(line).groups()
			(rttmin, rttavg, rttmax, rttstddev, ipg, ewma) = (float(rttmin), float(rttavg), float(rttmax), float(rttstddev), float(ipg), float(ewma))
			details = True
	if not summary or not details or errors:
		return
	import math
	loss = 1.0 - math.sqrt(1.0 - loss)
	avg = rttavg / 2.0
	stddev = rttstddev / 2.0
	if rttunit == "s":
		avg = avg * 1000.0
		stddev = stddev * 1000.0
	return (loss, avg, stddev)
开发者ID:m3z,项目名称:ToMaTo,代码行数:31,代码来源:ifaceutil.py

示例4: log_rating

 def log_rating(self, filename, rating):
     if filename:
         query = 'UPDATE music SET rating=%i WHERE \
                  path = "%s" and filename = "%s"' % (int(rating),
                  util.escape(os.path.dirname(filename)),
                  util.escape(os.path.basename(filename)) )
         self.runquery(query)
开发者ID:adozenlines,项目名称:freevo1,代码行数:7,代码来源:logger.py

示例5: fetchWeekly

def fetchWeekly(cur):
    cur.execute('select d_id,count(*) from response where replyDate > (select subtime(now(), \'7 00:00:00\')) group by d_id order by count(*) desc limit 5')
    MAX_RESPONSES = 5
    convos = []
    for r in cur.fetchall():
        d_id = r[0]
        cur.execute('select category.name,user_id,title,content from conversation inner join category using (cat_id) where d_id=%s',(d_id,))
        test = cur.fetchone()
        name = util.formatCategoryName(test[0]);
        title = util.escape(test[2].encode('utf-8'))
        poster = fetchUser(cur,test[1])
        
        item = {'user':poster,'content':util.escape(test[3].encode('utf-8')).replace('\n','<br />')}
        
        cur.execute('select user_id,content from response where d_id=%s order by replyDate desc limit '+str(MAX_RESPONSES),(d_id,))
        responses = []
        for r2 in cur.fetchall():
            responses.insert(0,{'user':fetchUser(cur,r2[0]),'content':util.escape(r2[1].encode('utf-8')).replace('\n','<br />')})
        if (responses < MAX_RESPONSES):
            responses.insert(0,item)
            
        # count replies
        numReplies = r[1]

        # count participants
        cur.execute('select DISTINCT user_id from response where d_id=%s',(d_id,))
        uids = set()
        for u in cur.fetchall():
            uids.add(u[0])
        uids.add(poster['user_id'])
        convos.append({'title':title,'category_name':name,'responses':responses,'numReplies':numReplies,'numUsers':len(uids)})
    return convos
开发者ID:outerclub,项目名称:OuterClub,代码行数:32,代码来源:database.py

示例6: setLinkEmulation

def setLinkEmulation(host, dev, bandwidth=None, **kwargs):
	assert ifaceutil.interfaceExists(host, dev)
	netem_ref = "dev %s root handle 1:0" % util.escape(dev)
	if not bandwidth is None:
		netem_ref = "dev %s parent 1:1 handle 10:" % util.escape(dev)
		_tc_mod(host, "qdisc", "dev %s root handle 1:" % util.escape(dev), _buildTbf(bandwidth))
	_tc_mod(host, "qdisc", netem_ref, _buildNetem(bandwidth=bandwidth, **kwargs))
开发者ID:david-hock,项目名称:ToMaTo,代码行数:7,代码来源:tc.py

示例7: log_track

 def log_track(self, filename):
     if filename:
         query = 'UPDATE music SET play_count=play_count+1,last_play=%f WHERE \
                  path = "%s" and filename = "%s"' % (time.time(),
                  util.escape(os.path.dirname(filename)),
                  util.escape(os.path.basename(filename)) )
         self.runquery(query)
开发者ID:adozenlines,项目名称:freevo1,代码行数:7,代码来源:logger.py

示例8: bridgeDisconnect

def bridgeDisconnect(host, bridge, iface, deleteBridgeIfLast=False):
	assert bridgeExists(host, bridge), "Bridge does not exist: %s" % bridge
	if not iface in bridgeInterfaces(host, bridge):
		return
	host.execute("brctl delif %s %s" % (util.escape(bridge), util.escape(iface)))
	assert not iface in bridgeInterfaces(host, bridge), "Interface %s could not be removed from bridge %s" % (iface, bridge)
	if deleteBridgeIfLast and not bridgeInterfaces(host, bridge):
		bridgeRemove(host, bridge)
开发者ID:m3z,项目名称:ToMaTo,代码行数:8,代码来源:ifaceutil.py

示例9: packdir

def packdir(host, archive, dir, args=""):
    assert existsDir(host, dir), "Directory does not exist"
    if archive.endswith(".gz") and not "-z" in args:
        args = args + " -z"
    if archive.endswith(".bz2") and not "-j" in args:
        args = args + " -j"
    res = host.execute("tar -cf %s -C %s %s ." % (util.escape(archive), util.escape(dir), args))
    assert existsFile(host, archive), "Failed to pack directory: %s" % res
    return res
开发者ID:m3z,项目名称:ToMaTo,代码行数:9,代码来源:fileutil.py

示例10: setIncomingRedirect

def setIncomingRedirect(host, srcDev, dstDev):
	assert ifaceutil.interfaceExists(host, srcDev)
	assert ifaceutil.interfaceExists(host, dstDev)
	_tc_mod(host, "qdisc", "dev %s ingress" % util.escape(srcDev))
	""" 
	Protocol all would forward all traffic but that results
	in ARP traffic being multiplied and causing lots of traffic
	""" 
	_tc_mod(host, "filter", "dev %s parent ffff:" % util.escape(srcDev), \
	 "protocol all prio 49152 u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev %s" % util.escape(dstDev))
开发者ID:david-hock,项目名称:ToMaTo,代码行数:10,代码来源:tc.py

示例11: bridgeConnect

def bridgeConnect(host, bridge, iface):
	if iface in bridgeInterfaces(host, bridge):
		return
	assert interfaceExists(host, iface), "Interface does not exist: %s" % iface
	if not bridgeExists(host, bridge):
		bridgeCreate(host, bridge)
	oldbridge = interfaceBridge(host, iface)
	if oldbridge:
		bridgeDisconnect(host, oldbridge, iface)
	host.execute("brctl addif %s %s" % (util.escape(bridge), util.escape(iface)))
	assert iface in bridgeInterfaces(host, bridge), "Interface %s could not be connected to bridge %s" % (iface, bridge)
开发者ID:m3z,项目名称:ToMaTo,代码行数:11,代码来源:ifaceutil.py

示例12: setLinkEmulation

def setLinkEmulation(host, dev, bandwidth=None, keepBandwidth=False, **kwargs):
	assert ifaceutil.interfaceExists(host, dev)
	netem_ref = "dev %s root handle 1:0" % util.escape(dev)
	cmd = ""
	if not bandwidth is None:
		netem_ref = "dev %s parent 1:1 handle 10:" % util.escape(dev)
		if not keepBandwidth:
			cmd = _tc_cmd("qdisc", "replace", "dev %s root handle 1:" % util.escape(dev), _buildTbf(bandwidth))
			cmd += ";"
	cmd += _tc_cmd("qdisc", "replace", netem_ref, _buildNetem(bandwidth=bandwidth, **kwargs))
	host.execute(cmd)
开发者ID:m3z,项目名称:ToMaTo,代码行数:11,代码来源:tc.py

示例13: disconnectInterfaces

def disconnectInterfaces(host, if1, if2, id):
	#calculate table ids
	table1 = 1000 + id * 2
	table2 = 1000 + id * 2 + 1
	try:
		#remove rules
		host.execute ( "ip rule del iif %s" % util.escape(if1) )
		host.execute ( "ip rule del iif %s" % util.escape(if2) )
		#remove routes
		host.execute ( "ip route del table %s default" % util.escape(table1) )
		host.execute ( "ip route del table %s default" % util.escape(table2) )
	except exceptions.CommandError, exc:
		if exc.errorCode != 2: #Rule does not exist
			raise
开发者ID:david-hock,项目名称:ToMaTo,代码行数:14,代码来源:ifaceutil.py

示例14: _crawl_once

 def _crawl_once(page, depth_):
     self.wait()
     echo("Trying", escape(page.title), "at", depth_, flush = True)
     if match_function(page):
         echo("Taking", escape(page.title))
         return page
     elif depth_ >= self.depth:
         return None
     else:
         state = LinkState(page, self.depth - depth_, self.depth)
         link = self.selector.select_link(state)
         if link is None:
             return None
         new_page = wikipedia.page(link)
         return _crawl_once(new_page, depth_ + 1)
开发者ID:Mercerenies,项目名称:net-game,代码行数:15,代码来源:algorithm.py

示例15: clearLinkEmulation

def clearLinkEmulation(host, dev):
	assert ifaceutil.interfaceExists(host, dev)
	try:
		host.execute(_tc_cmd("qdisc", "del", "root dev %s" % util.escape(dev)))
	except exceptions.CommandError, exc:
		if not "No such file or directory" in exc.errorMessage:
			raise
开发者ID:m3z,项目名称:ToMaTo,代码行数:7,代码来源:tc.py


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