Esempio n. 1
0
	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
Esempio n. 2
0
 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
Esempio n. 3
0
 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)
 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
Esempio n. 5
0
 def get_value(self, key, args, keywords):
     if isinstance(key, str):
         try:
             return keywords[key]
         except KeyError:
             return key
     else:
         return Formatter.get_value(key, args, keywords)
Esempio n. 6
0
 def get_value(self, key, args, kwds):
     if isinstance(key, str):
         try:
             return kwds[key]
         except KeyError:
             return "{" + key + "}"
     else:
         return Formatter.get_value(key, args, kwds)
Esempio n. 7
0
 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)
Esempio n. 8
0
    def get_value(self, key, args, kwds):

        if isinstance(key, str):
            try:
                return kwds[key]
            except KeyError:
                return f'{{{key}}}' if self.default is None else self.default
        else:
            return Formatter.get_value(key, args, kwds)
Esempio n. 9
0
 def get_value(self, key, args, kwds):
   if isinstance(key, str):
     try:
       # Check explicitly passed arguments first
       return kwds[key]
     except KeyError:
       return self.namespace[key]
   else:
     return Formatter.get_value(key, args, kwds)
Esempio n. 10
0
 def get_value(self, key, args, kwargs):
     """Return the ley name if the value is missing."""
     if isinstance(key, str):
         try:
             return kwargs[key]
         except KeyError:
             return key
     else:
         return Formatter.get_value(key, args, kwargs)  # pylint: disable=E1120
Esempio n. 11
0
 def get_value(self, key, args, kwds):
     if isinstance(key, str):
         try:
             return kwds[key]
         except KeyError:
             return self.defaults[key]
     else:
         fmt = Formatter()
         return fmt.get_value(key, args, kwds)
Esempio n. 12
0
 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
Esempio n. 13
0
 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)
Esempio n. 14
0
 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
Esempio n. 15
0
 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
Esempio n. 16
0
 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)
Esempio n. 17
0
    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)
Esempio n. 18
0
 def get_value(self, key, args, format_kwargs):
     if isinstance(key, str):
         if format_kwargs.get(key) is not None:
             ret = format_kwargs[key]
         elif self.cli_kwargs.get(key) is not None:
             ret = self.cli_kwargs[key]
         else:
             raise Exception("Can't replace %s in fn" % key)
         # assert ret is not None, "fn_formatter: %s is None" % key
         # print("fn_formatter: %s is None" % key)
         return ret
     else:
         return Formatter.get_value(key, args, format_kwargs)
Esempio n. 19
0
 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
Esempio n. 20
0
 def get_value(self, key, args, kwds):
     if isinstance(key, str):
         try:
             val = kwds[key]
             if val != None:
                 return kwds[key]
             else:
                 logging.error("Value for key="+ key+ \
                 " is not set in the /config/<command>.yaml file. Please set the key and rerun the command." )
                 exit()
         except KeyError:
             logging.error("The Key="+ key+ \
             " is not set in the /config/<command>.yaml file. Please set the key and rerun the command." )
             exit()
     else:
         return Formatter.get_value(key, args, **kwds)
Esempio n. 21
0
    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)
Esempio n. 22
0
    def get_value(self, key, args, kwargs):
        """
        :param key: is index (of args) or string (of kwargs)
        :param args: positional arguments tuple, like in .format('one', 'two')
        :param kwargs: keyword arguments dict, like in .format(first='Hodor', last='Hodor!')
           or data={'first':'Hodor','last':'Hodor!'} ; .format(**data)
        :return: the getattr(key) / getitem(key) of args/kwargs/the enclosed property dict
        """
        colored = ''
        if isinstance(key, str):
            if key=='':
                return Formatter.get_value(self,key, args, kwargs)
            try:
                colored = kwargs[key]
            except KeyError:
                colored = self.msg_dict[key]

        elif isinstance(key,int) or isinstance(key,long):
            colored = args[key]

        return colored
Esempio n. 23
0
    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)
Esempio n. 24
0
 def get_value(self, key, args, kwargs):
     # Try standard formatting, if key not found then return None
     try:
         return Formatter.get_value(self, key, args, kwargs)
     except KeyError:
         return None
Esempio n. 25
0
 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
Esempio n. 26
0
 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)
Esempio n. 27
0
 def get_value(self, *args, **kwargs):
     try:
         return Formatter.get_value(self, *args, **kwargs)
     except KeyError:
         return ''
Esempio n. 28
0
 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
Esempio n. 29
0
 def get_value(self, *args, **kwargs):
     try:
         return Formatter.get_value(self, *args, **kwargs)
     except KeyError:
         return ''
Esempio n. 30
0
 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
Esempio n. 31
0
 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)
Esempio n. 32
0
File: ptwit.py Progetto: ptpt/ptwit
 def get_value(self, key, args, kwargs):
     # Try standard formatting, if key not found then return None
     try:
         return Formatter.get_value(self, key, args, kwargs)
     except KeyError:
         return None
 def get_value(self, key, args, kwds):
     if isinstance(key, str):
         return kwds.get(key, self.default)
     else:
         Formatter.get_value(key, args, kwds)
Esempio n. 34
0
 def get_value(self, key, args, kwargs):
     try:
         return Formatter.get_value(self, key, args, kwargs)
     except KeyError:
         return MISSING_KEY
Esempio n. 35
0
 def get_value(self, first, args, kwargs):
     try:
         return Formatter.get_value(self, first, args, kwargs)
     except KeyError:
         return eval(first, self.namespace)
Esempio n. 36
0
 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
Esempio n. 37
0
 def get_value(self, first, args, kwargs):
     try:
         return Formatter.get_value(self, first, args, kwargs)
     except KeyError:
         return eval(first, self.namespace)
Esempio n. 38
0
 def get_value(self, key, args, kwds):
     if isinstance(key, str):
         return kwds.get(key, self.default.format(key))
     else:
         return Formatter.get_value(key, args, kwds)