From 9e207a965305fc48c108081c55ae09a8716efdcb Mon Sep 17 00:00:00 2001 From: "Bala.FA" Date: Sat, 11 Apr 2020 00:50:07 +0530 Subject: [PATCH 1/2] fix formatting as per pep8 in parsers.py --- minio/parsers.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/minio/parsers.py b/minio/parsers.py index a6e5d90df..51e83bca1 100644 --- a/minio/parsers.py +++ b/minio/parsers.py @@ -42,7 +42,7 @@ from .xml_marshal import (NOTIFICATIONS_ARN_FIELDNAME_MAP) -_S3_NS = {'s3' : 'http://s3.amazonaws.com/doc/2006-03-01/'} +_S3_NS = {'s3': 'http://s3.amazonaws.com/doc/2006-03-01/'} class S3Element(object): @@ -51,6 +51,7 @@ class S3Element(object): functions. """ + def __init__(self, root_name, element): self.root_name = root_name self.element = element @@ -163,6 +164,7 @@ def parse_multipart_upload_result(data): root.get_etag_elem() ) + def parse_copy_object(bucket_name, object_name, data): """ Parser for copy object response. @@ -178,6 +180,7 @@ def parse_copy_object(bucket_name, object_name, data): root.get_localized_time_elem('LastModified') ) + def parse_list_buckets(data): """ Parser for list buckets response. @@ -194,6 +197,7 @@ def parse_list_buckets(data): for bucket in buckets.findall('Bucket') ] + def _parse_objects_from_xml_elts(bucket_name, contents, common_prefixes): """Internal function that extracts objects and common prefixes from list_objects responses. @@ -217,6 +221,7 @@ def _parse_objects_from_xml_elts(bucket_name, contents, common_prefixes): return objects, object_dirs + def parse_list_objects(data, bucket_name): """ Parser for list objects response. @@ -270,6 +275,7 @@ def parse_list_objects_v2(data, bucket_name): return objects + object_dirs, is_truncated, continuation_token + def parse_list_multipart_uploads(data, bucket_name): """ Parser for list multipart uploads response. @@ -328,6 +334,7 @@ def parse_list_parts(data, bucket_name, object_name, upload_id): return parts, is_truncated, part_marker + def parse_new_multipart_upload(data): """ Parser for new multipart upload response. @@ -338,6 +345,7 @@ def parse_new_multipart_upload(data): root = S3Element.fromstring('InitiateMultipartUploadResult', data) return root.get_child_text('UploadId') + def parse_location_constraint(data): """ Parser for location constraint response. @@ -348,6 +356,7 @@ def parse_location_constraint(data): root = S3Element.fromstring('BucketLocationConstraintResult', data) return root.text() + def _iso8601_to_localized_time(date_string): """ Convert iso8601 date string into UTC time. @@ -366,6 +375,7 @@ def _iso8601_to_localized_time(date_string): localized_time = pytz.utc.localize(parsed_date) return localized_time + def parse_get_bucket_notification(data): """ Parser for a get_bucket_notification response from S3. @@ -390,6 +400,7 @@ def parse_get_bucket_notification(data): return notifications + def _parse_add_notifying_service_config(data, notifications, service_key, service_xml_tag): @@ -411,7 +422,7 @@ def _parse_add_notifying_service_config(data, notifications, service_key, 'Value': xml_filter_rule.get_child_text('Value'), } for xml_filter_rule in xml_filter_rules.findall( - './S3Key/FilterRule') + './S3Key/FilterRule') ] } } @@ -426,6 +437,7 @@ def _parse_add_notifying_service_config(data, notifications, service_key, return notifications + def parse_multi_object_delete_response(data): """Parser for Multi-Object Delete API response. From 278e1ef4ec102514ca74f0b3be5993ee6c2c4e60 Mon Sep 17 00:00:00 2001 From: "Bala.FA" Date: Sat, 11 Apr 2020 01:14:24 +0530 Subject: [PATCH 2/2] remove unused imports and use pythonic approach. --- minio/parsers.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/minio/parsers.py b/minio/parsers.py index 51e83bca1..c30519bb4 100644 --- a/minio/parsers.py +++ b/minio/parsers.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,8 +27,6 @@ # standard. from xml.etree import ElementTree -from xml.etree.ElementTree import ParseError - from datetime import datetime # dependencies. @@ -87,7 +86,7 @@ def find(self, name): """ elt = self.element.find('s3:{}'.format(name), _S3_NS) - return S3Element(self.root_name, elt) if elt is not None else None + return S3Element(self.root_name, elt) if elt else None def get_child_text(self, name, strict=True): """Extract text of a child element. If strict, and child element is @@ -213,8 +212,7 @@ def _parse_objects_from_xml_elts(bucket_name, contents, common_prefixes): ] object_dirs = [ - Object(bucket_name, dir_elt.text(), None, '', - 0, is_dir=True) + Object(bucket_name, dir_elt.text(), None, '', 0, is_dir=True) for dirs_elt in common_prefixes for dir_elt in dirs_elt.findall('Prefix') ]