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

Python backend.tr函数代码示例

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

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



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

示例1: checkConsistency

    def checkConsistency(self, loader_context=None):
        # Import InterfaceResource and FirewallResource here instead of the top
        # of the file to avoid an import loop
        from ufwi_ruleset.forward.resource.interface import InterfaceResource
        from ufwi_ruleset.forward.resource.firewall import FirewallResource

        duplicates = set()
        for item in self.items:
            if isinstance(item.network, InterfaceResource):
                raise RulesetError(
                    tr("You can not use an interface (%s) in a platform (%s)."),
                    item.network.formatID(), self.formatID())
            if isinstance(item.network, FirewallResource):
                raise RulesetError(
                    tr("You can not use the firewall object in a platform (%s)."),
                    self.formatID())

            if item.network.interface != self.interface:
                raise RulesetError(
                    tr('A platform (%s) can not contain network objects '
                       'from different interfaces (%s and %s).'),
                    self.formatID(),
                    self.interface.formatID(),
                    item.network.interface.formatID())

            key = (item.network.id, item.protocol.id)
            if key in duplicates:
                raise RulesetError(
                    tr("Duplicate item in the platform %s: (%s, %s)."),
                    self.formatID(),
                    item.network.formatID(), item.protocol.formatID())
            duplicates.add(key)
开发者ID:maximerobin,项目名称:Ufwi,代码行数:32,代码来源:platform.py


示例2: checkIdentifier

def checkIdentifier(id):
    if not isinstance(id, unicode):
        raise RulesetError(tr("Invalid identifier: type is not unicode (%s)"), unicode(type(id)))
    if not id:
        raise RulesetError(tr("Invalid identifier: empty string"))
    if not REGEX_ID.match(id):
        raise RulesetError(tr("Invalid identifier: invalid characters or length (%s)"), repr(id))
开发者ID:maximerobin,项目名称:Ufwi,代码行数:7,代码来源:object.py


示例3: sendMailToAdmin_cb

 def sendMailToAdmin_cb(self, unused, template_variables):
     template_variables['my_fqdn'] = '%s.%s' % (
         template_variables['my_hostname'],
         template_variables['my_domain'])
     jinja_env = jinja.Environment()
     template = jinja_env.from_string(self.body_template)
     rendered_body = unicode(template.render(**template_variables))
     msg = MIMEText(rendered_body.encode('utf-8'), 'plain', 'utf-8')
     msg['Subject'] = u'[EW4 %s] %s' % (
         template_variables['my_hostname'],
         unicode(template_variables['subject']))
     sender = self.config.sender_mail
     if check_mail(sender):
         msg['From'] = sender
     else:
         raise NuConfError(CONTACT_INVALID_SENDER,
                           tr("'sender' e-mail : invalid e-mail address"))
     recipient = self.config.admin_mail
     if check_mail(recipient):
         msg['To'] = recipient
     else:
         raise NuConfError(CONTACT_INVALID_RECIPIENT,
                 tr("'recipient' e-mail : invalid e-mail address"))
     defer = sendmail('127.0.0.1', sender, recipient, msg.as_string())
     defer.addCallback(self.logSuccess)
     return defer
开发者ID:maximerobin,项目名称:Ufwi,代码行数:26,代码来源:contact.py


示例4: loadFile

    def loadFile(self, ruleset_context, filetype, name,
    editable=False, from_template=None, action=None, ruleset_id=0,
    filename=None, content=None):
        # Log the action
        logger = ruleset_context.logger
        text = "Load %s: %s" % (filetype, name)
        if ruleset_id == 0:
            logger.info(text)
        else:
            logger.debug(text)

        if not content:
            # Get the filename
            if not filename:
                if filetype == "library":
                    filename = LIBRARY_FILENAME
                else:
                    filename = rulesetFilename(filetype, name)

            # Parse the XML file
            try:
                with open(filename) as fp:
                    ruleset = etree.parse(fp).getroot()
            except IOError, err:
                if err.errno == ENOENT:
                    if filetype == 'template':
                        message = tr('The "%s" template does not exist. It has been deleted or renamed.')
                    else:
                        message = tr('The "%s" rule set does not exist. It has been deleted or renamed.')
                    raise RulesetError(message, name)
                else:
                    raise RulesetError(
                        tr('Unable to open file "%s" (%s): %s'),
                        basename(filename), filetype, exceptionAsUnicode(err))
开发者ID:maximerobin,项目名称:Ufwi,代码行数:34,代码来源:ruleset.py


示例5: moveAcl

    def moveAcl(self, acl, new_order, check_editable):
        # Compute rules order
        rules  = self.acls
        old_order = self.getOrder(acl)
        length = len(rules)

        # Consistency checks
        if not (0 <= new_order < length):
            if new_order < old_order:
                format = tr("Unable to move up the %s: the rule is already the first of the %s chain.")
            else:
                format = tr("Unable to move down the %s: the rule is already the last of the %s chain.")
            raise RulesetError(
                format,
                unicode(acl), unicode(self))

        if old_order < new_order:
            first = old_order
            last = new_order
        else:
            first = new_order
            last = old_order

        for order in xrange(first, last+1):
            print("check", order)
            check_editable(rules[order])

        # Move the rule
        rule = rules.pop(old_order)
        rules.insert(new_order, rule)
