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

Python i18n._函数代码示例

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

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



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

示例1: _default_password_checker

def _default_password_checker(cfg, username, password):
    """ Check if a password is secure enough.
        We use a built-in check to get rid of the worst passwords.

        We do NOT use cracklib / python-crack here any more because it is
        not thread-safe (we experienced segmentation faults when using it).

        If you don't want to check passwords, use password_checker = None.

        :returns: None if there is no problem with the password,
                 some unicode object with an error msg, if the password is problematic.
    """
    # in any case, do a very simple built-in check to avoid the worst passwords
    if len(password) < 6:
        return _("Password is too short.")
    if len(set(password)) < 4:
        return _("Password has not enough different characters.")

    username_lower = username.lower()
    password_lower = password.lower()
    if username in password or password in username or \
       username_lower in password_lower or password_lower in username_lower:
        return _("Password is too easy to guess (password contains name or name contains password).")

    keyboards = (ur"`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./", # US kbd
                 ur"^1234567890ß´qwertzuiopü+asdfghjklöä#yxcvbnm,.-", # german kbd
                ) # add more keyboards!
    for kbd in keyboards:
        rev_kbd = kbd[::-1]
        if password in kbd or password in rev_kbd or \
           password_lower in kbd or password_lower in rev_kbd:
            return _("Password is too easy to guess (keyboard sequence).")
    return None
开发者ID:pombredanne,项目名称:moin2,代码行数:33,代码来源:default.py


示例2: get_bool

def get_bool(arg, name=None, default=None):
    """
    For use with values returned from parse_quoted_separated or given
    as macro parameters, return a boolean from a unicode string.
    Valid input is 'true'/'false', 'yes'/'no' and '1'/'0' or None for
    the default value.

    :param arg: The argument, may be None or a unicode string
    :param name: Name of the argument, for error messages
    :param default: default value if arg is None
    :rtype: boolean or None
    :returns: the boolean value of the string according to above rules
              (or default value)
    """
    assert default is None or isinstance(default, bool)
    if arg is None:
        return default
    elif not isinstance(arg, unicode):
        raise TypeError('Argument must be None or unicode')
    arg = arg.lower()
    if arg in [u'0', u'false', u'no']:
        return False
    elif arg in [u'1', u'true', u'yes']:
        return True
    else:
        if name:
            raise ValueError(
                _('Argument "%(name)s" must be a boolean value, not "%(value)s"', name=name, value=arg))
        else:
            raise ValueError(
                _('Argument must be a boolean value, not "%(value)s"', value=arg))
开发者ID:gitpraetorianlabs,项目名称:moin-2.0,代码行数:31,代码来源:paramparser.py


示例3: get_int

def get_int(arg, name=None, default=None):
    """
    For use with values returned from parse_quoted_separated or given
    as macro parameters, return an integer from a unicode string
    containing the decimal representation of a number.
    None is a valid input and yields the default value.

    :param arg: The argument, may be None or a unicode string
    :param name: Name of the argument, for error messages
    :param default: default value if arg is None
    :rtype: int or None
    :returns: the integer value of the string (or default value)
    """
    assert default is None or isinstance(default, (int, long))
    if arg is None:
        return default
    elif not isinstance(arg, unicode):
        raise TypeError('Argument must be None or unicode')
    try:
        return int(arg)
    except ValueError:
        if name:
            raise ValueError(
                _('Argument "%(name)s" must be an integer value, not "%(value)s"', name=name, value=arg))
        else:
            raise ValueError(
                _('Argument must be an integer value, not "%(value)s"', value=arg))
开发者ID:gitpraetorianlabs,项目名称:moin-2.0,代码行数:27,代码来源:paramparser.py


示例4: get_float

def get_float(arg, name=None, default=None):
    """
    For use with values returned from parse_quoted_separated or given
    as macro parameters, return a float from a unicode string.
    None is a valid input and yields the default value.

    :param arg: The argument, may be None or a unicode string
    :param name: Name of the argument, for error messages
    :param default: default return value if arg is None
    :rtype: float or None
    :returns: the float value of the string (or default value)
    """
    assert default is None or isinstance(default, (int, long, float))
    if arg is None:
        return default
    elif not isinstance(arg, unicode):
        raise TypeError('Argument must be None or unicode')
    try:
        return float(arg)
    except ValueError:
        if name:
            raise ValueError(
                _('Argument "%(name)s" must be a floating point value, not "%(value)s"', name=name, value=arg))
        else:
            raise ValueError(
                _('Argument must be a floating point value, not "%(value)s"', value=arg))
