-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the fetching from URI... still not fully defined...
- Loading branch information
Showing
4 changed files
with
58 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
import logging | ||
from urllib.request import urlopen, Request | ||
from urllib.error import URLError, HTTPError | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
class Fetcher(): | ||
|
||
__slots__ = ('response') | ||
|
||
def __init__(self, link): | ||
try: | ||
LOG.info('Fetching URI: %s', link) | ||
self.response = urlopen(link) | ||
except HTTPError as e: | ||
LOG.error('%r', e) | ||
raise ValueError(f'HTTP Error {e.code}') | ||
except URLError as e: | ||
LOG.error('%r', e) | ||
raise ValueError(e.reason) | ||
|
||
def read(self, size=-1): | ||
if size < 0: | ||
return self.response.read() | ||
return self.response.read(size) | ||
|
||
def close(self): | ||
return self.response.close() | ||
|
||
def seek(self, offset, whence): | ||
return self.response.seek(offset, whence=whence) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters