def test_normal_string(self): a = String(["Just a normal string"]) self.failUnlessEqual(unicode(a), "Just a normal string") self.failUnlessEqual(a.unprotected, "Just a normal string") self.failUnlessEqual(a.as_list(secret=True), ["Just a normal string"]) self.failUnlessEqual(a.as_list(secret=False), ["Just a normal string"])
def test_partially_secret(self): a = "adduser -u fred -p " b = String() b.add_secret("password") c = " -h /home/fred" d = String([a, b, c]) self.failUnlessEqual(unicode(d), "adduser -u fred -p ***** -h /home/fred") self.failUnlessEqual(d.unprotected, "adduser -u fred -p password -h /home/fred") self.failUnlessEqual( d.as_list(secret=True), ["adduser -u fred -p ", "*****", " -h /home/fred"]) self.failUnlessEqual( d.as_list(secret=False), ["adduser -u fred -p ", "password", " -h /home/fred"])
def resolve(self): r = self.value.resolve() if not isinstance(r, basestring): self.error( "Only simple strings can be marked with .secret at this time. Perhaps you want to look in to .yay.gpg files?" ) p = String() p.add_secret(r) return p
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.String` 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, String): protected = True if protected: p = String() 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 = String() 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