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

Python web.utf8函数代码示例

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

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



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

示例1: sendmail_to_signatory

def sendmail_to_signatory(user, pid):
    p = db.select('petition', where='id=$pid', vars=locals())[0]
    p.url = 'http//watchdog.net/c/%s' % (pid) 
    token = auth.get_secret_token(user.email)
    msg = render_plain.signatory_mailer(user, p, token)
    #@@@ shouldn't this web.utf8 stuff taken care by in web.py?
    web.sendmail(web.utf8(config.from_address), web.utf8(user.email), web.utf8(msg.subject.strip()), web.utf8(msg))
开发者ID:christopherbdnk,项目名称:watchdog,代码行数:7,代码来源:petition.py


示例2: getkeys

 def getkeys(self, namespace, lang=None):
     namespace = web.utf8(namespace)
     lang = web.utf8(lang)
     
     # making a simplified assumption here.
     # Keys for a language are all the strings defined for that language and 
     # all the strings defined for default language. By doing this, once a key is 
     # added to default lang, then it will automatically appear in all other languages.
     keys = set(self._data.get((namespace, lang), {}).keys() + self._data.get((namespace, DEFAULT_LANG), {}).keys())
     return sorted(keys)
开发者ID:EdwardBetts,项目名称:infogami,代码行数:10,代码来源:i18n.py


示例3: simple_diff

def simple_diff(a, b):
    a = a or ''
    b = b or ''
    if a is None: a = ''
    if b is None: b = ''
    a = web.utf8(a).split(' ')
    b = web.utf8(b).split(' ')
    out = []
    for (tag, i1, i2, j1, j2) in SequenceMatcher(a=a, b=b).get_opcodes():
        out.append(web.storage(tag=tag, left=' '.join(a[i1:i2]), right=' '.join(b[j1:j2])))
    return out
开发者ID:EdwardBetts,项目名称:infogami,代码行数:11,代码来源:diff.py


示例4: __call__

    def __call__(self, handler):
        # temp hack to handle languages and users during upstream-to-www migration
        if web.ctx.path.startswith("/l/"):
            raise web.seeother("/languages/" + web.ctx.path[len("/l/"):])

        if web.ctx.path.startswith("/user/"):
            if not web.ctx.site.get(web.ctx.path):
                raise web.seeother("/people/" + web.ctx.path[len("/user/"):])

        real_path, readable_path = get_readable_path(web.ctx.site, web.ctx.path, self.patterns, encoding=web.ctx.encoding)

        #@@ web.ctx.path is either quoted or unquoted depends on whether the application is running
        #@@ using builtin-server or lighttpd. Thats probably a bug in web.py.
        #@@ take care of that case here till that is fixed.
        # @@ Also, the redirection must be done only for GET requests.
        if readable_path != web.ctx.path and readable_path != urllib.quote(web.utf8(web.ctx.path)) and web.ctx.method == "GET":
            raise web.redirect(web.safeunicode(readable_path) + web.safeunicode(web.ctx.query))

        web.ctx.readable_path = readable_path
        web.ctx.path = real_path
        web.ctx.fullpath = web.ctx.path + web.ctx.query
        out = handler()
        V2_TYPES = ['works', 'books', 'people', 'authors',
                    'publishers', 'languages', 'account']
        if out and any(web.ctx.path.startswith('/%s/' % _type) for _type in V2_TYPES):
            out.v2 = True
        return out
开发者ID:internetarchive,项目名称:openlibrary,代码行数:27,代码来源:readableurls.py


示例5: __str__

 def __str__(self):
     def get(lang): 
         return self._i18n._data.get((self._namespace, lang))
     default_data = get(DEFAULT_LANG) or {}
     data = get(web.ctx.lang) or default_data
     text = data.get(self._key) or default_data.get(self._key) or self._key
     return web.utf8(text)
开发者ID:EdwardBetts,项目名称:infogami,代码行数:7,代码来源:i18n.py


示例6: output

def output(string_):
    """Appends `string_` to the response."""
    string_ = web.utf8(string_)
    if web.ctx.get('flush'):
        web.ctx._write(string_)
    else:
        web.ctx.output += str(string_)
开发者ID:LittleForker,项目名称:webpy,代码行数:7,代码来源:migration.py


示例7: _load_template

def _load_template(page, lazy=False):
    """load template from a wiki page."""
    if lazy:
        page = web.storage(key=page.key, body=web.utf8(_stringify(page.body)))
        wikitemplates[page.key] = LazyTemplate(lambda: _load_template(page))
    else:
        wikitemplates[page.key] = _compile_template(page.key, page.body)