开发者ID:maximerobin,项目名称:Ufwi,代码行数:30,代码来源:chain.py


示例6: iptablesSave

def iptablesSave(logger, ipv6):
    """
    Save current iptables rules into a file.
    Return the filename of the saved rules.
    Raise an IptablesError on error.
    """
    if ipv6:
        filename = 'old_rules_ipv6'
        address_type = "IPv6"
    else:
        filename = 'old_rules_ipv4'
        address_type = "IPv4"
    filename = path_join(RULESET_DIR, filename)
    logger.warning("Save %s iptables rules to %s" % (address_type, filename))
    if ipv6:
        command_str = IP6TABLES_SAVE
    else:
        command_str = IPTABLES_SAVE
    command = (command_str,)
    with open(filename, 'w') as rules:
        process, code = runCommandAsRoot(logger, command, timeout=22.5, stdout=rules)
    if code != 0:
        raise IptablesError(tr("%s command exited with code %s!"), command_str, code)
    size = getsize(filename)
    if not size:
        raise IptablesError(tr("%s command output is empty!"), command_str)
    return filename
开发者ID:maximerobin,项目名称:Ufwi,代码行数:27,代码来源:save.py


示例7: create

 def create(self, conf, logger):
     dbtype = conf['dbtype']
     try:
         db_object = self.objects[dbtype]
         if isinstance(db_object, (str, unicode)):
             raise DatabaseError(tr('Unable to use %s: %s'), dbtype, toUnicode(db_object))
     except KeyError, e:
         raise DatabaseError(tr('Unsupported database type %s'), dbtype)
开发者ID:maximerobin,项目名称:Ufwi,代码行数:8,代码来源:database.py


示例8: checkConsistency

 def checkConsistency(self, loader_context=None):
     if self.day_to < self.day_from:
         raise RulesetError(
             tr("Invalid day range: %s..%s"),
             self.day_from, self.day_to)
     if self.hour_to <= self.hour_from:
         raise RulesetError(
             tr("Invalid hour range: %sh00..%sh59"),
             self.hour_from, (self.hour_to - 1))
开发者ID:maximerobin,项目名称:Ufwi,代码行数:9,代码来源:periodicity.py


示例9: templatize

 def templatize(self, object, fusion):
     object.checkEditable()
     if object.isGeneric():
         raise RulesetError(tr("The %s object is already a generic object."), object.formatID())
     if not self.ruleset.is_template:
         raise RulesetError(tr("The rule set is not a template!"))
     attr = object.getAttributes()
     object.templatize(attr)
     return self.modifyObject(object, attr, fusion)
开发者ID:maximerobin,项目名称:Ufwi,代码行数:9,代码来源:object_dict.py


示例10: _createTemplate

 def _createTemplate(self, name, parent):
     if (name in self.include_templates) \
     or (self.is_template and (self.name == name)):
         raise RulesetError(
             tr('The "%s" template can not be included twice'),
             name)
     identifier = 1 + len(self.include_templates)
     if 9 < identifier:
         raise RulesetError(tr("A rule set cannot comprise more than 9 templates!"))
     return IncludeTemplate(name, parent, identifier)
开发者ID:maximerobin,项目名称:Ufwi,代码行数:10,代码来源:ruleset.py


示例11: getUserGroupNumber

def getUserGroupNumber(group):
    try:
        group = int(group)
    except ValueError:
        raise RulesetError(
            tr("Invalid user group: %s"),
            unicode(group))
    if not(MIN_GROUP <= group <= MAX_GROUP):
        raise RulesetError(tr("Invalid user group number: %s"), group)
    return group
开发者ID:maximerobin,项目名称:Ufwi,代码行数:10,代码来源:user_group.py


示例12: loadError

 def loadError(self, err, when):
     message = u"[%s] %s" % (err.__class__.__name__, exceptionAsUnicode(err))
     if self.name:
         err = RulesetError(
             tr('Error while loading %s from the "%s" rule set: %s'),
             when, self.name, message)
     else:
         err = RulesetError(
             tr('Error on new rule set creation (while loading %s): %s'),
             when, message)
     reraise(err)
开发者ID:maximerobin,项目名称:Ufwi,代码行数:11,代码来源:ruleset.py


示例13: _checkUserGroup

 def _checkUserGroup(self, require_group_name, user_group):
     if require_group_name:
         if user_group.name is None:
             raise RulesetError(
                 tr('The firewall uses user group names, but the %s user group has no name'),
                 user_group.formatID())
     else:
         if user_group.group is None:
             raise RulesetError(
                 tr('The firewall uses user group numbers, but the %s user group has no number'),
                 user_group.formatID())
开发者ID:maximerobin,项目名称:Ufwi,代码行数:11,代码来源:apply_rules.py


