This is an automated email from the ASF dual-hosted git repository.
smiklosovic pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new 27ab63f remove unused imports in cqlsh.py and cqlshlib
27ab63f is described below
commit 27ab63f00501a6afda94e760efab8af3e90c598b
Author: Brad Schoening <[email protected]>
AuthorDate: Fri Mar 4 12:02:25 2022 +0100
remove unused imports in cqlsh.py and cqlshlib
patch by Brad Schoening; reviewed by Stefan Miklosovic and Brandon Williams
for CASSANDRA-17413
---
CHANGES.txt | 1 +
bin/cqlsh.py | 13 +++++--------
pylib/cqlshlib/copyutil.py | 5 +++--
pylib/cqlshlib/cqlhandling.py | 6 ------
pylib/cqlshlib/displaying.py | 2 --
pylib/cqlshlib/formatting.py | 3 ---
pylib/cqlshlib/test/__init__.py | 2 --
pylib/cqlshlib/test/ansi_colors.py | 9 ++++++---
pylib/cqlshlib/test/cassconnect.py | 3 ++-
pylib/cqlshlib/test/run_cqlsh.py | 19 +++++++++++++------
pylib/cqlshlib/test/test_copyutil.py | 13 ++++++-------
pylib/cqlshlib/test/test_cql_parsing.py | 8 ++++----
pylib/cqlshlib/test/test_cqlsh_completion.py | 6 +++---
pylib/cqlshlib/test/test_cqlsh_output.py | 2 --
pylib/cqlshlib/test/test_unicode.py | 5 +----
pylib/cqlshlib/test/winpty.py | 2 +-
pylib/cqlshlib/tracing.py | 1 -
17 files changed, 45 insertions(+), 55 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index e6368eb..2beaa5c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
4.1
+ * remove unused imports in cqlsh.py and cqlshlib (CASSANDRA-17413)
* deprecate property windows_timer_interval (CASSANDRA-17404)
* Expose streaming as a vtable (CASSANDRA-17390)
* Make startup checks configurable (CASSANDRA-17220)
diff --git a/bin/cqlsh.py b/bin/cqlsh.py
index dd3c705..dad28f1 100755
--- a/bin/cqlsh.py
+++ b/bin/cqlsh.py
@@ -16,8 +16,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import division, unicode_literals, print_function
-
import cmd
import codecs
import csv
@@ -37,7 +35,7 @@ from contextlib import contextmanager
from glob import glob
from uuid import UUID
-if sys.version_info < (3, 6) and sys.version_info[0:2] != (2, 7):
+if sys.version_info < (3, 6):
sys.exit("\ncqlsh requires Python 3.6+\n")
# see CASSANDRA-10428
@@ -140,8 +138,7 @@ from cassandra.auth import PlainTextAuthProvider
from cassandra.cluster import Cluster
from cassandra.cqltypes import cql_typename
from cassandra.marshal import int64_unpack
-from cassandra.metadata import (ColumnMetadata, KeyspaceMetadata,
- TableMetadata, protect_name, protect_names)
+from cassandra.metadata import (ColumnMetadata, KeyspaceMetadata,
TableMetadata)
from cassandra.policies import WhiteListRoundRobinPolicy
from cassandra.query import SimpleStatement, ordered_dict_factory,
TraceUnavailable
from cassandra.util import datetime_from_timestamp
@@ -152,15 +149,15 @@ cqlshlibdir = os.path.join(CASSANDRA_PATH, 'pylib')
if os.path.isdir(cqlshlibdir):
sys.path.insert(0, cqlshlibdir)
-from cqlshlib import cql3handling, cqlhandling, pylexotron, sslhandling,
cqlshhandling
+from cqlshlib import cql3handling, pylexotron, sslhandling, cqlshhandling
from cqlshlib.copyutil import ExportTask, ImportTask
from cqlshlib.displaying import (ANSI_RESET, BLUE, COLUMN_NAME_COLORS, CYAN,
RED, WHITE, FormattedValue, colorme)
from cqlshlib.formatting import (DEFAULT_DATE_FORMAT, DEFAULT_NANOTIME_FORMAT,
DEFAULT_TIMESTAMP_FORMAT, CqlType,
DateTimeFormat,
- format_by_type, formatter_for)
+ format_by_type)
from cqlshlib.tracing import print_trace, print_trace_session
-from cqlshlib.util import get_file_encoding_bomsize, trim_if_present
+from cqlshlib.util import get_file_encoding_bomsize
DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 9042
diff --git a/pylib/cqlshlib/copyutil.py b/pylib/cqlshlib/copyutil.py
index 9ecb6ae..b87340b 100644
--- a/pylib/cqlshlib/copyutil.py
+++ b/pylib/cqlshlib/copyutil.py
@@ -16,7 +16,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import unicode_literals
import csv
import datetime
import json
@@ -33,6 +32,7 @@ import sys
import threading
import time
import traceback
+import errno
from bisect import bisect_right
from calendar import timegm
@@ -51,7 +51,7 @@ from six.moves.queue import Queue
from cassandra import OperationTimedOut
from cassandra.cluster import Cluster, DefaultConnection
-from cassandra.cqltypes import ReversedType, UserType, BytesType, VarcharType
+from cassandra.cqltypes import ReversedType, UserType, VarcharType
from cassandra.metadata import protect_name, protect_names, protect_value
from cassandra.policies import RetryPolicy, WhiteListRoundRobinPolicy,
DCAwareRoundRobinPolicy, FallthroughRetryPolicy
from cassandra.query import BatchStatement, BatchType, SimpleStatement,
tuple_factory
@@ -201,6 +201,7 @@ class ReceivingChannels(object):
try:
readable, _, _ = select(self._readers, [], [], timeout)
except select.error as exc:
+ # TODO: PEP 475 in Python 3.5 should make this unnecessary
# Do not abort on window resize:
if exc[0] != errno.EINTR:
raise
diff --git a/pylib/cqlshlib/cqlhandling.py b/pylib/cqlshlib/cqlhandling.py
index 3da0ab1..0fd73c1 100644
--- a/pylib/cqlshlib/cqlhandling.py
+++ b/pylib/cqlshlib/cqlhandling.py
@@ -111,12 +111,6 @@ class CqlParsingRuleSet(pylexotron.ParsingRuleSet):
# don't put any 'endline' tokens in output
continue
- # Convert all unicode tokens to ascii, where possible. This
- # helps avoid problems with performing unicode-incompatible
- # operations on tokens (like .lower()). See CASSANDRA-9083
- # for one example of this.
- str_token = t[1]
-
curstmt.append(t)
if t[0] == 'endtoken':
term_on_nl = False
diff --git a/pylib/cqlshlib/displaying.py b/pylib/cqlshlib/displaying.py
index ef076f7..7109f11 100644
--- a/pylib/cqlshlib/displaying.py
+++ b/pylib/cqlshlib/displaying.py
@@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import unicode_literals
-
from collections import defaultdict
RED = '\033[0;1;31m'
diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py
index 56e7783..b82486a 100644
--- a/pylib/cqlshlib/formatting.py
+++ b/pylib/cqlshlib/formatting.py
@@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import unicode_literals
-
import binascii
import calendar
import datetime
@@ -23,7 +21,6 @@ import math
import os
import re
import sys
-import platform
from six import ensure_text
diff --git a/pylib/cqlshlib/test/__init__.py b/pylib/cqlshlib/test/__init__.py
index 4bb037e..635f0d9 100644
--- a/pylib/cqlshlib/test/__init__.py
+++ b/pylib/cqlshlib/test/__init__.py
@@ -13,5 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
-from .cassconnect import create_db, remove_db
diff --git a/pylib/cqlshlib/test/ansi_colors.py
b/pylib/cqlshlib/test/ansi_colors.py
index 9fc3411..2bdc736 100644
--- a/pylib/cqlshlib/test/ansi_colors.py
+++ b/pylib/cqlshlib/test/ansi_colors.py
@@ -14,8 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import unicode_literals
-
import re
import six
@@ -65,6 +63,7 @@ for colordef in color_defs:
for c in nameset:
colors_by_name[c] = colorcode
+
class ColoredChar(object):
def __init__(self, c, colorcode):
self.c = c
@@ -104,6 +103,7 @@ class ColoredChar(object):
def colortag(self):
return lookup_letter_from_code(self._colorcode)
+
class ColoredText(object):
def __init__(self, source=''):
if isinstance(source, six.text_type):
@@ -152,7 +152,6 @@ class ColoredText(object):
@staticmethod
def parse_sgr_param(curclr, paramstr):
- oldclr = curclr
args = list(map(int, paramstr.split(';')))
for a in args:
if a == 0:
@@ -179,15 +178,19 @@ class ColoredText(object):
def colortags(self):
return ''.join([c.colortag() for c in self.chars])
+
def lookup_colorcode(name):
return colors_by_name[name]
+
def lookup_colorname(code):
return colors_by_num.get(code, 'Unknown-color-0%o' % code)
+
def lookup_colorletter(letter):
return colors_by_letter[letter]
+
def lookup_letter_from_code(code):
letr = letters_by_num.get(code, ' ')
if letr == 'n':
diff --git a/pylib/cqlshlib/test/cassconnect.py
b/pylib/cqlshlib/test/cassconnect.py
index b245f69..0118e07 100644
--- a/pylib/cqlshlib/test/cassconnect.py
+++ b/pylib/cqlshlib/test/cassconnect.py
@@ -157,7 +157,8 @@ def cql_rule_set():
return CqlRuleSet
-class DEFAULTVAL: pass
+class DEFAULTVAL:
+ pass
__TEST__ = False
diff --git a/pylib/cqlshlib/test/run_cqlsh.py b/pylib/cqlshlib/test/run_cqlsh.py
index ed01034..9adb854 100644
--- a/pylib/cqlshlib/test/run_cqlsh.py
+++ b/pylib/cqlshlib/test/run_cqlsh.py
@@ -16,18 +16,15 @@
# NOTE: this testing tool is *nix specific
-from __future__ import unicode_literals
-
import os
import sys
import re
import contextlib
import subprocess
import signal
-import math
from time import time
from . import basecase
-from os.path import join, normpath
+from os.path import join
import pty
@@ -42,6 +39,7 @@ except AttributeError:
# Python 3.7+
Pattern = re.Pattern
+
def get_smm_sequence(term='xterm'):
"""
Return the set meta mode (smm) sequence, if any.
@@ -57,10 +55,12 @@ def get_smm_sequence(term='xterm'):
result = result.decode("utf-8")
return result
+
DEFAULT_SMM_SEQUENCE = get_smm_sequence()
cqlshlog = basecase.cqlshlog
+
def set_controlling_pty(master, slave):
os.setsid()
os.close(master)
@@ -70,6 +70,7 @@ def set_controlling_pty(master, slave):
os.close(slave)
os.close(os.open(os.ttyname(1), os.O_RDWR))
+
@contextlib.contextmanager
def raising_signal(signum, exc):
"""
@@ -85,9 +86,11 @@ def raising_signal(signum, exc):
finally:
signal.signal(signum, oldhandlr)
+
class TimeoutError(Exception):
pass
+
@contextlib.contextmanager
def timing_out(seconds):
if seconds is None:
@@ -107,6 +110,7 @@ def timing_out(seconds):
def noop(*a):
pass
+
class ProcRunner:
def __init__(self, path, tty=True, env=None, args=()):
self.exe_path = path
@@ -222,6 +226,7 @@ class ProcRunner:
curtime = time()
return got
+
class CqlshRunner(ProcRunner):
def __init__(self, path=None, host=None, port=None, keyspace=None,
cqlver=None,
args=(), prompt=DEFAULT_CQLSH_PROMPT, env=None, tty=True,
**kwargs):
@@ -256,7 +261,7 @@ class CqlshRunner(ProcRunner):
self.output_header = self.read_to_next_prompt()
def read_to_next_prompt(self, timeout=10.0):
- return self.read_until(self.prompt, timeout=timeout, ptty_timeout=3,
replace=[DEFAULT_SMM_SEQUENCE,])
+ return self.read_until(self.prompt, timeout=timeout, ptty_timeout=3,
replace=[DEFAULT_SMM_SEQUENCE])
def read_up_to_timeout(self, timeout, blksize=4096):
output = ProcRunner.read_up_to_timeout(self, timeout, blksize=blksize)
@@ -281,12 +286,14 @@ class CqlshRunner(ProcRunner):
promptline = output
output = ''
assert re.match(self.prompt, DEFAULT_PREFIX + promptline), \
- 'last line of output %r does not match %r?' % (promptline,
self.prompt)
+ 'last line of output %r does not match %r?' % (promptline,
self.prompt)
return output + '\n'
+
def run_cqlsh(**kwargs):
return contextlib.closing(CqlshRunner(**kwargs))
+
def call_cqlsh(**kwargs):
kwargs.setdefault('prompt', None)
proginput = kwargs.pop('input', '')
diff --git a/pylib/cqlshlib/test/test_copyutil.py
b/pylib/cqlshlib/test/test_copyutil.py
index 58c5d17..19fcdd1 100644
--- a/pylib/cqlshlib/test/test_copyutil.py
+++ b/pylib/cqlshlib/test/test_copyutil.py
@@ -20,7 +20,7 @@
import unittest
-from cassandra.metadata import MIN_LONG, Murmur3Token, TokenMap
+from cassandra.metadata import MIN_LONG, Murmur3Token
from cassandra.policies import SimpleConvictionPolicy
from cassandra.pool import Host
from unittest.mock import Mock
@@ -75,7 +75,7 @@ class TestExportTask(CopyTaskTest):
}
# merge override options with standard options
overridden_opts = dict(self.opts)
- for k,v in opts.items():
+ for k, v in opts.items():
overridden_opts[k] = v
export_task = ExportTask(shell, self.ks, self.table, self.columns,
self.fname, overridden_opts, self.protocol_version, self.config_file)
assert export_task.get_ranges() == expected_ranges
@@ -93,19 +93,19 @@ class TestExportTask(CopyTaskTest):
self._test_get_ranges_murmur3_base({'begintoken': 1, 'endtoken': -1},
{})
# simple case of a single range
- expected_ranges = {(1,2): {'hosts': ('10.0.0.4', '10.0.0.1',
'10.0.0.2'), 'attempts': 0, 'rows': 0, 'workerno': -1}}
+ expected_ranges = {(1, 2): {'hosts': ('10.0.0.4', '10.0.0.1',
'10.0.0.2'), 'attempts': 0, 'rows': 0, 'workerno': -1}}
self._test_get_ranges_murmur3_base({'begintoken': 1, 'endtoken': 2},
expected_ranges)
# simple case of two contiguous ranges
expected_ranges = {
- (-4611686018427387903,0): {'hosts': ('10.0.0.3', '10.0.0.4',
'10.0.0.1'), 'attempts': 0, 'rows': 0, 'workerno': -1},
- (0,1): {'hosts': ('10.0.0.4', '10.0.0.1', '10.0.0.2'), 'attempts':
0, 'rows': 0, 'workerno': -1}
+ (-4611686018427387903, 0): {'hosts': ('10.0.0.3', '10.0.0.4',
'10.0.0.1'), 'attempts': 0, 'rows': 0, 'workerno': -1},
+ (0, 1): {'hosts': ('10.0.0.4', '10.0.0.1', '10.0.0.2'),
'attempts': 0, 'rows': 0, 'workerno': -1}
}
self._test_get_ranges_murmur3_base({'begintoken':
-4611686018427387903, 'endtoken': 1}, expected_ranges)
# specify a begintoken only (endtoken defaults to None)
expected_ranges = {
- (4611686018427387905,None): {'hosts': ('10.0.0.1', '10.0.0.2',
'10.0.0.3'), 'attempts': 0, 'rows': 0, 'workerno': -1}
+ (4611686018427387905, None): {'hosts': ('10.0.0.1', '10.0.0.2',
'10.0.0.3'), 'attempts': 0, 'rows': 0, 'workerno': -1}
}
self._test_get_ranges_murmur3_base({'begintoken':
4611686018427387905}, expected_ranges)
@@ -114,4 +114,3 @@ class TestExportTask(CopyTaskTest):
(None, MIN_LONG + 1): {'hosts': ('10.0.0.2', '10.0.0.3',
'10.0.0.4'), 'attempts': 0, 'rows': 0, 'workerno': -1}
}
self._test_get_ranges_murmur3_base({'endtoken': MIN_LONG + 1},
expected_ranges)
-
diff --git a/pylib/cqlshlib/test/test_cql_parsing.py
b/pylib/cqlshlib/test/test_cql_parsing.py
index 8631d7a..b1f45f5 100644
--- a/pylib/cqlshlib/test/test_cql_parsing.py
+++ b/pylib/cqlshlib/test/test_cql_parsing.py
@@ -778,12 +778,12 @@ class TestCqlParsing(TestCase):
def parse_cqlsh_statements(text):
- '''
+ """
Runs its argument through the sequence of parsing steps that cqlsh takes
its
input through.
Currently does not handle batch statements.
- '''
+ """
# based on onecmd
statements, _ = CqlRuleSet.cql_split_statements(text)
# stops here. For regular cql commands, onecmd just splits it and sends it
@@ -799,13 +799,13 @@ def tokens_with_types(lexed):
def strip_final_empty_items(xs):
- '''
+ """
Returns its a copy of argument as a list, but with any terminating
subsequence of falsey values removed.
>>> strip_final_empty_items([[3, 4], [5, 6, 7], [], [], [1], []])
[[3, 4], [5, 6, 7], [], [], [1]]
- '''
+ """
rv = list(xs)
while rv and not rv[-1]:
diff --git a/pylib/cqlshlib/test/test_cqlsh_completion.py
b/pylib/cqlshlib/test/test_cqlsh_completion.py
index 8bba22c..011a548 100644
--- a/pylib/cqlshlib/test/test_cqlsh_completion.py
+++ b/pylib/cqlshlib/test/test_cqlsh_completion.py
@@ -38,6 +38,7 @@ COMPLETION_RESPONSE_TIME = 0.5
completion_separation_re = re.compile(r'\s+')
+
class CqlshCompletionCase(BaseTestCase):
@classmethod
@@ -52,7 +53,7 @@ class CqlshCompletionCase(BaseTestCase):
env = os.environ.copy()
env['COLUMNS'] = '100000'
if (locale.getpreferredencoding() != 'UTF-8'):
- env['LC_CTYPE'] = 'en_US.utf8'
+ env['LC_CTYPE'] = 'en_US.utf8'
self.cqlsh_runner = testrun_cqlsh(cqlver=None, env=env)
self.cqlsh = self.cqlsh_runner.__enter__()
@@ -150,7 +151,6 @@ class CqlshCompletionCase(BaseTestCase):
# retry once
self.cqlsh.send(CTRL_C)
self.cqlsh.read_to_next_prompt(timeout=10.0)
-
def strategies(self):
return CqlRuleSet.replication_strategies
@@ -680,7 +680,7 @@ class TestCqlshCompletion(CqlshCompletionCase):
'timestamp_resolution', 'min_threshold',
'class', 'max_threshold',
'tombstone_compaction_interval',
'tombstone_threshold',
'enabled',
'unchecked_tombstone_compaction',
-
'only_purge_repaired_tombstones','provide_overlapping_tombstones'])
+ 'only_purge_repaired_tombstones',
'provide_overlapping_tombstones'])
def test_complete_in_create_columnfamily(self):
self.trycompletions('CREATE C', choices=['COLUMNFAMILY', 'CUSTOM'])
diff --git a/pylib/cqlshlib/test/test_cqlsh_output.py
b/pylib/cqlshlib/test/test_cqlsh_output.py
index eb8edea..14c2b25 100644
--- a/pylib/cqlshlib/test/test_cqlsh_output.py
+++ b/pylib/cqlshlib/test/test_cqlsh_output.py
@@ -17,8 +17,6 @@
# to configure behavior, define $CQL_TEST_HOST to the destination address
# and $CQL_TEST_PORT to the associated port.
-from __future__ import unicode_literals, with_statement
-
import locale
import os
import re
diff --git a/pylib/cqlshlib/test/test_unicode.py
b/pylib/cqlshlib/test/test_unicode.py
index 836c2d9..7ec121e 100644
--- a/pylib/cqlshlib/test/test_unicode.py
+++ b/pylib/cqlshlib/test/test_unicode.py
@@ -15,10 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import unicode_literals, with_statement
-
import os
-import subprocess
from .basecase import BaseTestCase
from .cassconnect import (get_cassandra_connection, create_keyspace,
testrun_cqlsh)
@@ -71,5 +68,5 @@ class TestCqlshUnicode(BaseTestCase):
output = c.cmd_and_response('CREATE TYPE "%s" ( "%s" int );' %
(v1, v2))
output = c.cmd_and_response('DESC TYPES;')
self.assertIn(v1, output)
- output = c.cmd_and_response('DESC TYPE "%s";' %(v1,))
+ output = c.cmd_and_response('DESC TYPE "%s";' % (v1,))
self.assertIn(v2, output)
diff --git a/pylib/cqlshlib/test/winpty.py b/pylib/cqlshlib/test/winpty.py
index f197aa5..9381a2f 100644
--- a/pylib/cqlshlib/test/winpty.py
+++ b/pylib/cqlshlib/test/winpty.py
@@ -47,4 +47,4 @@ class WinPty(object):
count = count + 1
except Empty:
pass
- return buf.getvalue()
\ No newline at end of file
+ return buf.getvalue()
diff --git a/pylib/cqlshlib/tracing.py b/pylib/cqlshlib/tracing.py
index 0f1988a..e068250 100644
--- a/pylib/cqlshlib/tracing.py
+++ b/pylib/cqlshlib/tracing.py
@@ -19,7 +19,6 @@ import time
from cassandra.query import QueryTrace, TraceUnavailable
from cqlshlib.displaying import MAGENTA
-from cqlshlib.formatting import CqlType
def print_trace_session(shell, session, session_id, partial_session=False):
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]