请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.escape函数代码示例

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

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



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


示例16: bridgeCreate

def bridgeCreate(host, bridge):
	try:
		host.execute("brctl addbr %s" % util.escape(bridge))
	except exceptions.CommandError:
		if not bridgeExists(host, bridge):
			raise
	assert bridgeExists(host, bridge), "Bridge cannot be created: %s" % bridge
开发者ID:m3z,项目名称:ToMaTo,代码行数:7,代码来源:ifaceutil.py


示例17: startDhcp

def startDhcp(host, iface):
	for cmd in ["/sbin/dhclient", "/sbin/dhcpcd"]:
		try:
			return host.execute("[ -e %s ] && %s %s" % (cmd, cmd, util.escape(iface)))
		except exceptions.CommandError, err:
			if err.errorCode != 8:
				raise			
开发者ID:m3z,项目名称:ToMaTo,代码行数:7,代码来源:ifaceutil.py


示例18: insertComment

def insertComment(conn, comment_data):
    author = comment_data['author']
    url = comment_data['url']
    comment = util.escape(comment_data['comment'])
    email = comment_data['email']
    ip = comment_data['ip']
    name= comment_data['name']
    dt = time.time()

    logging.info('Inserting comment by '+author)

    cursor = conn.cursor()

    insert = """
        insert into blog_item_comments
        (item_name, comment, name, website, email, ip, date)
        values (?,?,?,?,?,?,?)
        """

    getItemName = """
        select item_name
        from blog_items
        where item_title = ?
        """

    cursor.execute(getItemName, [name])
    data = cursor.fetchall()[0]
    item_name = data[0]
    logging.debug("item_name " + item_name)

    insert_data = [item_name, comment, author, url, email, ip, dt]
    cursor.execute(insert, insert_data)
    conn.commit()
开发者ID:kdorland,项目名称:txtblog,代码行数:33,代码来源:manager.py


示例19: fileTransfer

def fileTransfer(src_host,
                 src_path,
                 dst_host,
                 dst_path,
                 direct=False,
                 compressed=False):
    if compressed:
        src = src_host.getHostServer().randomFilename()
        dst = dst_host.getHostServer().randomFilename()
        compress(src_host, src_path, src)
    else:
        if direct:
            src = src_path
            dst = dst_path
            mode = src_host.execute(
                "stat -c %%a %s" % util.escape(src)).strip()
        else:
            dst = dst_host.getHostServer().randomFilename()
            src = src_host.getHostServer().randomFilename()
            copy(src_host, src_path, src)
    chmod(src_host, src, 644)
    url = src_host.getHostServer().downloadGrant(src, "file")
    res = fetch(dst_host, url, dst)
    assert existsFile(dst_host, dst), "Failure to transfer file: %s" % res
    if compressed:
        uncompress(dst_host, dst, dst_path)
        delete(dst_host, dst)
        delete(src_host, src)
    else:
        if not direct:
            copy(dst_host, dst, dst_path)
            delete(dst_host, dst)
            delete(src_host, src)
        else:
            chmod(src_host, src_path, mode)
开发者ID:m3z,项目名称:ToMaTo,代码行数:35,代码来源:fileutil.py


示例20: _expr_test_function_def

def _expr_test_function_def(test_name, expr_string, expr_kind,
                            type, expected_result):
    template = "    def test_%s(self):\n" + \
               "        self._check_expr('%s','%s','%s','%s')\n\n"
    return template % tuple(escape(t) for t in (test_name, expr_string,
                                                expr_kind, type,
                                                expected_result))
开发者ID:jruberg,项目名称:Pyty,代码行数:7,代码来源:generate_tests.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python util.exec_remote_command函数代码示例发布时间:2022-05-27
下一篇:
Python util.error函数代码示例发布时间: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