Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OWCSVImport: Get ready for OWFile merge #5077

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Orange/data/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from os import path, remove
from tempfile import NamedTemporaryFile
from urllib.error import HTTPError
from urllib.parse import urlparse, urlsplit, urlunsplit, \
unquote as urlunquote, quote
from urllib.request import urlopen, Request
Expand Down Expand Up @@ -405,7 +406,7 @@ class UrlReader(FileFormat):
def __init__(self, filename):
filename = filename.strip()
if not urlparse(filename).scheme:
filename = 'http://' + filename
filename = 'https://' + filename
filename = quote(filename, safe="/:")
super().__init__(filename)

Expand Down Expand Up @@ -437,8 +438,11 @@ def read(self):

def _resolve_redirects(self, url):
# Resolve (potential) redirects to a final URL
with contextlib.closing(self.urlopen(url)) as response:
return response.url
try:
with contextlib.closing(self.urlopen(url)) as response:
return response.url
except HTTPError:
return url

@classmethod
def _trim(cls, url):
Expand All @@ -460,7 +464,7 @@ def _trim_googlesheet(url):
match = re.match(r'(?:https?://)?(?:www\.)?'
r'docs\.google\.com/spreadsheets/d/'
r'(?P<workbook_id>[-\w_]+)'
r'(?:/.*?gid=(?P<sheet_id>\d+).*|.*)?',
r'(?:/.*?gid(=|%3D)(?P<sheet_id>\d+).*|.*)?',
url, re.IGNORECASE)
try:
workbook, sheet = match.group('workbook_id'), match.group('sheet_id')
Expand Down
Loading