← Back to team overview

subunit-dev team mailing list archive

Re: Writing Content to a file

 

On 21 June 2015 at 09:39, Brendan Donegan <brendan.donegan@xxxxxxxxxxxxx> wrote:
> Hi,
>
> I have a subunit stream with some logs embedded in it as 'Content' types. I
> (think I) need to write these to a file in order to include them in a POST
> request to a service that I want to upload them to. The issue that I have is
> that it appears to be non-trivial to do this, which is puzzling as they
> represent files. For text files I can call as_text().encode('utf-8') or what
> have you, but for images as_text isn't supported so I appear to be left with
> casting to a string which is kind of horrible. Is there something I'm
> completely missing here?

You should be able to POST the full stream as-is and have the server
interpret it, if the server accepts subunit :). Is the server source
public?

If the server doesn't accept subunit but you want to pull out a
specific attachment and submit it, you should be able to give your
HTTP client an iterable of bytes - the testtools Content API -
https://github.com/testing-cabal/testtools/blob/master/testtools/content.py#L61
- has iter_bytes for that. You can of course write to a file and then
hand a file handle if you need to.

If you're using the native v2 API then you get the attachments in
small chunks (because things can interleave), but it sounds like
you're using a higher level API so the advice above should fit.

-Rob

-- 
Robert Collins <rbtcollins@xxxxxx>
Distinguished Technologist
HP Converged Cloud


References