[ovs-dev] [python 05/31] python: Avoid lots of \" in quoted strings by using '' as outermost quotes.

Ben Pfaff blp at nicira.com
Tue Aug 23 21:04:59 UTC 2011


Suggested-by: Reid Price <reid at nicira.com>
---
 python/ovs/db/data.py   |    6 +++---
 python/ovs/db/error.py  |    4 ++--
 python/ovs/db/idl.py    |   30 +++++++++++++++---------------
 python/ovs/db/parser.py |    2 +-
 python/ovs/db/schema.py |    6 +++---
 python/ovs/db/types.py  |   10 +++++-----
 6 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/python/ovs/db/data.py b/python/ovs/db/data.py
index 27f6f11..eb3060d 100644
--- a/python/ovs/db/data.py
+++ b/python/ovs/db/data.py
@@ -143,12 +143,12 @@ class Atom(object):
             length = len(s)
             if length < base.min_length:
                 raise ConstraintViolation(
-                    "\"%s\" length %d is less than minimum allowed length %d"
+                    '"%s" length %d is less than minimum allowed length %d'
                     % (s, length, base.min_length))
             elif length > base.max_length:
                 raise ConstraintViolation(
-                    "\"%s\" length %d is greater than maximum allowed "
-                    "length %d" % (s, length, base.max_length))
+                    '"%s" length %d is greater than maximum allowed '
+                    'length %d' % (s, length, base.max_length))
     
     def to_json(self):
         if self.type == ovs.db.types.UuidType:
diff --git a/python/ovs/db/error.py b/python/ovs/db/error.py
index 882518c..f863516 100644
--- a/python/ovs/db/error.py
+++ b/python/ovs/db/error.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2009, 2010 Nicira Networks
+# Copyright (c) 2009, 2010, 2011 Nicira Networks
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -29,5 +29,5 @@ class Error(Exception):
         # Compose message.
         syntax = ""
         if self.json is not None:
-                syntax = "syntax \"%s\": " % ovs.json.to_string(self.json)
+                syntax = 'syntax "%s": ' % ovs.json.to_string(self.json)
         Exception.__init__(self, "%s%s: %s" % (syntax, self.tag, self.msg))
diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
index 1ee330e..8ce1751 100644
--- a/python/ovs/db/idl.py
+++ b/python/ovs/db/idl.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2009, 2010 Nicira Networks
+# Copyright (c) 2009, 2010, 2011 Nicira Networks
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -185,40 +185,40 @@ class Idl:
         for table_name, table_update in table_updates.iteritems():
             table = self.schema.tables.get(table_name)
             if not table:
-                raise error.Error("<table-updates> includes unknown "
-                                  "table \"%s\"" % table_name)
+                raise error.Error('<table-updates> includes unknown '
+                                  'table "%s"' % table_name)
 
             if type(table_update) != dict:
-                raise error.Error("<table-update> for table \"%s\" is not "
-                                  "an object" % table_name, table_update)
+                raise error.Error('<table-update> for table "%s" is not '
+                                  'an object' % table_name, table_update)
 
             for uuid_string, row_update in table_update.iteritems():
                 if not ovs.ovsuuid.UUID.is_valid_string(uuid_string):
