You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ca...@codespot.com on 2012/01/24 18:48:22 UTC

[cassandra-dbapi2] push by pcannon@gmail.com - fix comment blanker for string literals... on 2012-01-24 17:48 GMT

Revision: 20bbfa61ac9b
Author:   paul cannon <pa...@datastax.com>
Date:     Tue Jan 24 09:46:37 2012
Log:      fix comment blanker for string literals

comment-like markers which showed up in string literals were still being
treated as comments by the blanker. the blanker is necessary to avoid
an even huger regex for trying to identify valid named params
(colon-names in string literals and in comments should not get parameter
replacements).

http://code.google.com/a/apache-extras.org/p/cassandra-dbapi2/source/detail?r=20bbfa61ac9b

Modified:
  /cql/marshal.py

=======================================
--- /cql/marshal.py	Tue Dec 13 14:36:44 2011
+++ /cql/marshal.py	Tue Jan 24 09:46:37 2012
@@ -51,11 +51,11 @@
  """, re.S | re.X)

  _comment_re = re.compile(r"""
-    (?:  /\* .*? \*/
-      |  // [^\n]*
-      |  -- [^\n]*
-    )
-""", re.S | re.X)
+       // .*? $
+    |  -- .*? $
+    |  /\* .*? \*/
+    | ' [^']* '
+""", re.S | re.M | re.X)

  BYTES_TYPE = "org.apache.cassandra.db.marshal.BytesType"
  ASCII_TYPE = "org.apache.cassandra.db.marshal.AsciiType"
@@ -73,6 +73,14 @@
  TIME_UUID_TYPE = "org.apache.cassandra.db.marshal.TimeUUIDType"
  COUNTER_COLUMN_TYPE = "org.apache.cassandra.db.marshal.CounterColumnType"

+def blank_comments(query):
+    def teh_blanker(match):
+        m = match.group(0)
+        if m.startswith("'"):
+            return m
+        return ' ' * len(m)
+    return _comment_re.sub(teh_blanker, query)
+
  def prepare(query, params):
      """
      For every match of the form ":param_name", call cql_quote
@@ -83,7 +91,7 @@
      # kill comments first, so that we don't have to try to parse around  
them.
      # but keep the character count the same, so that location-tagged error
      # messages still work
-    query = _comment_re.sub(lambda m: ' ' * len(m.group(0)), query)
+    query = blank_comments(query)
      return _param_re.sub(lambda m: m.group(1) +  
cql_quote(params[m.group(2)]), query)

  def cql_quote(term):