Skip to content

Commit 4ad1d0d

Browse files
committed
properly set user-agent for py2/py3
1 parent ec76a39 commit 4ad1d0d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

bagit.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
if sys.version_info >= (3,):
2929
from urllib.parse import urlparse
3030
from urllib.request import urlopen, FancyURLopener
31+
import urllib.request
3132
else:
3233
from urllib import urlopen, FancyURLopener
3334
from urlparse import urlparse
@@ -590,7 +591,10 @@ def fetch_files_to_be_fetched(self):
590591
"""
591592
Fetches files from the fetch.txt
592593
"""
593-
urllib._urlopener = BagFetcherURLOpener # pylint: disable=protected-access
594+
if sys.version_info >= (3,):
595+
urllib.request._urlopener = BagFetcherURLOpener() # pylint: disable=protected-access
596+
else:
597+
urllib._urlopener = BagFetcherURLOpener() # pylint: disable=protected-access
594598
for url, expected_size, filename in self.fetch_entries():
595599
expected_size = int(expected_size) # FIXME should be int in the first place
596600
if filename in self.payload_files():
@@ -974,7 +978,7 @@ def _path_is_dangerous(self, path):
974978
return not (common == bag_path)
975979

976980
class BagFetcherURLOpener(FancyURLopener):
977-
version = "bagit.py/%s (Python/%s)" % (VERSION, sys.version)
981+
version = "bagit.py/%s (Python/%s)" % (VERSION, sys.version_info)
978982

979983
class BagError(Exception):
980984
pass

0 commit comments

Comments
 (0)