开发者ID:anandology,项目名称:infogami,代码行数:7,代码来源:code.py


示例8: replace_header

def replace_header(hdr, value):
    """
    设置header
    """
    hdr, value = web.utf8(hdr), web.utf8(value)
    # protection against HTTP response splitting attack
    if '\n' in hdr or '\r' in hdr or '\n' in value or '\r' in value:
        raise ValueError, 'invalid characters in header'
    
    for i, temp in enumerate(web.ctx.headers):
        h, v = temp
        if h.lower() == hdr.lower():
            web.ctx.headers[i] = (hdr, value)
            break
    else:
        web.ctx.headers.append((hdr, value))
开发者ID:IthacaDream,项目名称:nowater_web,代码行数:16,代码来源:baseutils.py


示例9: __disabled_POST

    def __disabled_POST(self):
        i = web.input(_method='post')
        i['type.key'] = '/type/comment'
        i['_comment'] = ''
        path = '/c/'+ str(get_random_string())

        # prevent most common spam
        if 'url' in  i['comment'] and 'link' in i['comment'] and 'http://' in i['comment']:
            return web.seeother(i['article.key'])
        if '<a href' in  i['comment'] and 'http://' in i['comment']:
            return web.seeother(i['article.key'])
        if i['website'] in ['http://www.yahoo.com/', 'http://www.google.com/', 'http://www.bing.com/', "http://www.facebook.com/"]:
            return web.seeother(i['article.key'])            
          
        query = {
            'key': path,
            'type': {'key': "/type/comment"},
            'article': {"key": i["article.key"]},
            'comment': {'type': '/type/text', 'value': i['comment']},
            'author': i['author'],
            'website': i['website'],
            'email': i['email'],
            'permission':  {'key': '/permission/restricted'} 
        }

        web.ctx.site.save(query, comment='new comment')

        c = web.ctx.site.get(path)
        msg = render.comment_email(c, web.ctx.home)
        try:
            web.sendmail(config.from_address, config.comment_recipients, web.utf8(msg.subject).strip(), web.utf8(msg))
        except:
            import traceback
            traceback.print_exc()
        web.seeother(i['article.key']+"#comments")
开发者ID:anandology,项目名称:kottapalli,代码行数:35,代码来源:code.py


示例10: replace_macros

def replace_macros(html, macros):
    """Replaces the macro place holders with real macro output."""    
    for placeholder, macro_info in macros.items():
        name, args = macro_info
        html = html.replace("<p>%s\n</p>" % placeholder, web.utf8(call_macro(name, args)))
        
    return html
开发者ID:EdwardBetts,项目名称:infogami,代码行数:7,代码来源:macro.py


示例11: __call__

 def __call__(self, *a):
     try:
         a = [x or "" for x in a]
         return str(self) % tuple(web.utf8(x) for x in a)
     except:
         print >> web.debug, 'failed to substitute (%s/%s) in language %s' % (self._namespace, self._key, web.ctx.lang)
     return str(self)
开发者ID:EdwardBetts,项目名称:infogami,代码行数:7,代码来源:i18n.py


示例12: _load_macro

def _load_macro(page, lazy=False):
    if lazy:
        page = web.storage(key=page.key, macro=web.utf8(_stringify(page.macro)), description=page.description or "")
        wikimacros[page.key] = LazyTemplate(lambda: _load_macro(page))
    else:
        t = _compile_template(page.key, page.macro)
        t.__doc__ = page.description or ''
        wikimacros[page.key] = t
开发者ID:anandology,项目名称:infogami,代码行数:8,代码来源:code.py


示例13: safeeval_args

def safeeval_args(args):
    """Evalues the args string safely using templator."""
    result = [None]
    def f(*args, **kwargs):
        result[0] = args, kwargs
    code = "$def with (f)\n$f(%s)" % args
    web.template.Template(web.utf8(code))(f)
    return result[0]
开发者ID:EdwardBetts,项目名称:infogami,代码行数:8,代码来源:macro.py


示例14: POST

	def POST(self):
		post = web.input()
		if post.get('u_email') and post.get('u_pass'):	
			user = pduser.loaduser_by_email(post.u_email)
			if user and user.u_pass==md5.new(web.utf8(post.u_pass)).hexdigest():
				login.Login.encode_cookie(user.u_id)
				return web.seeother(web.ctx.sitehost+web.input().get('ref',"/"))
		return render.login(post)
开发者ID:waile23,项目名称:todo,代码行数:8,代码来源:account.py


