Skip to content

Commit

Permalink
[Storage File] pylint + mypy pass
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshith91 committed Jul 2, 2019
1 parent e9341e0 commit 877cf44
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 121 deletions.
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-file/azure/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-file/azure/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__path__ = __import__('pkgutil').extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
try:
from urllib.parse import urlparse, unquote
except ImportError:
from urlparse import urlparse
from urllib2 import unquote
from urlparse import urlparse # type: ignore
from urllib2 import unquote # type: ignore

from azure.core.exceptions import ClientAuthenticationError
from azure.core.pipeline.policies import SansIOHTTPPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
if sys.version_info >= (3, 5):
# the timeout to connect is 20 seconds, and the read timeout is 2000 seconds
# the 2000 seconds was calculated with: 100MB (max block size)/ 50KB/s (an arbitrarily chosen minimum upload speed)
DEFAULT_SOCKET_TIMEOUT = (20, 2000)
DEFAULT_SOCKET_TIMEOUT = (20, 2000) # type: ignore

STORAGE_OAUTH_SCOPE = "https://storage.azure.com/.default"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def __str__(self):
('f' if self.file else ''))


Services.BLOB = Services(blob=True)
Services.QUEUE = Services(queue=True)
Services.TABLE = Services(table=True)
Services.FILE = Services(file=True)
Services.BLOB = Services(blob=True) # type: ignore
Services.QUEUE = Services(queue=True) # type: ignore
Services.TABLE = Services(table=True) # type: ignore
Services.FILE = Services(file=True) # type: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import uuid
import types
import platform
from typing import Any, TYPE_CHECKING
from wsgiref.handlers import format_date_time
try:
from urllib.parse import (
Expand All @@ -23,8 +24,8 @@
urlencode,
)
except ImportError:
from urllib import urlencode
from urlparse import (
from urllib import urlencode # type: ignore
from urlparse import ( # type: ignore
urlparse,
parse_qsl,
urlunparse,
Expand All @@ -42,13 +43,14 @@
from .models import LocationMode

try:
_unicode_type = unicode
_unicode_type = unicode # type: ignore
except NameError:
_unicode_type = str


_LOGGER = logging.getLogger(__name__)

if TYPE_CHECKING:
from azure.core.pipeline import PipelineRequest, PipelineResponse

def encode_base64(data):
if isinstance(data, _unicode_type):
Expand Down Expand Up @@ -277,7 +279,7 @@ def __init__(self, **kwargs): # pylint: disable=unused-argument
super(StorageRequestHook, self).__init__()

def on_request(self, request, **kwargs):
# type: (PipelineRequest) -> PipelineResponse
# type: (PipelineRequest, **Any) -> PipelineResponse
request_callback = request.context.options.pop('raw_request_hook', self._request_callback)
if request_callback:
request_callback(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# --------------------------------------------------------------------------

from typing import ( # pylint: disable=unused-import
Union, Optional, Any, Iterable, Dict, List, Type,
Union, Optional, Any, Iterable, Dict, List, Type, Tuple,
TYPE_CHECKING
)
import base64
Expand All @@ -18,8 +18,8 @@
try:
from urllib.parse import quote, unquote, parse_qs
except ImportError:
from urlparse import parse_qs
from urllib2 import quote, unquote
from urlparse import parse_qs # type: ignore
from urllib2 import quote, unquote # type: ignore

import six
import isodate
Expand Down Expand Up @@ -118,7 +118,7 @@ def to_list():
class StorageAccountHostsMixin(object):

def __init__(
self, parsed_url, # type: str
self, parsed_url, # type: Any
service, # type: str
credential=None, # type: Optional[Any]
**kwargs # type: Any
Expand Down Expand Up @@ -487,7 +487,7 @@ def create_configuration(**kwargs):


def create_pipeline(credential, **kwargs):
# type: (Configuration, Optional[HTTPPolicy], **Any) -> Tuple[Configuration, Pipeline]
# type: (Any, **Any) -> Tuple[Configuration, Pipeline]
credential_policy = None
if hasattr(credential, 'get_token'):
credential_policy = BearerTokenCredentialPolicy(credential, STORAGE_OAUTH_SCOPE)
Expand Down Expand Up @@ -542,8 +542,8 @@ def is_credential_sastoken(credential):
return False


def add_metadata_headers(metadata):
# type: (Dict[str, str]) -> Dict[str, str]
def add_metadata_headers(metadata=None):
# type: (Optional[Dict[str, str]]) -> Dict[str, str]
headers = {}
if metadata:
for key, value in metadata.items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# --------------------------------------------------------------------------

import functools

from typing import ( # pylint: disable=unused-import
Optional, Union, Any, Dict, TYPE_CHECKING
)
try:
from urllib.parse import urlparse, quote, unquote
except ImportError:
from urlparse import urlparse
from urllib2 import quote, unquote
from urlparse import urlparse # type: ignore
from urllib2 import quote, unquote # type: ignore

import six
from azure.core.polling import LROPoller
Expand All @@ -32,6 +34,9 @@
from ._share_utils import deserialize_directory_properties
from .polling import CloseHandles

if TYPE_CHECKING:
from .models import SharePermissions, ShareProperties, DirectoryProperties, ContentSettings
from ._generated.models import HandleItem

class DirectoryClient(StorageAccountHostsMixin):
"""A client to interact with a specific directory, although it may not yet exist.
Expand Down Expand Up @@ -73,15 +78,15 @@ class DirectoryClient(StorageAccountHostsMixin):
account URL already has a SAS token. The value can be a SAS token string or an account
shared access key.
"""
def __init__(
def __init__( # type: ignore
self, directory_url, # type: str
share=None, # type: Optional[Union[str, ShareProperties]]
directory_path=None, # type: Optional[str]
snapshot=None, # type: Optional[Union[str, Dict[str, Any]]]
credential=None, # type: Optional[Any]
**kwargs # type: Optional[Any]
):
# type: (...) -> DirectoryClient
# type: (...) -> None
try:
if not directory_url.lower().startswith('http'):
directory_url = "https://" + directory_url
Expand All @@ -103,14 +108,14 @@ def __init__(
raise ValueError(
'You need to provide either an account key or SAS token when creating a storage service.')
try:
self.snapshot = snapshot.snapshot
self.snapshot = snapshot.snapshot # type: ignore
except AttributeError:
try:
self.snapshot = snapshot['snapshot']
self.snapshot = snapshot['snapshot'] # type: ignore
except TypeError:
self.snapshot = snapshot or path_snapshot
try:
self.share_name = share.name
self.share_name = share.name # type: ignore
except AttributeError:
self.share_name = share or unquote(share)
self.directory_path = directory_path or path_dir
Expand Down Expand Up @@ -142,7 +147,7 @@ def from_connection_string(
cls, conn_str, # type: str
share=None, # type: Optional[Union[str, ShareProperties]]
directory_path=None, # type: Optional[str]
credential=None, # type: Optiona[Any]
credential=None, # type: Optional[Any]
**kwargs # type: Any
):
# type: (...) -> DirectoryClient
Expand Down Expand Up @@ -207,7 +212,7 @@ def get_subdirectory_client(self, directory_name, **kwargs):
_hosts=self._hosts, _configuration=self._config, _pipeline=self._pipeline,
_location_mode=self._location_mode, **kwargs)

def create_directory(
def create_directory( # type: ignore
self, metadata=None, # type: Optional[Dict[str, str]]
timeout=None, # type: Optional[int]
**kwargs # type: Optional[Any]
Expand All @@ -232,9 +237,9 @@ def create_directory(
:caption: Creates a directory.
"""
headers = kwargs.pop('headers', {})
headers.update(add_metadata_headers(metadata))
headers.update(add_metadata_headers(metadata)) # type: ignore
try:
return self._client.directory.create(
return self._client.directory.create( # type: ignore
timeout=timeout,
cls=return_response_headers,
headers=headers,
Expand All @@ -243,7 +248,7 @@ def create_directory(
process_storage_error(error)

def delete_directory(self, timeout=None, **kwargs):
# type: (Optional[int]) -> None
# type: (Optional[int], **Any) -> None
"""Marks the directory for deletion. The directory is
later deleted during garbage collection.
Expand All @@ -265,7 +270,7 @@ def delete_directory(self, timeout=None, **kwargs):
process_storage_error(error)

def list_directories_and_files(self, name_starts_with=None, marker=None, timeout=None, **kwargs):
# type: (Optional[str], Optional[int]) -> DirectoryProperties
# type: (Optional[str], Optional[str], Optional[int], **Any) -> DirectoryProperties
"""Lists all the directories and files under the directory.
:param str name_starts_with:
Expand Down Expand Up @@ -347,7 +352,7 @@ def close_handles(
:rtype: ~azure.core.polling.LROPoller
"""
try:
handle_id = handle.id
handle_id = handle.id # type: ignore
except AttributeError:
handle_id = handle or '*'
command = functools.partial(
Expand Down Expand Up @@ -388,9 +393,9 @@ def get_directory_properties(self, timeout=None, **kwargs):
**kwargs)
except StorageErrorException as error:
process_storage_error(error)
return response
return response # type: ignore

def set_directory_metadata(self, metadata, timeout=None, **kwargs):
def set_directory_metadata(self, metadata, timeout=None, **kwargs): # type: ignore
# type: (Dict[str, Any], Optional[int], Any) -> Dict[str, Any]
"""Sets the metadata for the directory.
Expand All @@ -409,7 +414,7 @@ def set_directory_metadata(self, metadata, timeout=None, **kwargs):
headers = kwargs.pop('headers', {})
headers.update(add_metadata_headers(metadata))
try:
return self._client.directory.set_metadata(
return self._client.directory.set_metadata( # type: ignore
timeout=timeout,
cls=return_response_headers,
headers=headers,
Expand All @@ -418,7 +423,7 @@ def set_directory_metadata(self, metadata, timeout=None, **kwargs):
process_storage_error(error)

def create_subdirectory(
self, directory_name, # type: str,
self, directory_name, # type: str
metadata=None, #type: Optional[Dict[str, Any]]
timeout=None, # type: Optional[int]
**kwargs
Expand Down Expand Up @@ -447,10 +452,10 @@ def create_subdirectory(
"""
subdir = self.get_subdirectory_client(directory_name)
subdir.create_directory(metadata=metadata, timeout=timeout, **kwargs)
return subdir
return subdir # type: ignore

def delete_subdirectory(
self, directory_name, # type: str,
self, directory_name, # type: str
timeout=None, # type: Optional[int]
**kwargs
):
Expand Down Expand Up @@ -536,11 +541,11 @@ def upload_file(
timeout=timeout,
encoding=encoding,
**kwargs)
return file_client
return file_client # type: ignore

def delete_file(
self, file_name, # type: str,
timeout=None, # type: Optional[int],
self, file_name, # type: str
timeout=None, # type: Optional[int]
**kwargs # type: Optional[Any]
):
# type: (...) -> None
Expand Down
Loading

0 comments on commit 877cf44

Please sign in to comment.