python: Change 'clone' function names to 'copy'.
[sliver-openvswitch.git] / python / ovs / db / data.py
index 9530fb9..334c261 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import errno
-import logging
-import os
 import re
-import select
-import sys
 import uuid
 
 import ovs.poller
@@ -101,7 +96,7 @@ class Atom(object):
             or (type_ == ovs.db.types.StringType and type(json) in [str, unicode])):
             atom = Atom(type_, json)
         elif type_ == ovs.db.types.UuidType:
-            atom = Atom(type_, ovs.ovsuuid.UUID.from_json(json, symtab))
+            atom = Atom(type_, ovs.ovsuuid.from_json(json, symtab))
         else:
             raise error.Error("expected %s" % type_.to_string(), json)
         atom.check_constraints(base)
@@ -152,7 +147,7 @@ class Atom(object):
     
     def to_json(self):
         if self.type == ovs.db.types.UuidType:
-            return self.value.to_json()
+            return ovs.ovsuuid.to_json(self.value)
         else:
             return self.value
 
@@ -170,7 +165,7 @@ class Atom(object):
             return ['%s.string = xstrdup("%s");'
                     % (var, escapeCString(self.value))]
         elif self.type == ovs.db.types.UuidType:
-            return self.value.cInitUUID(var)
+            return ovs.ovsuuid.to_c_assignment(self.value, var)
 
     def toEnglish(self, escapeLiteral=returnUnchanged):
         if self.type == ovs.db.types.IntegerType:
@@ -217,7 +212,7 @@ class Atom(object):
         elif type(x) == float:
             t = ovs.db.types.RealType
         elif x in [False, True]:
-            t = ovs.db.types.RealType
+            t = ovs.db.types.BooleanType
         elif type(x) in [str, unicode]:
             t = ovs.db.types.StringType
         elif isinstance(x, uuid):
@@ -246,7 +241,7 @@ class Datum(object):
     def __contains__(self, item):
         return item in self.values
 
-    def clone(self):
+    def copy(self):
         return Datum(self.type, dict(self.values))
 
     @staticmethod
@@ -269,10 +264,10 @@ class Datum(object):
         This function is not commonly useful because the most ordinary way to
         obtain a datum is ultimately via Datum.from_json() or Atom.from_json(),
         which check constraints themselves."""
-        for keyAtom, valueAtom in self.values:
-            keyAtom.check_constraints()
+        for keyAtom, valueAtom in self.values.iteritems():
+            keyAtom.check_constraints(self.type.key)
             if valueAtom is not None:
-                valueAtom.check_constraints()
+                valueAtom.check_constraints(self.type.value)
 
     @staticmethod
     def from_json(type_, json, symtab=None):
@@ -348,11 +343,9 @@ class Datum(object):
         if head:
             s.append(head)
 
-        i = 0
-        for key in sorted(self.values):
+        for i, key in enumerate(sorted(self.values)):
             if i:
                 s.append(", ")
-            i += 1
 
             s.append(key.to_string())
             if self.type.is_map():
@@ -412,18 +405,14 @@ class Datum(object):
         s += ["%s->keys = xmalloc(%d * sizeof *%s->keys);"
               % (var, len(self.values), var)]
 
-        i = 0
-        for key, value in sorted(self.values.items()):
+        for i, key in enumerate(sorted(self.values)):
             s += key.cInitAtom("%s->keys[%d]" % (var, i))
-            i += 1
         
         if self.type.value:
             s += ["%s->values = xmalloc(%d * sizeof *%s->values);"
                   % (var, len(self.values), var)]
-            i = 0
-            for key, value in sorted(self.values.items()):
+            for i, (key, value) in enumerate(sorted(self.values.items())):
                 s += value.cInitAtom("%s->values[%d]" % (var, i))
-                i += 1
         else:
             s += ["%s->values = NULL;" % var]