barneygale / httpio Goto Github PK
View Code? Open in Web Editor NEWPython library for reading HTTP resources as random-access file-like objects using the `Range` header
License: Other
Python library for reading HTTP resources as random-access file-like objects using the `Range` header
License: Other
The PyPi version hasn't been bumped since 2016, seems like pypi should get the latest bits.
>>> import httpio
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/frafra/.cache/pypoetry/virtualenvs/draft-2Uym0jAL-py3.9/lib64/python3.9/site-packages/httpio/__init__.py", line 229, in <module>
from .asyncio import AsyncHTTPIOFileContextManagerMixin
File "/home/frafra/.cache/pypoetry/virtualenvs/draft-2Uym0jAL-py3.9/lib64/python3.9/site-packages/httpio/asyncio.py", line 4, in <module>
from httpio_async import AsyncHTTPIOFile, AsyncHTTPIOFileContextManagerMixin # noqa: F401
File "/home/frafra/.cache/pypoetry/virtualenvs/draft-2Uym0jAL-py3.9/lib64/python3.9/site-packages/httpio_async/__init__.py", line 6, in <module>
import aiohttp
ModuleNotFoundError: No module named 'aiohttp'
Lines 7 to 10 in 18c1b98
For some reason, it seems AmazonS3 may return the "accept-ranges: bytes" header more than once. requests
will concatenate the values, resulting in the header value being bytes, bytes
, and then:
Line 70 in 18c1b98
This test triggers, and we can't open the file.
I'd guess a better test would be "bytes" in response.headers.get(...)
Also, it looks like the Accept-Ranges
header is not required:
https://tools.ietf.org/html/rfc7233#section-2.3
An origin server that supports byte-range requests for a given target
resource MAY sendAccept-Ranges: bytes
to indicate what range units are supported.
Here's an url you can try for reproduction
https://files.pythonhosted.org/packages/44/e8/4ae9ef3d455f4ce5aa22259cb6e40c69b29ef6b02d49c5cdfa265f7fc821/Django-3.0.1.tar.gz
I'd like be able to use httpio with httpx on trio, I'd be able to do this if all of this with a pluggable session strategy:
@attr.s(frozen=True)
class AIOHttpFactory:
_session = attr.ib()
_kwargs = attr.ib()
def length(self, url) -> int:
async with self._session.head(self.url, **self._kwargs) as response:
response.raise_for_status()
return int(response.headers.get('content-length', None))
def get(self, url, start, end) -> bytes:
headers = {
"Range": "bytes=%d-%d" % (start, end - 1),
**self._kwargs.get("headers", {})
}
kwargs = {**self._kwargs, "headers": headers}
async with self._session.get(url, **kwargs) as response:
response.raise_for_status()
return await response.read()
@classmethod
@contextlib.asynccontextmanager
def session(cls, kwargs):
async with asyncio.ClientSession() as s:
yield cls(s, kwargs)
def __init__(self, url, block_size=-1, session_factory=None, **kwargs):
"""
:param url: The URL of the file to open
:param block_size: The cache block size, or `-1` to disable caching.
:param kwargs: Additional arguments to pass to `session.get`
"""
super(AsyncHTTPIOFile, self).__init__()
self.url = url
self.block_size = block_size
if session_factory is None
from . import aiohttp_strategy
session_factory = aiohttp_strategy.AIOHttpFactory
self._session_factory = session_factory
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.