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


Python web.utf8函数代码示例

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


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


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