This is where the duck seal comes in handy - it doesn't need to be a duck (= file), it just has to WIN, as one.
A little experimentation shows that any object that has a valid readlines () method is good.
I faked it with:
def myfakefile(keystring): myfakefile.readlines=lambda: keystring.split("\n") return myfakefile mykey = paramiko.RSAKey.from_private_key(myfakefile(keystring))
This is incredibly hacked, but it works.
What does this mean when you call myfakefile (keystring), it creates myfakefile.readlines, which returns the (divided) contents of the keys.
Then it returns a function.
The same functions are passed to the from_private_key command. from_private_key, thinking it is a file, calls myfakefile.readlines (). This calls the newly created (lambda) function, which returns the kind of thing you expect from file.readlines () - or, close enough, anyway.
Please note that saving results will not work as expected:
k1=myfakefile(keystring1) k2=myfakefile(keystring2)
There are more reliable ways to make it work as it should, but itβs not worth the effort - just use StringIO if your needs are more complex.
AMADANON Inc.
source share