1# coding=utf-8
2# --------------------------------------------------------------------------
3# Copyright (c) Microsoft Corporation. All rights reserved.
4# Licensed under the MIT License. See License.txt in the project root for
5# license information.
6#
7# Code generated by Microsoft (R) AutoRest Code Generator.
8# Changes may cause incorrect behavior and will be lost if the code is
9# regenerated.
10# --------------------------------------------------------------------------
11
12from azure.core.exceptions import map_error
13
14from ... import models
15
16
17class DirectoryOperations:
18    """DirectoryOperations async operations.
19
20    You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute.
21
22    :param client: Client for service requests.
23    :param config: Configuration of service client.
24    :param serializer: An object model serializer.
25    :param deserializer: An object model deserializer.
26    :ivar restype: . Constant value: "directory".
27    """
28
29    models = models
30
31    def __init__(self, client, config, serializer, deserializer) -> None:
32
33        self._client = client
34        self._serialize = serializer
35        self._deserialize = deserializer
36
37        self._config = config
38        self.restype = "directory"
39
40    async def create(self, file_attributes="none", file_creation_time="now", file_last_write_time="now", timeout=None, metadata=None, file_permission="inherit", file_permission_key=None, *, cls=None, **kwargs):
41        """Creates a new directory under the specified share or parent directory.
42
43        :param file_attributes: If specified, the provided file attributes
44         shall be set. Default value: ‘Archive’ for file and ‘Directory’ for
45         directory. ‘None’ can also be specified as default.
46        :type file_attributes: str
47        :param file_creation_time: Creation time for the file/directory.
48         Default value: Now.
49        :type file_creation_time: str
50        :param file_last_write_time: Last write time for the file/directory.
51         Default value: Now.
52        :type file_last_write_time: str
53        :param timeout: The timeout parameter is expressed in seconds. For
54         more information, see <a
55         href="https://docs.microsoft.com/en-us/rest/api/storageservices/Setting-Timeouts-for-File-Service-Operations?redirectedfrom=MSDN">Setting
56         Timeouts for File Service Operations.</a>
57        :type timeout: int
58        :param metadata: A name-value pair to associate with a file storage
59         object.
60        :type metadata: str
61        :param file_permission: If specified the permission (security
62         descriptor) shall be set for the directory/file. This header can be
63         used if Permission size is <= 8KB, else x-ms-file-permission-key
64         header shall be used. Default value: Inherit. If SDDL is specified as
65         input, it must have owner, group and dacl. Note: Only one of the
66         x-ms-file-permission or x-ms-file-permission-key should be specified.
67        :type file_permission: str
68        :param file_permission_key: Key of the permission to be set for the
69         directory/file. Note: Only one of the x-ms-file-permission or
70         x-ms-file-permission-key should be specified.
71        :type file_permission_key: str
72        :param callable cls: A custom type or function that will be passed the
73         direct response
74        :return: None or the result of cls(response)
75        :rtype: None
76        :raises:
77         :class:`StorageErrorException<azure.storage.fileshare.models.StorageErrorException>`
78        """
79        error_map = kwargs.pop('error_map', None)
80        # Construct URL
81        url = self.create.metadata['url']
82        path_format_arguments = {
83            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
84        }
85        url = self._client.format_url(url, **path_format_arguments)
86
87        # Construct parameters
88        query_parameters = {}
89        if timeout is not None:
90            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
91        query_parameters['restype'] = self._serialize.query("self.restype", self.restype, 'str')
92
93        # Construct headers
94        header_parameters = {}
95        if metadata is not None:
96            header_parameters['x-ms-meta'] = self._serialize.header("metadata", metadata, 'str')
97        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
98        if file_permission is not None:
99            header_parameters['x-ms-file-permission'] = self._serialize.header("file_permission", file_permission, 'str')
100        if file_permission_key is not None:
101            header_parameters['x-ms-file-permission-key'] = self._serialize.header("file_permission_key", file_permission_key, 'str')
102        header_parameters['x-ms-file-attributes'] = self._serialize.header("file_attributes", file_attributes, 'str')
103        header_parameters['x-ms-file-creation-time'] = self._serialize.header("file_creation_time", file_creation_time, 'str')
104        header_parameters['x-ms-file-last-write-time'] = self._serialize.header("file_last_write_time", file_last_write_time, 'str')
105
106        # Construct and send request
107        request = self._client.put(url, query_parameters, header_parameters)
108        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
109        response = pipeline_response.http_response
110
111        if response.status_code not in [201]:
112            map_error(status_code=response.status_code, response=response, error_map=error_map)
113            raise models.StorageErrorException(response, self._deserialize)
114
115        if cls:
116            response_headers = {
117                'ETag': self._deserialize('str', response.headers.get('ETag')),
118                'Last-Modified': self._deserialize('rfc-1123', response.headers.get('Last-Modified')),
119                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
120                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
121                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
122                'x-ms-request-server-encrypted': self._deserialize('bool', response.headers.get('x-ms-request-server-encrypted')),
123                'x-ms-file-permission-key': self._deserialize('str', response.headers.get('x-ms-file-permission-key')),
124                'x-ms-file-attributes': self._deserialize('str', response.headers.get('x-ms-file-attributes')),
125                'x-ms-file-creation-time': self._deserialize('str', response.headers.get('x-ms-file-creation-time')),
126                'x-ms-file-last-write-time': self._deserialize('str', response.headers.get('x-ms-file-last-write-time')),
127                'x-ms-file-change-time': self._deserialize('str', response.headers.get('x-ms-file-change-time')),
128                'x-ms-file-id': self._deserialize('str', response.headers.get('x-ms-file-id')),
129                'x-ms-file-parent-id': self._deserialize('str', response.headers.get('x-ms-file-parent-id')),
130                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
131            }
132            return cls(response, None, response_headers)
133    create.metadata = {'url': '/{shareName}/{directory}'}
134
135    async def get_properties(self, sharesnapshot=None, timeout=None, *, cls=None, **kwargs):
136        """Returns all system properties for the specified directory, and can also
137        be used to check the existence of a directory. The data returned does
138        not include the files in the directory or any subdirectories.
139
140        :param sharesnapshot: The snapshot parameter is an opaque DateTime
141         value that, when present, specifies the share snapshot to query.
142        :type sharesnapshot: str
143        :param timeout: The timeout parameter is expressed in seconds. For
144         more information, see <a
145         href="https://docs.microsoft.com/en-us/rest/api/storageservices/Setting-Timeouts-for-File-Service-Operations?redirectedfrom=MSDN">Setting
146         Timeouts for File Service Operations.</a>
147        :type timeout: int
148        :param callable cls: A custom type or function that will be passed the
149         direct response
150        :return: None or the result of cls(response)
151        :rtype: None
152        :raises:
153         :class:`StorageErrorException<azure.storage.fileshare.models.StorageErrorException>`
154        """
155        error_map = kwargs.pop('error_map', None)
156        # Construct URL
157        url = self.get_properties.metadata['url']
158        path_format_arguments = {
159            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
160        }
161        url = self._client.format_url(url, **path_format_arguments)
162
163        # Construct parameters
164        query_parameters = {}
165        if sharesnapshot is not None:
166            query_parameters['sharesnapshot'] = self._serialize.query("sharesnapshot", sharesnapshot, 'str')
167        if timeout is not None:
168            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
169        query_parameters['restype'] = self._serialize.query("self.restype", self.restype, 'str')
170
171        # Construct headers
172        header_parameters = {}
173        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
174
175        # Construct and send request
176        request = self._client.get(url, query_parameters, header_parameters)
177        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
178        response = pipeline_response.http_response
179
180        if response.status_code not in [200]:
181            map_error(status_code=response.status_code, response=response, error_map=error_map)
182            raise models.StorageErrorException(response, self._deserialize)
183
184        if cls:
185            response_headers = {
186                'x-ms-meta': self._deserialize('{str}', response.headers.get('x-ms-meta')),
187                'ETag': self._deserialize('str', response.headers.get('ETag')),
188                'Last-Modified': self._deserialize('rfc-1123', response.headers.get('Last-Modified')),
189                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
190                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
191                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
192                'x-ms-server-encrypted': self._deserialize('bool', response.headers.get('x-ms-server-encrypted')),
193                'x-ms-file-attributes': self._deserialize('str', response.headers.get('x-ms-file-attributes')),
194                'x-ms-file-creation-time': self._deserialize('str', response.headers.get('x-ms-file-creation-time')),
195                'x-ms-file-last-write-time': self._deserialize('str', response.headers.get('x-ms-file-last-write-time')),
196                'x-ms-file-change-time': self._deserialize('str', response.headers.get('x-ms-file-change-time')),
197                'x-ms-file-permission-key': self._deserialize('str', response.headers.get('x-ms-file-permission-key')),
198                'x-ms-file-id': self._deserialize('str', response.headers.get('x-ms-file-id')),
199                'x-ms-file-parent-id': self._deserialize('str', response.headers.get('x-ms-file-parent-id')),
200                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
201            }
202            return cls(response, None, response_headers)
203    get_properties.metadata = {'url': '/{shareName}/{directory}'}
204
205    async def delete(self, timeout=None, *, cls=None, **kwargs):
206        """Removes the specified empty directory. Note that the directory must be
207        empty before it can be deleted.
208
209        :param timeout: The timeout parameter is expressed in seconds. For
210         more information, see <a
211         href="https://docs.microsoft.com/en-us/rest/api/storageservices/Setting-Timeouts-for-File-Service-Operations?redirectedfrom=MSDN">Setting
212         Timeouts for File Service Operations.</a>
213        :type timeout: int
214        :param callable cls: A custom type or function that will be passed the
215         direct response
216        :return: None or the result of cls(response)
217        :rtype: None
218        :raises:
219         :class:`StorageErrorException<azure.storage.fileshare.models.StorageErrorException>`
220        """
221        error_map = kwargs.pop('error_map', None)
222        # Construct URL
223        url = self.delete.metadata['url']
224        path_format_arguments = {
225            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
226        }
227        url = self._client.format_url(url, **path_format_arguments)
228
229        # Construct parameters
230        query_parameters = {}
231        if timeout is not None:
232            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
233        query_parameters['restype'] = self._serialize.query("self.restype", self.restype, 'str')
234
235        # Construct headers
236        header_parameters = {}
237        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
238
239        # Construct and send request
240        request = self._client.delete(url, query_parameters, header_parameters)
241        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
242        response = pipeline_response.http_response
243
244        if response.status_code not in [202]:
245            map_error(status_code=response.status_code, response=response, error_map=error_map)
246            raise models.StorageErrorException(response, self._deserialize)
247
248        if cls:
249            response_headers = {
250                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
251                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
252                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
253                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
254            }
255            return cls(response, None, response_headers)
256    delete.metadata = {'url': '/{shareName}/{directory}'}
257
258    async def set_properties(self, file_attributes="none", file_creation_time="now", file_last_write_time="now", timeout=None, file_permission="inherit", file_permission_key=None, *, cls=None, **kwargs):
259        """Sets properties on the directory.
260
261        :param file_attributes: If specified, the provided file attributes
262         shall be set. Default value: ‘Archive’ for file and ‘Directory’ for
263         directory. ‘None’ can also be specified as default.
264        :type file_attributes: str
265        :param file_creation_time: Creation time for the file/directory.
266         Default value: Now.
267        :type file_creation_time: str
268        :param file_last_write_time: Last write time for the file/directory.
269         Default value: Now.
270        :type file_last_write_time: str
271        :param timeout: The timeout parameter is expressed in seconds. For
272         more information, see <a
273         href="https://docs.microsoft.com/en-us/rest/api/storageservices/Setting-Timeouts-for-File-Service-Operations?redirectedfrom=MSDN">Setting
274         Timeouts for File Service Operations.</a>
275        :type timeout: int
276        :param file_permission: If specified the permission (security
277         descriptor) shall be set for the directory/file. This header can be
278         used if Permission size is <= 8KB, else x-ms-file-permission-key
279         header shall be used. Default value: Inherit. If SDDL is specified as
280         input, it must have owner, group and dacl. Note: Only one of the
281         x-ms-file-permission or x-ms-file-permission-key should be specified.
282        :type file_permission: str
283        :param file_permission_key: Key of the permission to be set for the
284         directory/file. Note: Only one of the x-ms-file-permission or
285         x-ms-file-permission-key should be specified.
286        :type file_permission_key: str
287        :param callable cls: A custom type or function that will be passed the
288         direct response
289        :return: None or the result of cls(response)
290        :rtype: None
291        :raises:
292         :class:`StorageErrorException<azure.storage.fileshare.models.StorageErrorException>`
293        """
294        error_map = kwargs.pop('error_map', None)
295        comp = "properties"
296
297        # Construct URL
298        url = self.set_properties.metadata['url']
299        path_format_arguments = {
300            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
301        }
302        url = self._client.format_url(url, **path_format_arguments)
303
304        # Construct parameters
305        query_parameters = {}
306        if timeout is not None:
307            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
308        query_parameters['restype'] = self._serialize.query("self.restype", self.restype, 'str')
309        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
310
311        # Construct headers
312        header_parameters = {}
313        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
314        if file_permission is not None:
315            header_parameters['x-ms-file-permission'] = self._serialize.header("file_permission", file_permission, 'str')
316        if file_permission_key is not None:
317            header_parameters['x-ms-file-permission-key'] = self._serialize.header("file_permission_key", file_permission_key, 'str')
318        header_parameters['x-ms-file-attributes'] = self._serialize.header("file_attributes", file_attributes, 'str')
319        header_parameters['x-ms-file-creation-time'] = self._serialize.header("file_creation_time", file_creation_time, 'str')
320        header_parameters['x-ms-file-last-write-time'] = self._serialize.header("file_last_write_time", file_last_write_time, 'str')
321
322        # Construct and send request
323        request = self._client.put(url, query_parameters, header_parameters)
324        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
325        response = pipeline_response.http_response
326
327        if response.status_code not in [200]:
328            map_error(status_code=response.status_code, response=response, error_map=error_map)
329            raise models.StorageErrorException(response, self._deserialize)
330
331        if cls:
332            response_headers = {
333                'ETag': self._deserialize('str', response.headers.get('ETag')),
334                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
335                'Last-Modified': self._deserialize('rfc-1123', response.headers.get('Last-Modified')),
336                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
337                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
338                'x-ms-request-server-encrypted': self._deserialize('bool', response.headers.get('x-ms-request-server-encrypted')),
339                'x-ms-file-permission-key': self._deserialize('str', response.headers.get('x-ms-file-permission-key')),
340                'x-ms-file-attributes': self._deserialize('str', response.headers.get('x-ms-file-attributes')),
341                'x-ms-file-creation-time': self._deserialize('str', response.headers.get('x-ms-file-creation-time')),
342                'x-ms-file-last-write-time': self._deserialize('str', response.headers.get('x-ms-file-last-write-time')),
343                'x-ms-file-change-time': self._deserialize('str', response.headers.get('x-ms-file-change-time')),
344                'x-ms-file-id': self._deserialize('str', response.headers.get('x-ms-file-id')),
345                'x-ms-file-parent-id': self._deserialize('str', response.headers.get('x-ms-file-parent-id')),
346                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
347            }
348            return cls(response, None, response_headers)
349    set_properties.metadata = {'url': '/{shareName}/{directory}'}
350
351    async def set_metadata(self, timeout=None, metadata=None, *, cls=None, **kwargs):
352        """Updates user defined metadata for the specified directory.
353
354        :param timeout: The timeout parameter is expressed in seconds. For
355         more information, see <a
356         href="https://docs.microsoft.com/en-us/rest/api/storageservices/Setting-Timeouts-for-File-Service-Operations?redirectedfrom=MSDN">Setting
357         Timeouts for File Service Operations.</a>
358        :type timeout: int
359        :param metadata: A name-value pair to associate with a file storage
360         object.
361        :type metadata: str
362        :param callable cls: A custom type or function that will be passed the
363         direct response
364        :return: None or the result of cls(response)
365        :rtype: None
366        :raises:
367         :class:`StorageErrorException<azure.storage.fileshare.models.StorageErrorException>`
368        """
369        error_map = kwargs.pop('error_map', None)
370        comp = "metadata"
371
372        # Construct URL
373        url = self.set_metadata.metadata['url']
374        path_format_arguments = {
375            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
376        }
377        url = self._client.format_url(url, **path_format_arguments)
378
379        # Construct parameters
380        query_parameters = {}
381        if timeout is not None:
382            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
383        query_parameters['restype'] = self._serialize.query("self.restype", self.restype, 'str')
384        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
385
386        # Construct headers
387        header_parameters = {}
388        if metadata is not None:
389            header_parameters['x-ms-meta'] = self._serialize.header("metadata", metadata, 'str')
390        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
391
392        # Construct and send request
393        request = self._client.put(url, query_parameters, header_parameters)
394        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
395        response = pipeline_response.http_response
396
397        if response.status_code not in [200]:
398            map_error(status_code=response.status_code, response=response, error_map=error_map)
399            raise models.StorageErrorException(response, self._deserialize)
400
401        if cls:
402            response_headers = {
403                'ETag': self._deserialize('str', response.headers.get('ETag')),
404                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
405                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
406                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
407                'x-ms-request-server-encrypted': self._deserialize('bool', response.headers.get('x-ms-request-server-encrypted')),
408                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
409            }
410            return cls(response, None, response_headers)
411    set_metadata.metadata = {'url': '/{shareName}/{directory}'}
412
413    async def list_files_and_directories_segment(self, prefix=None, sharesnapshot=None, marker=None, maxresults=None, timeout=None, *, cls=None, **kwargs):
414        """Returns a list of files or directories under the specified share or
415        directory. It lists the contents only for a single level of the
416        directory hierarchy.
417
418        :param prefix: Filters the results to return only entries whose name
419         begins with the specified prefix.
420        :type prefix: str
421        :param sharesnapshot: The snapshot parameter is an opaque DateTime
422         value that, when present, specifies the share snapshot to query.
423        :type sharesnapshot: str
424        :param marker: A string value that identifies the portion of the list
425         to be returned with the next list operation. The operation returns a
426         marker value within the response body if the list returned was not
427         complete. The marker value may then be used in a subsequent call to
428         request the next set of list items. The marker value is opaque to the
429         client.
430        :type marker: str
431        :param maxresults: Specifies the maximum number of entries to return.
432         If the request does not specify maxresults, or specifies a value
433         greater than 5,000, the server will return up to 5,000 items.
434        :type maxresults: int
435        :param timeout: The timeout parameter is expressed in seconds. For
436         more information, see <a
437         href="https://docs.microsoft.com/en-us/rest/api/storageservices/Setting-Timeouts-for-File-Service-Operations?redirectedfrom=MSDN">Setting
438         Timeouts for File Service Operations.</a>
439        :type timeout: int
440        :param callable cls: A custom type or function that will be passed the
441         direct response
442        :return: ListFilesAndDirectoriesSegmentResponse or the result of
443         cls(response)
444        :rtype:
445         ~azure.storage.fileshare.models.ListFilesAndDirectoriesSegmentResponse
446        :raises:
447         :class:`StorageErrorException<azure.storage.fileshare.models.StorageErrorException>`
448        """
449        error_map = kwargs.pop('error_map', None)
450        comp = "list"
451
452        # Construct URL
453        url = self.list_files_and_directories_segment.metadata['url']
454        path_format_arguments = {
455            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
456        }
457        url = self._client.format_url(url, **path_format_arguments)
458
459        # Construct parameters
460        query_parameters = {}
461        if prefix is not None:
462            query_parameters['prefix'] = self._serialize.query("prefix", prefix, 'str')
463        if sharesnapshot is not None:
464            query_parameters['sharesnapshot'] = self._serialize.query("sharesnapshot", sharesnapshot, 'str')
465        if marker is not None:
466            query_parameters['marker'] = self._serialize.query("marker", marker, 'str')
467        if maxresults is not None:
468            query_parameters['maxresults'] = self._serialize.query("maxresults", maxresults, 'int', minimum=1)
469        if timeout is not None:
470            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
471        query_parameters['restype'] = self._serialize.query("self.restype", self.restype, 'str')
472        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
473
474        # Construct headers
475        header_parameters = {}
476        header_parameters['Accept'] = 'application/xml'
477        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
478
479        # Construct and send request
480        request = self._client.get(url, query_parameters, header_parameters)
481        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
482        response = pipeline_response.http_response
483
484        if response.status_code not in [200]:
485            map_error(status_code=response.status_code, response=response, error_map=error_map)
486            raise models.StorageErrorException(response, self._deserialize)
487
488        header_dict = {}
489        deserialized = None
490        if response.status_code == 200:
491            deserialized = self._deserialize('ListFilesAndDirectoriesSegmentResponse', response)
492            header_dict = {
493                'Content-Type': self._deserialize('str', response.headers.get('Content-Type')),
494                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
495                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
496                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
497                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
498            }
499
500        if cls:
501            return cls(response, deserialized, header_dict)
502
503        return deserialized
504    list_files_and_directories_segment.metadata = {'url': '/{shareName}/{directory}'}
505
506    async def list_handles(self, marker=None, maxresults=None, timeout=None, sharesnapshot=None, recursive=None, *, cls=None, **kwargs):
507        """Lists handles for directory.
508
509        :param marker: A string value that identifies the portion of the list
510         to be returned with the next list operation. The operation returns a
511         marker value within the response body if the list returned was not
512         complete. The marker value may then be used in a subsequent call to
513         request the next set of list items. The marker value is opaque to the
514         client.
515        :type marker: str
516        :param maxresults: Specifies the maximum number of entries to return.
517         If the request does not specify maxresults, or specifies a value
518         greater than 5,000, the server will return up to 5,000 items.
519        :type maxresults: int
520        :param timeout: The timeout parameter is expressed in seconds. For
521         more information, see <a
522         href="https://docs.microsoft.com/en-us/rest/api/storageservices/Setting-Timeouts-for-File-Service-Operations?redirectedfrom=MSDN">Setting
523         Timeouts for File Service Operations.</a>
524        :type timeout: int
525        :param sharesnapshot: The snapshot parameter is an opaque DateTime
526         value that, when present, specifies the share snapshot to query.
527        :type sharesnapshot: str
528        :param recursive: Specifies operation should apply to the directory
529         specified in the URI, its files, its subdirectories and their files.
530        :type recursive: bool
531        :param callable cls: A custom type or function that will be passed the
532         direct response
533        :return: ListHandlesResponse or the result of cls(response)
534        :rtype: ~azure.storage.fileshare.models.ListHandlesResponse
535        :raises:
536         :class:`StorageErrorException<azure.storage.fileshare.models.StorageErrorException>`
537        """
538        error_map = kwargs.pop('error_map', None)
539        comp = "listhandles"
540
541        # Construct URL
542        url = self.list_handles.metadata['url']
543        path_format_arguments = {
544            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
545        }
546        url = self._client.format_url(url, **path_format_arguments)
547
548        # Construct parameters
549        query_parameters = {}
550        if marker is not None:
551            query_parameters['marker'] = self._serialize.query("marker", marker, 'str')
552        if maxresults is not None:
553            query_parameters['maxresults'] = self._serialize.query("maxresults", maxresults, 'int', minimum=1)
554        if timeout is not None:
555            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
556        if sharesnapshot is not None:
557            query_parameters['sharesnapshot'] = self._serialize.query("sharesnapshot", sharesnapshot, 'str')
558        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
559
560        # Construct headers
561        header_parameters = {}
562        header_parameters['Accept'] = 'application/xml'
563        if recursive is not None:
564            header_parameters['x-ms-recursive'] = self._serialize.header("recursive", recursive, 'bool')
565        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
566
567        # Construct and send request
568        request = self._client.get(url, query_parameters, header_parameters)
569        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
570        response = pipeline_response.http_response
571
572        if response.status_code not in [200]:
573            map_error(status_code=response.status_code, response=response, error_map=error_map)
574            raise models.StorageErrorException(response, self._deserialize)
575
576        header_dict = {}
577        deserialized = None
578        if response.status_code == 200:
579            deserialized = self._deserialize('ListHandlesResponse', response)
580            header_dict = {
581                'Content-Type': self._deserialize('str', response.headers.get('Content-Type')),
582                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
583                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
584                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
585                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
586            }
587
588        if cls:
589            return cls(response, deserialized, header_dict)
590
591        return deserialized
592    list_handles.metadata = {'url': '/{shareName}/{directory}'}
593
594    async def force_close_handles(self, handle_id, timeout=None, marker=None, sharesnapshot=None, recursive=None, *, cls=None, **kwargs):
595        """Closes all handles open for given directory.
596
597        :param handle_id: Specifies handle ID opened on the file or directory
598         to be closed. Asterix (‘*’) is a wildcard that specifies all handles.
599        :type handle_id: str
600        :param timeout: The timeout parameter is expressed in seconds. For
601         more information, see <a
602         href="https://docs.microsoft.com/en-us/rest/api/storageservices/Setting-Timeouts-for-File-Service-Operations?redirectedfrom=MSDN">Setting
603         Timeouts for File Service Operations.</a>
604        :type timeout: int
605        :param marker: A string value that identifies the portion of the list
606         to be returned with the next list operation. The operation returns a
607         marker value within the response body if the list returned was not
608         complete. The marker value may then be used in a subsequent call to
609         request the next set of list items. The marker value is opaque to the
610         client.
611        :type marker: str
612        :param sharesnapshot: The snapshot parameter is an opaque DateTime
613         value that, when present, specifies the share snapshot to query.
614        :type sharesnapshot: str
615        :param recursive: Specifies operation should apply to the directory
616         specified in the URI, its files, its subdirectories and their files.
617        :type recursive: bool
618        :param callable cls: A custom type or function that will be passed the
619         direct response
620        :return: None or the result of cls(response)
621        :rtype: None
622        :raises:
623         :class:`StorageErrorException<azure.storage.fileshare.models.StorageErrorException>`
624        """
625        error_map = kwargs.pop('error_map', None)
626        comp = "forceclosehandles"
627
628        # Construct URL
629        url = self.force_close_handles.metadata['url']
630        path_format_arguments = {
631            'url': self._serialize.url("self._config.url", self._config.url, 'str', skip_quote=True)
632        }
633        url = self._client.format_url(url, **path_format_arguments)
634
635        # Construct parameters
636        query_parameters = {}
637        if timeout is not None:
638            query_parameters['timeout'] = self._serialize.query("timeout", timeout, 'int', minimum=0)
639        if marker is not None:
640            query_parameters['marker'] = self._serialize.query("marker", marker, 'str')
641        if sharesnapshot is not None:
642            query_parameters['sharesnapshot'] = self._serialize.query("sharesnapshot", sharesnapshot, 'str')
643        query_parameters['comp'] = self._serialize.query("comp", comp, 'str')
644
645        # Construct headers
646        header_parameters = {}
647        header_parameters['x-ms-handle-id'] = self._serialize.header("handle_id", handle_id, 'str')
648        if recursive is not None:
649            header_parameters['x-ms-recursive'] = self._serialize.header("recursive", recursive, 'bool')
650        header_parameters['x-ms-version'] = self._serialize.header("self._config.version", self._config.version, 'str')
651
652        # Construct and send request
653        request = self._client.put(url, query_parameters, header_parameters)
654        pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs)
655        response = pipeline_response.http_response
656
657        if response.status_code not in [200]:
658            map_error(status_code=response.status_code, response=response, error_map=error_map)
659            raise models.StorageErrorException(response, self._deserialize)
660
661        if cls:
662            response_headers = {
663                'x-ms-request-id': self._deserialize('str', response.headers.get('x-ms-request-id')),
664                'x-ms-version': self._deserialize('str', response.headers.get('x-ms-version')),
665                'Date': self._deserialize('rfc-1123', response.headers.get('Date')),
666                'x-ms-marker': self._deserialize('str', response.headers.get('x-ms-marker')),
667                'x-ms-number-of-handles-closed': self._deserialize('int', response.headers.get('x-ms-number-of-handles-closed')),
668                'x-ms-error-code': self._deserialize('str', response.headers.get('x-ms-error-code')),
669            }
670            return cls(response, None, response_headers)
671    force_close_handles.metadata = {'url': '/{shareName}/{directory}'}
672