示例14: should_run

 def should_run(self, responsible):
     if not self.openvpn_cfg.enabled:
         if responsible:
             responsible.feedback(tr("Explicitely disabled."))
         return False
     if not self.openvpn_cfg.client_network:
         if responsible:
             responsible.feedback(
                 tr("No client network was defined, disabling server.")
                 )
         return False
     return True
开发者ID:maximerobin,项目名称:Ufwi,代码行数:12,代码来源:openvpn.py


示例15: rulesetDelete

def rulesetDelete(core, filetype, name):
    """
    Delete the specified ruleset.
    """
    if (filetype == "template") and (core.getMultisiteType() == MULTISITE_SLAVE):
        raise RulesetError(tr("Can not delete a template from a slave."))

    filename = rulesetFilename(filetype, name)
    try:
        unlink(filename)
    except IOError, err:
        raise RulesetError(tr("Unable to delete the file %s (%s): %s!"), name, filetype, exceptionAsUnicode(err))
开发者ID:maximerobin,项目名称:Ufwi,代码行数:12,代码来源:ruleset_list.py


示例16: _match

 def _match(self, rule, attributes, match_func):
     if not attributes:
         raise RulesetError(tr("Empty attribute list"))
     for attr in attributes:
         if attr not in self.MATCH_ATTRIBUTES:
             raise RulesetError(tr("Unknown rule attribute: %s"), attr)
         # TODO platform use flattenNetworkList
         objects_a = getattr(self, attr)
         objects_b = getattr(rule, attr)
         if not match_func(objects_a, objects_b):
             return False
     return True
开发者ID:maximerobin,项目名称:Ufwi,代码行数:12,代码来源:rule.py


示例17: build

    def build(self, request, filters):
        protos = {'tcp':   6,
                  'udp':   17,
                  'icmp':  1,
                  'igmp':  2}

        try:
            proto = protos[self.value]
            return '%s = %s' % ('ip_protocol', proto)
        except KeyError:
            raise RpcdError(tr('Protocol must be tcp or udp (is %s)'), self.value)
            raise RpcdError(tr('Unknown protocol: %s'), self.value)
开发者ID:maximerobin,项目名称:Ufwi,代码行数:12,代码来源:filters.py


示例18: create

    def create(self, context, data):
        "Create an anonymous session"

        client_name = getUnicode("client_name", data['client_name'], 3, 100)
        protocol_version = getUnicode("protocol_version", data['protocol_version'], 3, 100)

        # Check client name and protocol version
        if not client_name or not (3 <= len(client_name) <= 20):
            raise SessionError(SESSION_INVALID_ARG,
                tr("Invalid client name: need a string with length in 3..20"))
        if not protocol_version or not (3 <= len(protocol_version) <= 10):
            raise SessionError(SESSION_INVALID_ARG,
                tr("Invalid protocol version: need a string with length in 3..10"))

        # Check protocol version
        if protocol_version != PROTOCOL_VERSION:
            raise SessionError(SESSION_INVALID_VERSION,
                tr("Invalid protocol version: %s"),
                repr(protocol_version))

        # Only a user with no session can create a new session
        if not context.user:
            raise SessionError(SESSION_NO_USER,
                tr("Only a user can create a session!"))
        if context.hasSession():
            raise SessionError(SESSION_DUPLICATE,
                tr("You already own a session!"))


        # Fill the user context
        user = context.user
        if 'client_release' in data:
            #size between 3 and 100
            user.client_release = getUnicode('client_release', data['client_release'], 3, 100)
        user.groups = ["anonymous"]
        user.client_name = client_name
        user.protocol_version = protocol_version

        # Create the session
        cookie = self.createCookie()
        filename = b32encode(cookie).strip("=") + ".pickle"
        filename = path_join(self.path, filename)
        cookie = b64encode(cookie)
        session = Session(cookie, filename, user)

        # Register the session and write it to the disk
        self.sessions[session.cookie] = session
        context.setSession(session)
        session.save()

        # Session created
        return session.cookie
开发者ID:maximerobin,项目名称:Ufwi,代码行数:52,代码来源:session.py


示例19: checkServiceCall

 def checkServiceCall(self, context, service_name):
     ruleset_open = self.hasRules(context)
     if service_name == "open":
         if ruleset_open:
             rules = self.getRulesFile(context)
             raise LocalFWError(
                 tr("There is already an active rule set (%s)."),
                 rules.name)
     else:
         if not ruleset_open:
             raise LocalFWError(
                 tr("You have to open a rule set to use the %s() service."),
                 service_name)
开发者ID:maximerobin,项目名称:Ufwi,代码行数:13,代码来源:component.py


示例20: taskDone

    def taskDone(self, ret):
        if isinstance(ret, Failure):
            self.setError(ret.getErrorMessage())
            self.fw.error(
                tr("Error while performing task on firewall %s: %s") % (self.fw.name, str(ret.getErrorMessage()))
            )
            self.fw.debug(
                tr("Error while applying updates to firewall %s: %s") % (self.fw.name, str(ret.getTraceback()))
            )
            return

        if self.task_stop_on_success:
            self.state = FINNISHED
            self.task.stop()
开发者ID:maximerobin,项目名称:Ufwi,代码行数:14,代码来源:task.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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