开发者ID:gitpraetorianlabs,项目名称:moin-2.0,代码行数:26,代码来源:paramparser.py


示例5: get_complex

def get_complex(arg, name=None, default=None):
    """
    For use with values returned from parse_quoted_separated or given
    as macro parameters, return a complex from a unicode string.
    None is a valid input and yields the default value.

    :param arg: The argument, may be None or a unicode string
    :param name: Name of the argument, for error messages
    :param default: default return value if arg is None
    :rtype: complex or None
    :returns: the complex value of the string (or default value)
    """
    assert default is None or isinstance(default, (int, long, float, complex))
    if arg is None:
        return default
    elif not isinstance(arg, unicode):
        raise TypeError('Argument must be None or unicode')
    try:
        # allow writing 'i' instead of 'j'
        arg = arg.replace('i', 'j').replace('I', 'j')
        return complex(arg)
    except ValueError:
        if name:
            raise ValueError(
                _('Argument "%(name)s" must be a complex value, not "%(value)s"', name=name, value=arg))
        else:
            raise ValueError(
                _('Argument must be a complex value, not "%(value)s"', value=arg))
开发者ID:gitpraetorianlabs,项目名称:moin-2.0,代码行数:28,代码来源:paramparser.py


示例6: trash

def trash(namespace):
    """
    Returns the trashed items.
    """
    trash = _trashed(namespace)
    return render_template('admin/trash.html',
                           headline=_(u'Trashed Items'),
                           title_name=_(u'Trashed Items'),
                           results=trash)
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:9,代码来源:views.py


示例7: interwikihelp

def interwikihelp():
    """display a table with list of known interwiki names / urls"""
    headings = [_('InterWiki name'),
                _('URL'),
               ]
    rows = sorted(app.cfg.interwiki_map.items())
    return render_template('admin/interwikihelp.html',
                           title_name=_(u"Interwiki Help"),
                           headings=headings,
                           rows=rows)
开发者ID:pombredanne,项目名称:moin2,代码行数:10,代码来源:views.py


示例8: button_filter

def button_filter(tagname, attributes, contents, context, bind):
    """Show translated text in clickable buttons and submits."""
    if bind is None:
        return contents
    if tagname == 'input':
        if ('value' not in attributes and
                attributes.get('type') in ['submit', 'reset', ]):
            attributes['value'] = _(bind.default_value)
    elif tagname == 'button' and not contents:
        contents = _(bind.default_value)
    return contents
开发者ID:denedios,项目名称:moin-2.0,代码行数:11,代码来源:forms.py


示例9: itemsize

def itemsize():
    """display a table with item sizes"""
    headings = [_('Size'),
                _('Item name'),
               ]
    rows = [(rev.meta[SIZE], rev.meta[NAME])
            for rev in flaskg.storage.documents(wikiname=app.cfg.interwikiname)]
    rows = sorted(rows, reverse=True)
    return render_template('admin/itemsize.html',
                           title_name=_(u"Item Size"),
                           headings=headings,
                           rows=rows)
开发者ID:pombredanne,项目名称:moin2,代码行数:12,代码来源:views.py


示例10: _render_data

 def _render_data(self):
     # TODO: this could be a converter -> dom, then transcluding this kind
     # of items and also rendering them with the code in base class could work
     png_url = url_for('frontend.get_item', item_name=self.name, member='drawing.png', rev=self.rev.revid)
     title = _('Edit drawing %(filename)s (opens in new window)', filename=self.name)
     image_map = self._read_map()
     if image_map:
         mapid, image_map = self._transform_map(image_map, title)
         title = _('Clickable drawing: %(filename)s', filename=self.name)
         return Markup(image_map + u'<img src="{0}" alt="{1}" usemap="#{2}" />'.format(png_url, title, mapid))
     else:
         return Markup(u'<img src="{0}" alt="{1}" />'.format(png_url, title))
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:12,代码来源:content.py


