{"action":"created","issue":{"url":"https://api.github.com/repos/sigmavirus24/requests-toolbelt/issues/38","labels_url":"https://api.github.com/repos/sigmavirus24/requests-toolbelt/issues/38/labels{/name}","comments_url":"https://api.github.com/repos/sigmavirus24/requests-toolbelt/issues/38/comments","events_url":"https://api.github.com/repos/sigmavirus24/requests-toolbelt/issues/38/events","html_url":"https://github.com/sigmavirus24/requests-toolbelt/issues/38","id":40165779,"number":38,"title":"Add from_file classmethod to StreamingIterator","user":{"login":"sigmavirus24","id":240830,"avatar_url":"https://avatars.githubusercontent.com/u/240830?v=3","gravatar_id":"","url":"https://api.github.com/users/sigmavirus24","html_url":"https://github.com/sigmavirus24","followers_url":"https://api.github.com/users/sigmavirus24/followers","following_url":"https://api.github.com/users/sigmavirus24/following{/other_user}","gists_url":"https://api.github.com/users/sigmavirus24/gists{/gist_id}","starred_url":"https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sigmavirus24/subscriptions","organizations_url":"https://api.github.com/users/sigmavirus24/orgs","repos_url":"https://api.github.com/users/sigmavirus24/repos","events_url":"https://api.github.com/users/sigmavirus24/events{/privacy}","received_events_url":"https://api.github.com/users/sigmavirus24/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/sigmavirus24/requests-toolbelt/labels/Enhancement","name":"Enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/sigmavirus24/requests-toolbelt/labels/Long%20Hanging%20Fruit","name":"Long Hanging Fruit","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/sigmavirus24/requests-toolbelt/milestones/1","html_url":"https://github.com/sigmavirus24/requests-toolbelt/milestones/0.4","labels_url":"https://api.github.com/repos/sigmavirus24/requests-toolbelt/milestones/1/labels","id":854698,"number":1,"title":"0.4","description":"","creator":{"login":"sigmavirus24","id":240830,"avatar_url":"https://avatars.githubusercontent.com/u/240830?v=3","gravatar_id":"","url":"https://api.github.com/users/sigmavirus24","html_url":"https://github.com/sigmavirus24","followers_url":"https://api.github.com/users/sigmavirus24/followers","following_url":"https://api.github.com/users/sigmavirus24/following{/other_user}","gists_url":"https://api.github.com/users/sigmavirus24/gists{/gist_id}","starred_url":"https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sigmavirus24/subscriptions","organizations_url":"https://api.github.com/users/sigmavirus24/orgs","repos_url":"https://api.github.com/users/sigmavirus24/repos","events_url":"https://api.github.com/users/sigmavirus24/events{/privacy}","received_events_url":"https://api.github.com/users/sigmavirus24/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":14,"state":"open","created_at":"2014-11-05T15:49:20Z","updated_at":"2015-03-14T16:14:57Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2014-08-13T15:24:51Z","updated_at":"2015-03-29T17:11:14Z","closed_at":null,"body":"This allows someone to pass something like `sys.stdin` to `StreamingIterator.from_file` without having to create a function to wrap it. We can handle that for them."},"comment":{"url":"https://api.github.com/repos/sigmavirus24/requests-toolbelt/issues/comments/87445122","html_url":"https://github.com/sigmavirus24/requests-toolbelt/issues/38#issuecomment-87445122","issue_url":"https://api.github.com/repos/sigmavirus24/requests-toolbelt/issues/38","id":87445122,"user":{"login":"untitaker","id":837573,"avatar_url":"https://avatars.githubusercontent.com/u/837573?v=3","gravatar_id":"","url":"https://api.github.com/users/untitaker","html_url":"https://github.com/untitaker","followers_url":"https://api.github.com/users/untitaker/followers","following_url":"https://api.github.com/users/untitaker/following{/other_user}","gists_url":"https://api.github.com/users/untitaker/gists{/gist_id}","starred_url":"https://api.github.com/users/untitaker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/untitaker/subscriptions","organizations_url":"https://api.github.com/users/untitaker/orgs","repos_url":"https://api.github.com/users/untitaker/repos","events_url":"https://api.github.com/users/untitaker/events{/privacy}","received_events_url":"https://api.github.com/users/untitaker/received_events","type":"User","site_admin":false},"created_at":"2015-03-29T17:11:14Z","updated_at":"2015-03-29T17:11:14Z","body":"ATM, using StreamingIterator with file-like objects has quite a lot of indirection: `StreamingIterator.read` wraps an iterator, but that iterator is itself wrapping a file. Instead it's a lot easier to do:\r\n\r\n    f = ...\r\n    f.len = 1234  # yes, that's checked by super_len, apparently\r\n    requests.post(url, data=f)\r\n\r\nAnd in fact it seems to me the purported usecase of StreamingIterator is just a special case of \"converting an iterator to a file-like object\".\r\n\r\nGiven that, I propose that StreamingIterator is split up into several utilities:\r\n\r\n* A wrapper class that converts iterators to file-like objects.\r\n* A wrapper class that wraps a file-like object's read method to encode the return value (is this even necessary? Can't requests do the encoding itself? How does requests deal with the fileobjects that decode on read?)\r\n* A function specialized for that particular requests-specific usecase, that uses the classes above and also adds a `len` attribute to the resulting object.\r\n\r\nThe nice thing about this is that very little of that functionality is requests-specific."}}