Skip to content

Commit

Permalink
Merge pull request #216 from Azure/EncodedPaths
Browse files Browse the repository at this point in the history
Encoded paths
  • Loading branch information
milanchandna committed Jun 5, 2018
2 parents 35cbd94 + e30e9d4 commit 82f319f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.0.22 (2018-06-02)
+++++++++++++++++++
* Encoding filepaths in URI

0.0.21 (2018-06-01)
+++++++++++++++++++
* Remove unused msrest dependency
Expand Down
2 changes: 1 addition & 1 deletion azure/datalake/store/__init__.py
Expand Up @@ -6,7 +6,7 @@
# license information.
# --------------------------------------------------------------------------

__version__ = "0.0.21"
__version__ = "0.0.22"

from .core import AzureDLFileSystem
from .multithread import ADLDownloader
Expand Down
10 changes: 8 additions & 2 deletions azure/datalake/store/lib.py
Expand Up @@ -19,6 +19,12 @@
import time
import uuid
import platform
import sys

if sys.version_info >= (3, 4):
import urllib.parse as urllib
else:
import urllib

# 3rd party imports
import adal
Expand Down Expand Up @@ -370,12 +376,12 @@ def call(self, op, path='', is_extended=False, expected_error_code=None, **kwarg
url = self.url + self.extended_operations
else:
url = self.url + self.webhdfs
url += path
url += urllib.quote(path)
try:
headers = self.head.copy()
headers['x-ms-client-request-id'] = str(uuid.uuid1())
headers['User-Agent'] = self.user_agent
self._log_request(method, url, op, path, kwargs, headers)
self._log_request(method, url, op, urllib.quote(path), kwargs, headers)
r = func(url, params=params, headers=headers, data=data, stream=stream)
except requests.exceptions.RequestException as e:
raise DatalakeRESTException('HTTP error: ' + repr(e))
Expand Down
24 changes: 24 additions & 0 deletions tests/test_core.py
Expand Up @@ -20,6 +20,7 @@
b = posix(test_dir / 'b')
c = posix(test_dir / 'c')
d = posix(test_dir / 'd')
specialCharFile = posix(test_dir / '12,+3#456?.txt')


@my_vcr.use_cassette
Expand Down Expand Up @@ -433,6 +434,29 @@ def test_full_read(azure):
assert f.tell() == 10


@my_vcr.use_cassette
def test_filename_specialchar(azure):
with azure_teardown(azure):
with azure.open(specialCharFile, 'wb') as f:
f.write(b'0123456789')

with azure.open(specialCharFile, 'rb') as f:
assert len(f.read(4)) == 4
assert len(f.read(4)) == 4
assert len(f.read(4)) == 2

with azure.open(specialCharFile, 'rb') as f:
assert len(f.read()) == 10

with azure.open(specialCharFile, 'rb') as f:
assert f.tell() == 0
f.seek(3)
assert f.read(4) == b'3456'
assert f.tell() == 7
assert f.read(4) == b'789'
assert f.tell() == 10


def __ready_and_read_file_for_cache_test(azure, data=b'0123456789abcdef'):
with azure.open(a, 'wb') as f:
f.write(data)
Expand Down

0 comments on commit 82f319f

Please sign in to comment.