示例11: __call__

 def __call__(self, rev, contenttype=None, arguments=None):
     self.item_name = rev.item.name
     try:
         contents = self.list_contents(rev.data)
         contents = [(self.process_size(size),
                      self.process_datetime(dt),
                      self.process_name(name),
                     ) for size, dt, name in contents]
         return self.build_dom_table(contents, head=[_("Size"), _("Date"), _("Name")], cls='zebra')
     except ArchiveException as err:
         logging.exception("An exception within archive file handling occurred:")
         # XXX we also use a table for error reporting, could be
         # something more adequate, though:
         return self.build_dom_table([[str(err)]])
开发者ID:pombredanne,项目名称:moin2,代码行数:14,代码来源:archive_in.py


示例12: highlighterhelp

def highlighterhelp():
    """display a table with list of available Pygments lexers"""
    import pygments.lexers
    headings = [_('Lexer description'),
                _('Lexer names'),
                _('File patterns'),
                _('Mimetypes'),
               ]
    lexers = pygments.lexers.get_all_lexers()
    rows = sorted([[desc, ' '.join(names), ' '.join(patterns), ' '.join(mimetypes), ]
                   for desc, names, patterns, mimetypes in lexers])
    return render_template('admin/highlighterhelp.html',
                           title_name=_(u"Highlighter Help"),
                           headings=headings,
                           rows=rows)
开发者ID:pombredanne,项目名称:moin2,代码行数:15,代码来源:views.py


示例13: request

    def request(self, user_obj, **kw):
        u = None
        # always revalidate auth
        if user_obj and user_obj.auth_method == self.name:
            user_obj = None
        # something else authenticated before us
        if user_obj:
            return user_obj, True

        auth = request.authorization
        if auth and auth.username and auth.password is not None:
            logging.debug("http basic auth, received username: {0!r} password: {1!r}".format(
                auth.username, auth.password))
            u = user.User(name=auth.username.decode(self.coding),
                          password=auth.password.decode(self.coding),
                          auth_method=self.name, auth_attribs=[], trusted=self.trusted)
            logging.debug("user: {0!r}".format(u))

        if not u or not u.valid:
            from werkzeug import Response, abort
            response = Response(_('Please log in first.'), 401,
                                {'WWW-Authenticate': 'Basic realm="{0}"'.format(self.realm)})
            abort(response)

        logging.debug("u: {0!r}".format(u))
        if u and self.autocreate:
            logging.debug("autocreating user")
            u.create_or_update()
        if u and u.valid:
            logging.debug("returning valid user {0!r}".format(u))
            return u, True  # True to get other methods called, too
        else:
            logging.debug("returning {0!r}".format(user_obj))
            return user_obj, True
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:34,代码来源:http.py


示例14: item_acl_report

def item_acl_report():
    """
    Return a list of all items in the wiki along with the ACL Meta-data
    """
    all_items = flaskg.storage.documents(wikiname=app.cfg.interwikiname)
    items_acls = []
    for item in all_items:
        item_namespace = item.meta.get(NAMESPACE)
        item_id = item.meta.get(ITEMID)
        item_name = item.meta.get(NAME)
        item_acl = item.meta.get(ACL)
        acl_default = item_acl is None
        fqname = CompositeName(item_namespace, u'itemid', item_id)
        if acl_default:
            for namespace, acl_config in app.cfg.acl_mapping:
                if item_namespace == namespace[:-1]:
                    item_acl = acl_config['default']
        items_acls.append({'name': item_name,
                           'itemid': item_id,
                           'fqname': fqname,
                           'acl': item_acl,
                           'acl_default': acl_default})
    return render_template('admin/item_acl_report.html',
                           title_name=_('Item ACL Report'),
                           items_acls=items_acls)
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:25,代码来源:views.py


示例15: add_heading

 def add_heading(self, elem, level, id=None):
     elem.append(html.a(attrib={
         html.href: "#{0}".format(id),
         html.class_: "moin-permalink",
         html.title_: _("Link to this heading")
     }, children=(u"¶", )))
     self._headings.append((elem, level, id))
开发者ID:gitpraetorianlabs,项目名称:moin-2.0,代码行数:7,代码来源:html_out.py


示例16: wikiconfighelp

