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


Python backend.tr函数代码示例

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


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


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