Skip to content

Commit

Permalink
fix formatting as per pep8 in minio.select
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana committed Apr 9, 2020
1 parent aa0a079 commit 405e456
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 2 additions & 0 deletions minio/select/errors.py
Expand Up @@ -25,11 +25,13 @@
"""


class SelectMessageError(Exception):
'''
Raised in case of message type 'error'
'''


class SelectCRCValidationError(Exception):
'''
Raised in case of CRC mismatch
Expand Down
7 changes: 5 additions & 2 deletions minio/select/helpers.py
Expand Up @@ -32,18 +32,20 @@
EVENT_RECORDS = 'Records' # Event Type is Records
EVENT_PROGRESS = 'Progress' # Event Type Progress
EVENT_STATS = 'Stats' # Event Type Stats
EVENT_CONT = 'Cont' # Event Type continue
EVENT_CONT = 'Cont' # Event Type continue
EVENT_END = 'End' # Event Type is End
EVENT_CONTENT_TYPE = "text/xml" # Event content xml type
EVENT_CONTENT_TYPE = "text/xml" # Event content xml type
EVENT = 'event' # Message Type is event
ERROR = 'error' # Message Type is error


def calculate_crc(value):
'''
Returns the CRC using crc32
'''
return crc32(value) & 0xffffffff


def validate_crc(current_value, expected_value):
'''
Validate through CRC check
Expand All @@ -54,6 +56,7 @@ def validate_crc(current_value, expected_value):
return True
return False


def byte_int(data_bytes):
'''
Convert bytes to big-endian integer
Expand Down
9 changes: 9 additions & 0 deletions minio/select/options.py
Expand Up @@ -27,10 +27,12 @@

from .helpers import (SQL)


class CSVInput:
"""
CSVInput: Input Format as CSV.
"""

def __init__(self, FileHeaderInfo=None, RecordDelimiter="\n",
FieldDelimiter=",", QuoteCharacter='"',
QuoteEscapeCharacter='"', Comments="#",
Expand All @@ -43,10 +45,12 @@ def __init__(self, FileHeaderInfo=None, RecordDelimiter="\n",
self.Comments = Comments
self.AllowQuotedRecordDelimiter = AllowQuotedRecordDelimiter


class JSONInput:
"""
JSONInput: Input format as JSON.
"""

def __init__(self, Type=None):
self.Type = Type

Expand All @@ -61,6 +65,7 @@ class InputSerialization:
"""
InputSerialization: nput Format.
"""

def __init__(self, compression_type="NONE", csv=None, json=None, par=None):
self.compression_type = compression_type
self.csv_input = csv
Expand All @@ -73,6 +78,7 @@ class CSVOutput:
CSVOutput: Output as CSV.
"""

def __init__(self, QuoteFields="ASNEEDED", RecordDelimiter="\n",
FieldDelimiter=",", QuoteCharacter='"',
QuoteEscapeCharacter='"'):
Expand All @@ -87,6 +93,7 @@ class JsonOutput:
"""
JsonOutput- Output as JSON.
"""

def __init__(self, RecordDelimiter="\n"):
self.RecordDelimiter = RecordDelimiter

Expand All @@ -95,6 +102,7 @@ class OutputSerialization:
"""
OutputSerialization: Output Format.
"""

def __init__(self, csv=None, json=None):
self.csv_output = csv
self.json_output = json
Expand All @@ -104,6 +112,7 @@ class RequestProgress:
"""
RequestProgress: Sends progress message.
"""

def __init__(self, enabled=False):
self.enabled = enabled

Expand Down
14 changes: 10 additions & 4 deletions minio/select/reader.py
Expand Up @@ -42,6 +42,7 @@
from .helpers import (validate_crc, calculate_crc, byte_int)
from .errors import (SelectMessageError, SelectCRCValidationError)


def _extract_header(header_bytes):
"""
populates the header map after reading the header in bytes
Expand All @@ -51,7 +52,8 @@ def _extract_header(header_bytes):
# While loop ends when all the headers present are read
# header contains multipe headers
while header_byte_parsed < len(header_bytes):
header_name_byte_length = byte_int(header_bytes[header_byte_parsed:header_byte_parsed+1])
header_name_byte_length = byte_int(
header_bytes[header_byte_parsed:header_byte_parsed+1])
header_byte_parsed += 1
header_name = \
header_bytes[header_byte_parsed:
Expand All @@ -71,6 +73,7 @@ def _extract_header(header_bytes):
header_value.decode("utf-8").lstrip(":")
return header_map


def _parse_stats(stats):
"""
Parses stats XML and populates the stat dict.
Expand All @@ -86,12 +89,14 @@ def _parse_stats(stats):

return stat


class SelectObjectReader(object):
"""
SelectObjectReader returns a Reader that upon read
returns queried data, but stops when the response ends.
LimitedRandomReader is compatible with BufferedIOBase.
"""

def __init__(self, response):
self.response = response
self.remaining_bytes = bytes()
Expand Down Expand Up @@ -147,7 +152,7 @@ def __extract_message(self):
header_bytes = self.response.read(header_len)
if len(header_bytes) == 0:
raise SelectMessageError(
"Premature truncation of select message header"+
"Premature truncation of select message header" +
", server is sending corrupt message?")

crc_bytes.write(header_bytes)
Expand All @@ -158,7 +163,7 @@ def __extract_message(self):
event_type = header_map["event-type"]
if header_map["message-type"] == ERROR:
raise SelectMessageError(
header_map["error-code"] + ":\"" + \
header_map["error-code"] + ":\"" +
header_map["error-message"] + "\"")
elif header_map["message-type"] == EVENT:
if event_type == EVENT_END:
Expand All @@ -178,7 +183,8 @@ def __extract_message(self):
payload_bytes = self.response.read(payload_length)
else:
raise SelectMessageError(
"Unrecognized message-type {0}".format(header_map["message-type"])
"Unrecognized message-type {0}".format(
header_map["message-type"])
)

crc_bytes.write(payload_bytes)
Expand Down

0 comments on commit 405e456

Please sign in to comment.