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


Python i18n._函数代码示例

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


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


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