def wikiconfighelp():
    def format_default(default):
        if isinstance(default, defaultconfig.DefaultExpression):
            default_txt = default.text
        else:
            default_txt = repr(default)
            if len(default_txt) > 30:
                default_txt = '...'
        return default_txt

    groups = []
    for groupname in defaultconfig.options:
        heading, desc, opts = defaultconfig.options[groupname]
        opts = sorted([(groupname + '_' + name, format_default(default), description)
                       for name, default, description in opts])
        groups.append((heading, desc, opts))
    for groupname in defaultconfig.options_no_group_name:
        heading, desc, opts = defaultconfig.options_no_group_name[groupname]
        opts = sorted([(name, format_default(default), description)
                       for name, default, description in opts])
        groups.append((heading, desc, opts))
    groups.sort()
    return render_template('admin/wikiconfighelp.html',
                           title_name=_(u"Wiki Configuration Help"),
                           groups=groups)
开发者ID:pombredanne,项目名称:moin2,代码行数:25,代码来源:views.py


示例17: __call__

 def __call__(self, data, contenttype=None, arguments=None):
     text = decode_data(data, contenttype)
     content = normalize_split_text(text)
     # as of py 2.7.x (and in the year 2013), the csv module seems to still
     # have troubles with unicode, thus we encode to utf-8 ...
     content = [line.encode('utf-8') for line in content]
     dialect = csv.Sniffer().sniff(content[0])
     reader = csv.reader(content, dialect)
     # ... and decode back to unicode
     rows = []
     for encoded_row in reader:
         row = []
         for encoded_cell in encoded_row:
             row.append(encoded_cell.decode('utf-8'))
         if row:
             rows.append(row)
     head = None
     cls = None
     try:
         # fragile function throws errors when csv file is incorrectly formatted
         if csv.Sniffer().has_header('\n'.join(content)):
             head = rows[0]
             rows = rows[1:]
             cls = 'moin-sortable'
     except csv.Error as e:
         head = [_('Error parsing CSV file:'), str(e)]
     table = self.build_dom_table(rows, head=head, cls=cls)
     body = moin_page.body(children=(table, ))
     return moin_page.page(children=(body, ))
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:29,代码来源:text_csv_in.py


示例18: userprofile

def userprofile(user_name):
    """
    Set values in user profile
    """
    u = user.User(auth_username=user_name)
    if request.method == 'GET':
        return _(u"User profile of %(username)s: %(email)r", username=user_name,
                 email=(u.email, u.disabled))

    if request.method == 'POST':
        key = request.form.get('key', '')
        val = request.form.get('val', '')
        ok = False
        if hasattr(u, key):
            ok = True
            oldval = getattr(u, key)
            if isinstance(oldval, bool):
                val = bool(val)
            elif isinstance(oldval, int):
                val = int(val)
            elif isinstance(oldval, unicode):
                val = unicode(val)
            else:
                ok = False
        if ok:
            setattr(u, key, val)
            u.save()
            flash('{0}.{1}: {2} -> {3}'.format(user_name, key, unicode(oldval), unicode(val), ), "info")
        else:
            flash('modifying {0}.{1} failed'.format(user_name, key, ), "error")
    return redirect(url_for('.userbrowser'))
开发者ID:pombredanne,项目名称:moin2,代码行数:31,代码来源:views.py


示例19: __call__

 def __call__(self, rev, contenttype=None, arguments=None):
     item_name = rev.item.fqname.value
     attrib = {
         xlink.href: Iri(scheme='wiki', authority='', path='/' + item_name, query='do=modify'),
     }
     a = moin_page.a(attrib=attrib, children=[_("%(item_name)s does not exist. Create it?", item_name=item_name)])
     body = moin_page.body(children=(a, ))
     return moin_page.page(children=(body, ))
开发者ID:denedios,项目名称:moin-2.0,代码行数:8,代码来源:nonexistent_in.py


示例20: sysitems_upgrade

def sysitems_upgrade():
    from MoinMoin.storage.backends import upgrade_sysitems
    from MoinMoin.storage.error import BackendError
    if request.method == 'GET':
        action = 'syspages_upgrade'
        label = 'Upgrade System Pages'
        return render_template('admin/sysitems_upgrade.html',
                               title_name=_(u"System items upgrade"))
    if request.method == 'POST':
        xmlfile = request.files.get('xmlfile')
        try:
            upgrade_sysitems(xmlfile)
        except BackendError as e:
            flash(_('System items upgrade failed due to the following error: %(error)s.', error=e), 'error')
        else:
            flash(_('System items have been upgraded successfully!'))
        return redirect(url_for('.index'))
开发者ID:pombredanne,项目名称:moin2,代码行数:17,代码来源:views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python items.Item类代码示例发布时间:2022-05-24
下一篇:
Python formatter.FormatterBase类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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