def resolve(self): """ If any of the nodes that are being concatenated are protected (because Yay knows they were loaded from .yay.gpg) then this will return an :py:class:`~yay.protected.ProtectedString` object. If none of the nodes are then it will return a string. """ resolved = [x.resolve() for x in self.args] protected = False for x in resolved: if isinstance(x, ProtectedString): protected = True if protected: p = ProtectedString() for x in resolved: p.add(x) return p return "".join(str(x) for x in resolved)
def resolve(self): """ Boxed will do some simple and automatic processing of data when it resolves. * If it isn't a subclass of basestring it will be returned as is * `yes`, `true` and `on` will become python True * `no`, `false` and `off` will become python False * If it can be cast to an ``int`` it will be. * If it can be represented in ascii it will be * Otherwise a unicode string is returned """ value = self.value if not isinstance(value, basestring): return value if self.secret: p = ProtectedString() p.add_secret(value) return p if value.lower() in ("yes", "true", "on"): return True if value.lower() in ("no", "false", "off"): return False try: return int(value) except ValueError: pass # FIXME: could still be a float or a timestamp try: return value.encode("ascii") except UnicodeEncodeError: return value