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


Python Formatter.get_value方法代码示例

本文整理汇总了Python中string.Formatter.get_value方法的典型用法代码示例。如果您正苦于以下问题:Python Formatter.get_value方法的具体用法?Python Formatter.get_value怎么用?Python Formatter.get_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在string.Formatter的用法示例。


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

示例1: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
	def get_value(self, key, args, kwds):
        	# Let default get_value() handle ints
		if not isinstance(key, str):
                        return Formatter.get_value(self, key, args, kwds)

		# HACK, we allow defining strings via fields to allow
                # conversions
                if key[:2] == 's|':
                        return key[2:]

		if key[:2] == 't|':
                        # title mode ("TITLE ATTR")
                        include_title = True
                elif key[:2] == 'a|':
                	# plain attribute mode ("ATTR")
                	include_title = False
                else:
                        # No special field, have default get_value() get it
                        return Formatter.get_value(self, key, args, kwds)

		key = key[2:]
                (title, value) = self._nlattr(key)

                if include_title:
                        if not title:
                                title = key	# fall back to key as title
                        value = kw(title) + ' ' + value

                return value
开发者ID:BorodaZizitopa,项目名称:libnl,代码行数:31,代码来源:util.py

示例2: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, key, args, kwargs):
     if '|' in key:
         for kk in key.split('|'):
             out = Formatter.get_value(self, kk, args, kwargs)
             if out is not None and len(out) > 0:
                 return out
     out = Formatter.get_value(self, key, args, kwargs)
     if failOnEmpty and (out is None or len(out) == 0):
         raise ValueError("Cannot resolve %s" % key)
     return out
开发者ID:essembeh,项目名称:script-utils,代码行数:12,代码来源:plooze.py

示例3: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, key, args, kwds):
     if isinstance(key, str):
         try:
             return kwds[key]
         except KeyError:
             return self.context[key]
     else:
         return Formatter.get_value(key, args, kwds)
开发者ID:Yelp,项目名称:Tron,代码行数:10,代码来源:config_utils.py

示例4: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, key, args, kwargs):
     try:
         return Formatter.get_value(self, key, args, kwargs)
     except KeyError:
         if self.allow_empty:
             logger.debug("Found uninitialized key %s, replaced with empty string", key)
             return ""
         raise
开发者ID:openstack-infra,项目名称:jenkins-job-builder,代码行数:10,代码来源:formatter.py

示例5: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, key, args, kwds):
     if isinstance(key, str):
         if key:
             try:
                 # Check explicitly passed arguments first
                 return kwds[key]
             except KeyError:
                 return self.namespace[key]
         else:
             raise ValueError("zero length field name in format")
     else:
         return Formatter.get_value(self, key, args, kwds)
开发者ID:saddingtonbaynes,项目名称:rez,代码行数:14,代码来源:rex.py

示例6: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, key, args, kwargs):
     # try regular formatting first:
     try:
         return Formatter.get_value(self, key, args, kwargs)
     except Exception:
         pass
     # next, look in user_ns and builtins:
     for container in (self.shell.user_ns, __builtins__):
         if key in container:
             return container[key]
     # nothing found, put error message in its place
     return "<ERROR: '%s' not found>" % key
开发者ID:harsha547,项目名称:ipython,代码行数:14,代码来源:prompts.py

示例7: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
    def get_value(self, key, args, kwds):
        """
        When values are being swapped in a formatted string, if an exact match,
        the key is replaced by the value provided. If no values exist for a
        given key, simply return the variable name as its value

        Args:
            key (str or other): The expected name for the key in the formatted string
            args (any): The args to put in place of key
            kwds (iterable): key/value pairs

        Returns:
            str: The format-replaced string with all of the keys replaced
        """
        if isinstance(key, str):
            try:
                return kwds[key]
            except KeyError:
                return key
        else:
            Formatter.get_value(key, args, kwds)
开发者ID:ColinKennedy,项目名称:env,代码行数:23,代码来源:unseenformatter.py

示例8: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, key, args, kwargs):
     try:
         # XXX: .mpe Hack: format OrderedDict as regular dict on variable-expansion
         if is_complex(key, args, kwargs):
             return json.dumps(kwargs[key])
         else:
             return Formatter.get_value(self, key, args, kwargs)
     except KeyError:
         if self.allow_empty:
             logger.debug(
                 'Found uninitialized key %s, replaced with empty string',
                 key
             )
             return ''
         raise
开发者ID:dotmpe,项目名称:jenkins-job-builder,代码行数:17,代码来源:formatter.py

示例9: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
    def get_value(self, key, args, kwds):
        if isinstance(key, str):
            if key:
                try:
                    # Check explicitly passed arguments first
                    return kwds[key]
                except KeyError:
                    pass

                try:
                    # we deliberately do not call hasattr() first - hasattr()
                    # silently catches exceptions from properties.
                    return getattr(self.instance, key)
                except AttributeError:
                    pass

                return self.instance[key]
            else:
                raise ValueError("zero length field name in format")
        else:
            return Formatter.get_value(self, key, args, kwds)
开发者ID:foutoucour,项目名称:rez,代码行数:23,代码来源:formatting.py

示例10: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, *args, **kwargs):
     try:
         return Formatter.get_value(self, *args, **kwargs)
     except KeyError:
         return ''
开发者ID:AtulKumar2,项目名称:calibre,代码行数:7,代码来源:jacket.py

示例11: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, key, args, kwds):
   if isinstance(key, basestring) and key not in kwds:
     return self.default
   return Formatter.get_value(self, key, args, kwds)
开发者ID:sharpglasses,项目名称:depot_tools,代码行数:6,代码来源:my_activity.py

示例12: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, key, args, kwargs):
     # Try standard formatting, then return 'unknown key'
     try:
         return Formatter.get_value(self, key, args, kwargs)
     except KeyError:
         return self.default
开发者ID:centralman,项目名称:logcabin,代码行数:8,代码来源:event.py

示例13: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, key, args, kwds):
     if isinstance(key, str):
         return kwds.get(key, self.default)
     else:
         Formatter.get_value(key, args, kwds)
开发者ID:cparker,项目名称:pythonclub,代码行数:7,代码来源:RavenNodeLicenseReport2.py

示例14: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, key, args, kwargs):
     try:
         return Formatter.get_value(self, key, args, kwargs)
     except KeyError:
         return MISSING_KEY
开发者ID:imankulov,项目名称:tagged-logger,代码行数:7,代码来源:__init__.py

示例15: get_value

# 需要导入模块: from string import Formatter [as 别名]
# 或者: from string.Formatter import get_value [as 别名]
 def get_value(self, field_name, args, kwds):
     v = Formatter.get_value(self, field_name, args, kwds)
     if v is None:
         return EmptyNone
     return v
开发者ID:jacob-carrier,项目名称:code,代码行数:7,代码来源:recipe-577227.py


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