-                    raise error.Error("<table-update> for table \"%s\" "
-                                      "contains bad UUID \"%s\" as member "
-                                      "name" % (table_name, uuid_string),
+                    raise error.Error('<table-update> for table "%s" '
+                                      'contains bad UUID "%s" as member '
+                                      'name' % (table_name, uuid_string),
                                       table_update)
                 uuid = ovs.ovsuuid.UUID.from_string(uuid_string)
 
                 if type(row_update) != dict:
-                    raise error.Error("<table-update> for table \"%s\" "
-                                      "contains <row-update> for %s that "
-                                      "is not an object"
+                    raise error.Error('<table-update> for table "%s" '
+                                      'contains <row-update> for %s that '
+                                      'is not an object'
                                       % (table_name, uuid_string))
 
                 old = row_update.get("old", None)
                 new = row_update.get("new", None)
 
                 if old is not None and type(old) != dict:
-                    raise error.Error("\"old\" <row> is not object", old)
+                    raise error.Error('"old" <row> is not an object', old)
                 if new is not None and type(new) != dict:
-                    raise error.Error("\"new\" <row> is not object", new)
+                    raise error.Error('"new" <row> is not an object', new)
                 if (old is not None) + (new is not None) != len(row_update):
                     raise error.Error("<row-update> contains unexpected "
                                       "member", row_update)
                 if not old and not new:
-                    raise error.Error("<row-update> missing \"old\" and "
-                                      "\"new\" members", row_update)
+                    raise error.Error('<row-update> missing "old" and '
+                                      '"new" members', row_update)
 
                 if self.__parse_row_update(table, uuid, old, new):
                     self.change_seqno += 1
diff --git a/python/ovs/db/parser.py b/python/ovs/db/parser.py
index 07ce8e2..8858f00 100644
--- a/python/ovs/db/parser.py
+++ b/python/ovs/db/parser.py
@@ -94,7 +94,7 @@ def json_type_to_string(type):
 def unwrap_json(json, name, need_type):
     if (type(json) != list or len(json) != 2 or json[0] != name or
         type(json[1]) != need_type):
-        raise error.Error("expected [\"%s\", <%s>]"
+        raise error.Error('expected ["%s", <%s>]'
                           % (name, json_type_to_string(need_type)), json)
     return json[1]
 
diff --git a/python/ovs/db/schema.py b/python/ovs/db/schema.py
index 1a12393..e76d6f6 100644
--- a/python/ovs/db/schema.py
+++ b/python/ovs/db/schema.py
@@ -65,13 +65,13 @@ class DbSchema(object):
 
         if (version is not None and
             not re.match('[0-9]+\.[0-9]+\.[0-9]+$', version)):
-            raise error.Error("schema version \"%s\" not in format x.y.z"
+            raise error.Error('schema version "%s" not in format x.y.z'
                               % version)
 
         tables = {}
         for tableName, tableJson in tablesJson.iteritems():
             if tableName.startswith('_'):
-                raise error.Error("names beginning with \"_\" are reserved",
+                raise error.Error('names beginning with "_" are reserved',
                                   json)
             elif not ovs.db.parser.is_identifier(tableName):
                 raise error.Error("name must be a valid id", json)
@@ -183,7 +183,7 @@ class TableSchema(object):
         columns = {}
         for column_name, column_json in columns_json.iteritems():
             if column_name.startswith('_'):
-                raise error.Error("names beginning with \"_\" are reserved",
+                raise error.Error('names beginning with "_" are reserved',
                                   json)
             elif not ovs.db.parser.is_identifier(column_name):
                 raise error.Error("name must be a valid id", json)
diff --git a/python/ovs/db/types.py b/python/ovs/db/types.py
index 2ca0d29..ded9f5f 100644
--- a/python/ovs/db/types.py
+++ b/python/ovs/db/types.py
@@ -30,7 +30,7 @@ class AtomicType(object):
             for atomic_type in ATOMIC_TYPES:
                 if s == atomic_type.name:
                     return atomic_type
-        raise error.Error("\"%s\" is not an atomic type" % s)
+        raise error.Error('"%s" is not an atomic type' % s)
 
     @staticmethod
     def from_json(json):
@@ -39,7 +39,7 @@ class AtomicType(object):
         try:
             return AtomicType.from_string(json)
         except error.Error:
-            raise error.Error("\"%s\" is not an atomic-type" % json, json)
+            raise error.Error('"%s" is not an atomic-type' % json, json)
 
     def __str__(self):
         return self.name
@@ -181,8 +181,8 @@ class BaseType(object):
                 base.ref_type = parser.get_optional("refType", [str, unicode],
                                                    "strong")
                 if base.ref_type not in ['strong', 'weak']:
-                    raise error.Error("refType must be \"strong\" or \"weak\" "
-                                      "(not \"%s\")" % base.ref_type)
+                    raise error.Error('refType must be "strong" or "weak" '
+                                      '(not "%s")' % base.ref_type)
         parser.finish()
 
         return base
@@ -328,7 +328,7 @@ class BaseType(object):
         if self.ref_table:
             return "%s = NULL;" % var
         elif self.type == StringType and not is_optional:
-            return "%s = \"\";" % var
+            return '%s = "";' % var
         else:
             pattern = {IntegerType: '%s = 0;',
                        RealType: '%s = 0.0;',
-- 
1.7.4.4




More information about the dev mailing list