You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2018/01/15 14:07:38 UTC

[04/23] cassandra git commit: More PEP8 compliance for cqlsh

More PEP8 compliance for cqlsh

patch by Michael Kjellman; reviewed by Jay Zhuang for CASSANDRA-14021


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f8d73a3a
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f8d73a3a
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f8d73a3a

Branch: refs/heads/cassandra-3.0
Commit: f8d73a3acb00d807d09aa33e1612c89389b18480
Parents: d4fd82b
Author: Michael Kjellman <kj...@apple.com>
Authored: Tue Nov 14 20:51:37 2017 -0800
Committer: Jason Brown <ja...@gmail.com>
Committed: Mon Jan 15 05:56:44 2018 -0800

----------------------------------------------------------------------
 CHANGES.txt                    |  2 +-
 bin/cqlsh                      |  4 ++++
 pylib/cqlshlib/copyutil.py     |  6 +++---
 pylib/cqlshlib/cql3handling.py | 20 ++++++++++++++++++++
 pylib/cqlshlib/displaying.py   |  1 +
 pylib/cqlshlib/formatting.py   | 13 +++++++++++++
 pylib/cqlshlib/pylexotron.py   |  1 +
 pylib/cqlshlib/wcwidth.py      |  3 +++
 8 files changed, 46 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f8d73a3a/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b4e6f75..6e1ca85 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,5 @@
 2.1.20
- * 
+ * More PEP8 compliance for cqlsh (CASSANDRA-14021)
 
 2.1.19
  * Add storage port options to sstableloader (CASSANDRA-13844)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f8d73a3a/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index 6317ec9..30840db 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -83,6 +83,7 @@ def find_zip(libprefix):
         if zips:
             return max(zips)   # probably the highest version, if multiple
 
+
 cql_zip = find_zip(CQL_LIB_PREFIX)
 if cql_zip:
     ver = os.path.splitext(os.path.basename(cql_zip))[0][len(CQL_LIB_PREFIX):]
