Skip to content

Commit

Permalink
Format all following lint rules
Browse files Browse the repository at this point in the history
Signed-off-by: Harry <quanghai.ng1512@gmail.com>
  • Loading branch information
sudohainguyen committed May 15, 2024
1 parent c450436 commit 66e3713
Show file tree
Hide file tree
Showing 22 changed files with 1,552 additions and 1,062 deletions.
24 changes: 12 additions & 12 deletions python/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,39 @@
python generate.py
"""

import shutil
import subprocess
import sys
from os import path
from urllib.request import urlopen
import subprocess

here = path.abspath(path.dirname(__file__))

PACKAGE = 'TCLIService'
GENERATED = 'gen-py'
PACKAGE = "TCLIService"
GENERATED = "gen-py"

HIVE_SERVER2_URL = \
'https://raw.githubusercontent.com/apache/hive/branch-2.3/service-rpc/if/TCLIService.thrift'
HIVE_SERVER2_URL = "https://raw.githubusercontent.com/apache/hive/branch-2.3/service-rpc/if/TCLIService.thrift"


def save_url(url):
data = urlopen(url).read()
file_path = path.join(here, url.rsplit('/', 1)[-1])
with open(file_path, 'wb') as f:
file_path = path.join(here, url.rsplit("/", 1)[-1])
with open(file_path, "wb") as f:
f.write(data)


def main(hive_server2_url):
save_url(hive_server2_url)
hive_server2_path = path.join(here, hive_server2_url.rsplit('/', 1)[-1])
hive_server2_path = path.join(here, hive_server2_url.rsplit("/", 1)[-1])

subprocess.call(['thrift', '-r', '--gen', 'py', hive_server2_path])
shutil.move(path.join(here, PACKAGE), path.join(here, PACKAGE + '.old'))
subprocess.call(["thrift", "-r", "--gen", "py", hive_server2_path])
shutil.move(path.join(here, PACKAGE), path.join(here, PACKAGE + ".old"))
shutil.move(path.join(here, GENERATED, PACKAGE), path.join(here, PACKAGE))
shutil.rmtree(path.join(here, PACKAGE + '.old'))
shutil.rmtree(path.join(here, PACKAGE + ".old"))


if __name__ == '__main__':
if __name__ == "__main__":
if len(sys.argv) > 1:
url = sys.argv[1]
else:
Expand Down
6 changes: 3 additions & 3 deletions python/pyhive/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
__version__ = '0.7.0'
from __future__ import absolute_import, unicode_literals

__version__ = "0.7.0"
34 changes: 19 additions & 15 deletions python/pyhive/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
Many docstrings in this file are based on PEP-249, which is in the public domain.
"""

from __future__ import absolute_import
from __future__ import unicode_literals
from builtins import bytes
from builtins import int
from builtins import object
from builtins import str
from past.builtins import basestring
from pyhive import exc
from __future__ import absolute_import, unicode_literals

import abc
import collections
import time
import datetime
from future.utils import with_metaclass
import time
from builtins import bytes, int, object, str
from itertools import islice

from future.utils import with_metaclass
from past.builtins import basestring

from pyhive import exc

try:
from collections.abc import Iterable
except ImportError:
Expand Down Expand Up @@ -108,7 +107,9 @@ def fetchone(self):
raise exc.ProgrammingError("No query yet")

# Sleep until we're done or we have some data to return
self._fetch_while(lambda: not self._data and self._state != self._STATE_FINISHED)
self._fetch_while(
lambda: not self._data and self._state != self._STATE_FINISHED
)

if not self._data:
return None
Expand Down Expand Up @@ -217,7 +218,9 @@ def escape_args(self, parameters):
elif isinstance(parameters, (list, tuple)):
return tuple(self.escape_item(x) for x in parameters)
else:
raise exc.ProgrammingError("Unsupported param format: {}".format(parameters))
raise exc.ProgrammingError(
"Unsupported param format: {}".format(parameters)
)

def escape_number(self, item):
return item
Expand All @@ -228,15 +231,15 @@ def escape_string(self, item):
# as byte strings. The old version always encodes Unicode as byte strings, which breaks
# string formatting here.
if isinstance(item, bytes):
item = item.decode('utf-8')
item = item.decode("utf-8")
# This is good enough when backslashes are literal, newlines are just followed, and the way
# to escape a single quote is to put two single quotes.
# (i.e. only special character is single quote)
return "'{}'".format(item.replace("'", "''"))

def escape_sequence(self, item):
l = map(str, map(self.escape_item, item))
return '(' + ','.join(l) + ')'
return "(" + ",".join(l) + ")"

def escape_datetime(self, item, format, cutoff=0):
dt_str = item.strftime(format)
Expand All @@ -245,7 +248,7 @@ def escape_datetime(self, item, format, cutoff=0):

def escape_item(self, item):
if item is None:
return 'NULL'
return "NULL"
elif isinstance(item, (int, float)):
return self.escape_number(item)
elif isinstance(item, basestring):
Expand All @@ -262,5 +265,6 @@ def escape_item(self, item):

class UniversalSet(object):
"""set containing everything"""

def __contains__(self, item):
return True
24 changes: 20 additions & 4 deletions python/pyhive/exc.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
"""
Package private common utilities. Do not use directly.
"""
from __future__ import absolute_import
from __future__ import unicode_literals

from __future__ import absolute_import, unicode_literals

__all__ = [
'Error', 'Warning', 'InterfaceError', 'DatabaseError', 'InternalError', 'OperationalError',
'ProgrammingError', 'DataError', 'NotSupportedError',
"Error",
"Warning",
"InterfaceError",
"DatabaseError",
"InternalError",
"OperationalError",
"ProgrammingError",
"DataError",
"NotSupportedError",
]


Expand All @@ -15,29 +22,34 @@ class Error(Exception):
You can use this to catch all errors with one single except statement.
"""

pass


class Warning(Exception):
"""Exception raised for important warnings like data truncations while inserting, etc."""

pass


class InterfaceError(Error):
"""Exception raised for errors that are related to the database interface rather than the
database itself.
"""

pass


class DatabaseError(Error):
"""Exception raised for errors that are related to the database."""

pass


class InternalError(DatabaseError):
"""Exception raised when the database encounters an internal error, e.g. the cursor is not valid
anymore, the transaction is out of sync, etc."""

pass


Expand All @@ -47,20 +59,23 @@ class OperationalError(DatabaseError):
is not found, a transaction could not be processed, a memory allocation error occurred during
processing, etc.
"""

pass


class ProgrammingError(DatabaseError):
"""Exception raised for programming errors, e.g. table not found or already exists, syntax error
in the SQL statement, wrong number of parameters specified, etc.
"""

pass


class DataError(DatabaseError):
"""Exception raised for errors that are due to problems with the processed data like division by
zero, numeric value out of range, etc.
"""

pass


Expand All @@ -69,4 +84,5 @@ class NotSupportedError(DatabaseError):
database, e.g. requesting a ``.rollback()`` on a connection that does not support transaction or
has transactions turned off.
"""

pass

0 comments on commit 66e3713

Please sign in to comment.