Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / server2 / docs_server_utils.py
index 442c5ca..7fe962e 100644 (file)
@@ -23,10 +23,21 @@ def SanitizeAPIName(name):
     filename = 'experimental_' + filename.replace('experimental_', '')
   return filename
 
-def StringIdentity(string):
+def StringIdentity(first, *more):
   '''Creates a small hash of a string.
   '''
-  return b64encode(sha1(string).digest())[:8]
+  def encode(string):
+    return b64encode(sha1(string).digest())
+  identity = encode(first)
+  for m in more:
+    identity = encode(identity + m)
+  return identity[:8]
+
+def MarkFirst(dicts):
+  '''Adds a property 'first' == True to the first element in a list of dicts.
+  '''
+  if len(dicts) > 0:
+    dicts[0]['first'] = True
 
 def MarkLast(dicts):
   '''Adds a property 'last' == True to the last element in a list of dicts.
@@ -34,6 +45,12 @@ def MarkLast(dicts):
   if len(dicts) > 0:
     dicts[-1]['last'] = True
 
+def MarkFirstAndLast(dicts):
+  '''Marks the first and last element in a list of dicts.
+  '''
+  MarkFirst(dicts)
+  MarkLast(dicts)
+
 def ToUnicode(data):
   '''Returns the str |data| as a unicode object. It's expected to be utf8, but
   there are also latin-1 encodings in there for some reason. Fall back to that.