示例15: internal_redirect

def internal_redirect(path, method, query, data):
    # does an internal redirect within the application
    from webapp import app
    env = web.ctx.env
    env['REQUEST_METHOD'] = method
    env['PATH_INFO'] = path
    env['QUERY_STRING'] = web.utf8(query)

    cookie_headers = [(k, v) for k, v in web.ctx.headers if k == 'Set-Cookie'] 
    app.load(env)

    env['HTTP_COOKIE'] = env.get('HTTP_COOKIE', '') + ';' + ";".join([v for (k, v) in cookie_headers])
    web.ctx.headers = cookie_headers

    if method == 'POST':
        web.ctx.data = web.utf8(data)
    return app.handle()
开发者ID:jdthomas,项目名称:watchdog,代码行数:17,代码来源:auth.py


示例16: _compile_template

def _compile_template(name, text):
    text = web.utf8(_stringify(text))
            
    try:
        return web.template.Template(text, filter=web.websafe, filename=name)
    except (web.template.ParseError, SyntaxError), e:
        print >> web.debug, 'Template parsing failed for ', name
        import traceback
        traceback.print_exc()
        raise ValidationException("Template parsing failed: " + str(e))
开发者ID:anandology,项目名称:infogami,代码行数:10,代码来源:code.py


示例17: header

 def header(self, hdr, value, unique=True):
     """
     Adds 'hdr: value' to the response.
     @type hdr: str
     @param hdr: valid http header key
     @type value: str
     @param value: valid value for corresponding header key
     @type unique: bool
     @param unique: whether only one instance of the header is permitted.
     """
     hdr = web.utf8(hdr)
     value = web.utf8(value)
     previous = []
     for h, v in web.ctx.headers:
         if h.lower() == hdr.lower():
             previous.append((h, v))
     if unique:
         for p in previous:
             web.ctx.headers.remove(p)
     web.ctx.headers.append((hdr, value))
开发者ID:jortel,项目名称:agenthub,代码行数:20,代码来源:controller.py


示例18: GET

 def GET(self, id):
     db = NovelDB()
     novel = db.get_novel_info(id)        
     file = get_txt_file(str(id), web.utf8(novel.title))
     
     if file:
         web.replace_header("Content-Type", "text/plaintext")
         web.replace_header("Content-Disposition", "attachment; filename=%s.txt" % id)
         web.header("X-Accel-Redirect", "/download_txt/%s" % file)
         return "ok"
     else:
         return "出错了,请联系[email protected]"
开发者ID:IthacaDream,项目名称:nowater_web,代码行数:12,代码来源:show.py


示例19: __call__

    def __call__(self, handler):
        real_path, readable_path = self.get_readable_path(web.ctx.path, encoding=web.ctx.encoding)

        #@@ web.ctx.path is either quoted or unquoted depends on whether the application is running
        #@@ using builtin-server or lighttpd. Thats probably a bug in web.py. 
        #@@ take care of that case here till that is fixed.
        # @@ Also, the redirection must be done only for GET requests.
        if readable_path != web.ctx.path and readable_path != urllib.quote(web.utf8(web.ctx.path)) and web.ctx.method == "GET":
            raise web.seeother(web.safeunicode(readable_path) + web.safeunicode(web.ctx.query))

        web.ctx.readable_path = readable_path
        web.ctx.path = real_path
        web.ctx.fullpath = web.ctx.path + web.ctx.query
        return handler()
开发者ID:sribanta,项目名称:openlibrary,代码行数:14,代码来源:processors.py


示例20: header

def header(hdr, value, unique=True):
    """
    Adds 'hdr: value' to the response.
    This function has, in some regards, the opposite semantics of the web.header
    function. If unique is True, the hdr will be overwritten if it already
    exists in the response. Otherwise it will be appended.
    @type hdr: str
    @param hdr: valid http header key
    @type value: str
    @param value: valid value for corresponding header key
    @type unique: bool
    @param unique: whether only one instance of the header is in the response
    """
    hdr = web.utf8(hdr)
    value = web.utf8(value)
    previous = []
    for h, v in web.ctx.headers:
        if h.lower() == hdr.lower():
            previous.append((h, v))
    if unique:
        for p in previous:
            web.ctx.headers.remove(p)
    web.ctx.headers.append((hdr, value))
开发者ID:nareshbatthula,项目名称:pulp,代码行数:23,代码来源:http.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python web.verifyLogin函数代码示例发布时间:2022-05-26
下一篇:
Python web.urlquote函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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