2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

python: Avoid lots of \" in quoted strings by using '' as outermost quotes.

Suggested-by: Reid Price <reid@nicira.com>
This commit is contained in:
Ben Pfaff
2011-08-22 16:54:28 -07:00
parent b33a04c63a
commit f2d8ad13e1
6 changed files with 29 additions and 29 deletions

View File

@@ -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:

View File

@@ -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))

View File

@@ -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

View File

@@ -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]

View File

@@ -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)

View File

@@ -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;',