@@ -522,6 +523,8 @@ def show_warning_without_quoting_line(message, category, filename, lineno, file=
         file.write(warnings.formatwarning(message, category, filename, lineno, line=''))
     except IOError:
         pass
+
+
 warnings.showwarning = show_warning_without_quoting_line
 warnings.filterwarnings('always', category=cql3handling.UnexpectedTableStructure)
 
@@ -2213,6 +2216,7 @@ def main(options, hostname, port):
     if batch_mode and shell.statement_error:
         sys.exit(2)
 
+
 # always call this regardless of module name: when a sub-process is spawned
 # on Windows then the module name is not __main__, see CASSANDRA-9304
 insert_driver_hooks()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f8d73a3a/pylib/cqlshlib/copyutil.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/copyutil.py b/pylib/cqlshlib/copyutil.py
index 3a45353..85e2678 100644
--- a/pylib/cqlshlib/copyutil.py
+++ b/pylib/cqlshlib/copyutil.py
@@ -191,7 +191,7 @@ class OneWayChannels(object):
         for ch in self.channels:
             try:
                 ch.close()
-            except:
+            except Exception:
                 pass
 
 
@@ -1967,8 +1967,8 @@ class ImportConversion(object):
             pk_values = []
             for i in partition_key_indexes:
                 val = serialize(i, row[i])
-                l = len(val)
-                pk_values.append(struct.pack(">H%dsB" % l, l, val, 0))
+                length = len(val)
+                pk_values.append(struct.pack(">H%dsB" % length, length, val, 0))
             return b"".join(pk_values)
 
         if len(partition_key_indexes) == 1:

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f8d73a3a/pylib/cqlshlib/cql3handling.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py
index 029e0c7..012e383 100644
--- a/pylib/cqlshlib/cql3handling.py
+++ b/pylib/cqlshlib/cql3handling.py
@@ -34,6 +34,7 @@ class UnexpectedTableStructure(UserWarning):
     def __str__(self):
         return 'Unexpected table structure; may not translate correctly to CQL. ' + self.msg
 
+
 SYSTEM_KEYSPACES = ('system', 'system_traces', 'system_auth')
 NONALTERBALE_KEYSPACES = ('system')
 
@@ -109,6 +110,7 @@ class Cql3ParsingRuleSet(CqlParsingRuleSet):
             cqlword = cqlword[1:-1].replace("''", "'")
         return cqlword
 
+
 CqlRuleSet = Cql3ParsingRuleSet()
 
 # convenience for remainder of module
@@ -306,6 +308,7 @@ def prop_equals_completer(ctxt, cass):
             return ()
     return ['=']
 
+
 completer_for('property', 'propeq')(prop_equals_completer)
 
 
@@ -529,6 +532,7 @@ def ks_name_completer(ctxt, cass):
 def cf_ks_name_completer(ctxt, cass):
     return [maybe_escape_name(ks) + '.' for ks in cass.get_keyspace_names()]
 
+
 completer_for('columnFamilyName', 'ksname')(cf_ks_name_completer)
 
 
@@ -538,6 +542,7 @@ def cf_ks_dot_completer(ctxt, cass):
         return ['.']
     return []
 
+
 completer_for('columnFamilyName', 'dot')(cf_ks_dot_completer)
 
 
@@ -554,6 +559,7 @@ def cf_name_completer(ctxt, cass):
         raise
     return map(maybe_escape_name, cfnames)
 
+
 completer_for('userTypeName', 'ksname')(cf_ks_name_completer)
 
 completer_for('userTypeName', 'dot')(cf_ks_dot_completer)
@@ -606,6 +612,7 @@ def working_on_keyspace(ctxt):
         return True
     return False
 
+
 syntax_rules += r'''
 <useStatement> ::= "USE" <keyspaceName>
                  ;
@@ -694,6 +701,7 @@ def select_relation_lhs_completer(ctxt, cass):
 def select_count_star_completer(ctxt, cass):
     return ['*']
 
+
 explain_completion('selector', 'colname')
 
 syntax_rules += r'''
@@ -770,6 +778,7 @@ def insert_option_completer(ctxt, cass):
         opts.discard(opt.split()[0])
     return opts
 
+
 syntax_rules += r'''
 <updateStatement> ::= "UPDATE" cf=<columnFamilyName>
                         ( "USING" [updateopt]=<usingOption>
@@ -863,6 +872,7 @@ def update_indexbracket_completer(ctxt, cass):
         return ['[']
     return []
 
+
 syntax_rules += r'''
 <deleteStatement> ::= "DELETE" ( <deleteSelector> ( "," <deleteSelector> )* )?
                         "FROM" cf=<columnFamilyName>
@@ -890,6 +900,7 @@ def delete_delcol_completer(ctxt, cass):
     layout = get_table_meta(ctxt, cass)
     return map(maybe_escape_name, regular_column_names(layout))
 
+
 syntax_rules += r'''
 <batchStatement> ::= "BEGIN" ( "UNLOGGED" | "COUNTER" )? "BATCH"
                         ( "USING" [batchopt]=<usingOption>
@@ -912,6 +923,7 @@ def batch_opt_completer(ctxt, cass):
         opts.discard(opt.split()[0])
     return opts
 
+
 syntax_rules += r'''
 <truncateStatement> ::= "TRUNCATE" ("COLUMNFAMILY" | "TABLE")? cf=<columnFamilyName>
                       ;
@@ -931,6 +943,7 @@ def create_ks_wat_completer(ctxt, cass):
         return ['KEYSPACE']
     return ['KEYSPACE', 'SCHEMA']
 
+
 syntax_rules += r'''
 <createColumnFamilyStatement> ::= "CREATE" wat=( "COLUMNFAMILY" | "TABLE" ) ("IF" "NOT" "EXISTS")?
                                     ( ks=<nonSystemKeyspaceName> dot="." )? cf=<cfOrKsName>
@@ -979,6 +992,7 @@ def create_cf_wat_completer(ctxt, cass):
         return ['TABLE']
     return ['TABLE', 'COLUMNFAMILY']
 
+
 explain_completion('createColumnFamilyStatement', 'cf', '<new_table_name>')
 explain_completion('compositeKeyCfSpec', 'newcolname', '<new_column_name>')
 
@@ -1033,6 +1047,7 @@ def create_cf_composite_primary_key_comma_completer(ctxt, cass):
         return ()
     return [',']
 
+
 syntax_rules += r'''
 
 <idxName> ::= <identifier>
@@ -1065,6 +1080,7 @@ def create_index_col_completer(ctxt, cass):
     colnames = [cd.name for cd in layout.columns.values() if not cd.index]
     return map(maybe_escape_name, colnames)
 
+
 syntax_rules += r'''
 <dropKeyspaceStatement> ::= "DROP" "KEYSPACE" ("IF" "EXISTS")? ksname=<nonSystemKeyspaceName>
                           ;
@@ -1113,6 +1129,7 @@ def idx_ks_idx_name_completer(ctxt, cass):
         raise
     return map(maybe_escape_name, idxnames)
 
+
 syntax_rules += r'''
 <alterTableStatement> ::= "ALTER" wat=( "COLUMNFAMILY" | "TABLE" ) cf=<columnFamilyName>
                                <alterInstructions>
@@ -1149,6 +1166,7 @@ def alter_type_field_completer(ctxt, cass):
     fields = [tuple[0] for tuple in layout]
     return map(maybe_escape_name, fields)
 
+
 explain_completion('alterInstructions', 'newcol', '<new_column_name>')
 explain_completion('alterTypeInstructions', 'newcol', '<new_field_name>')
 
@@ -1227,6 +1245,7 @@ def username_name_completer(ctxt, cass):
     session = cass.session
     return [maybe_quote(row.values()[0].replace("'", "''")) for row in session.execute("LIST USERS")]
 
+
 syntax_rules += r'''
 <createTriggerStatement> ::= "CREATE" "TRIGGER" ( "IF" "NOT" "EXISTS" )? <cident>
                                "ON" cf=<columnFamilyName> "USING" class=<stringLiteral>
@@ -1251,6 +1270,7 @@ def alter_type_field_completer(ctxt, cass):
     names = get_trigger_names(ctxt, cass)
     return map(maybe_escape_name, names)
 
+
 # END SYNTAX/COMPLETION RULE DEFINITIONS
 
 CqlRuleSet.append_rules(syntax_rules)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f8d73a3a/pylib/cqlshlib/displaying.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/displaying.py b/pylib/cqlshlib/displaying.py
index 7b260c2..09068ca 100644
--- a/pylib/cqlshlib/displaying.py
+++ b/pylib/cqlshlib/displaying.py
@@ -99,6 +99,7 @@ class FormattedValue:
         """
         return self.coloredval + self._pad(width, fill)
 
+
 DEFAULT_VALUE_COLORS = dict(
     default=YELLOW,
     text=YELLOW,

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f8d73a3a/pylib/cqlshlib/formatting.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py
index abb4896..eac1810 100644
--- a/pylib/cqlshlib/formatting.py
+++ b/pylib/cqlshlib/formatting.py
@@ -38,6 +38,7 @@ def _show_control_chars(match):
         txt = txt[1:-1]
     return txt
 
+
 bits_to_turn_red_re = re.compile(r'\\([^uUx]|u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|U[0-9a-fA-F]{8})')
 
 
@@ -49,6 +50,7 @@ def _make_turn_bits_red_f(color1, color2):
         return color1 + txt + color2
     return _turn_bits_red
 
+
 default_null_placeholder = 'null'
 default_time_format = ''
 default_float_precision = 3
@@ -101,6 +103,7 @@ def format_value_default(val, colormap, **_):
     bval = controlchars_re.sub(_show_control_chars, escapedval)
     return bval if colormap is NO_COLOR_MAP else color_text(bval, colormap)
 
+
 # Mapping cql type base names ("int", "map", etc) to formatter functions,
 # making format_value a generic function
 _formatters = {}
@@ -128,6 +131,8 @@ def formatter_for(typname):
 def format_value_blob(val, colormap, **_):
     bval = '0x' + binascii.hexlify(str(val))
     return colorme(bval, colormap, 'blob')
+
+
 formatter_for('buffer')(format_value_blob)
 
 
@@ -188,6 +193,7 @@ def format_floating_point_type(val, colormap, float_precision, decimal_sep=None,
 
     return colorme(bval, colormap, 'float')
 
+
 formatter_for('float')(format_floating_point_type)
 
 
@@ -196,6 +202,7 @@ def format_integer_type(val, colormap, thousands_sep=None, **_):
     bval = format_integer_with_thousands_sep(val, thousands_sep) if thousands_sep else str(val)
     return colorme(bval, colormap, 'int')
 
+
 # We can get rid of this in cassandra-2.2
 if sys.version_info >= (2, 7):
     def format_integer_with_thousands_sep(val, thousands_sep=','):
@@ -221,6 +228,7 @@ def format_value_timestamp(val, colormap, time_format, quote=False, **_):
         bval = "'%s'" % bval
     return colorme(bval, colormap, 'timestamp')
 
+
 formatter_for('datetime')(format_value_timestamp)
 
 
@@ -241,6 +249,7 @@ def format_value_text(val, encoding, colormap, quote=False, **_):
 
     return bval if colormap is NO_COLOR_MAP else color_text(bval, colormap, wcwidth.wcswidth(bval.decode(encoding)))
 
+
 # name alias
 formatter_for('unicode')(format_value_text)
 
@@ -286,6 +295,8 @@ def format_value_set(val, encoding, colormap, time_format, float_precision, null
     return format_simple_collection(sorted(val), '{', '}', encoding, colormap,
                                     time_format, float_precision, nullval,
                                     decimal_sep, thousands_sep, boolean_styles)
+
+
 formatter_for('frozenset')(format_value_set)
 # This code is used by cqlsh (bundled driver version 2.7.2 using sortedset),
 # and the dtests, which use whichever driver on the machine, i.e. 3.0.0 (SortedSet)
@@ -314,6 +325,8 @@ def format_value_map(val, encoding, colormap, time_format, float_precision, null
         + rb
     displaywidth = 4 * len(subs) + sum(k.displaywidth + v.displaywidth for (k, v) in subs)
     return FormattedValue(bval, coloredval, displaywidth)
+
+
 formatter_for('OrderedDict')(format_value_map)
 formatter_for('OrderedMap')(format_value_map)
 formatter_for('OrderedMapSerializedKey')(format_value_map)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f8d73a3a/pylib/cqlshlib/pylexotron.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/pylexotron.py b/pylib/cqlshlib/pylexotron.py
index 9cf0f4e..7b11eac 100644
--- a/pylib/cqlshlib/pylexotron.py
+++ b/pylib/cqlshlib/pylexotron.py
@@ -518,6 +518,7 @@ class ParsingRuleSet:
         pattern.match(ctxt, completions)
         return completions
 
+
 import sys
 
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f8d73a3a/pylib/cqlshlib/wcwidth.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/wcwidth.py b/pylib/cqlshlib/wcwidth.py
index bc55c31..985fd41 100644
--- a/pylib/cqlshlib/wcwidth.py
+++ b/pylib/cqlshlib/wcwidth.py
@@ -94,6 +94,7 @@ def bisearch(ucs, table):
             return 1
     return 0
 
+
 # The following two functions define the column width of an ISO 10646
 # character as follows:
 #
@@ -178,6 +179,7 @@ combining = (
     (0xE0100, 0xE01EF)
 )
 
+
 # sorted list of non-overlapping intervals of East Asian Ambiguous
 # characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c"
 ambiguous = (
@@ -321,6 +323,7 @@ def wcwidth_cjk(c):
 def wcswidth_cjk(s):
     return mk_wcswidth_cjk(map(ord, s))
 
+
 if __name__ == "__main__":
     samples = (
         ('MUSIC SHARP SIGN', 1),


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org