Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: third_party/google-endpoints/pyasn1/type/tagmap.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/google-endpoints/pyasn1/type/tag.py ('k') | third_party/google-endpoints/pyasn1/type/univ.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/google-endpoints/pyasn1/type/tagmap.py
diff --git a/third_party/google-endpoints/pyasn1/type/tagmap.py b/third_party/google-endpoints/pyasn1/type/tagmap.py
new file mode 100644
index 0000000000000000000000000000000000000000..feb91ae3d85779731b21d0bd8a3e328102d55477
--- /dev/null
+++ b/third_party/google-endpoints/pyasn1/type/tagmap.py
@@ -0,0 +1,66 @@
+from pyasn1 import error
+
+class TagMap:
+ def __init__(self, posMap={}, negMap={}, defType=None):
+ self.__posMap = posMap.copy()
+ self.__negMap = negMap.copy()
+ self.__defType = defType
+
+ def __contains__(self, tagSet):
+ return tagSet in self.__posMap or \
+ self.__defType is not None and tagSet not in self.__negMap
+
+ def __getitem__(self, tagSet):
+ if tagSet in self.__posMap:
+ return self.__posMap[tagSet]
+ elif tagSet in self.__negMap:
+ raise error.PyAsn1Error('Key in negative map')
+ elif self.__defType is not None:
+ return self.__defType
+ else:
+ raise KeyError()
+
+ def __repr__(self):
+ s = self.__class__.__name__ + '('
+ if self.__posMap:
+ s = s + 'posMap=%r, ' % (self.__posMap,)
+ if self.__negMap:
+ s = s + 'negMap=%r, ' % (self.__negMap,)
+ if self.__defType is not None:
+ s = s + 'defType=%r' % (self.__defType,)
+ return s + ')'
+
+ def __str__(self):
+ s = self.__class__.__name__ + ':\n'
+ if self.__posMap:
+ s = s + 'posMap:\n%s, ' % ',\n '.join([ x.prettyPrintType() for x in self.__posMap.values()])
+ if self.__negMap:
+ s = s + 'negMap:\n%s, ' % ',\n '.join([ x.prettyPrintType() for x in self.__negMap.values()])
+ if self.__defType is not None:
+ s = s + 'defType:\n%s, ' % self.__defType.prettyPrintType()
+ return s
+
+ def clone(self, parentType, tagMap, uniq=False):
+ if self.__defType is not None and tagMap.getDef() is not None:
+ raise error.PyAsn1Error('Duplicate default value at %s' % (self,))
+ if tagMap.getDef() is not None:
+ defType = tagMap.getDef()
+ else:
+ defType = self.__defType
+
+ posMap = self.__posMap.copy()
+ for k in tagMap.getPosMap():
+ if uniq and k in posMap:
+ raise error.PyAsn1Error('Duplicate positive key %s' % (k,))
+ posMap[k] = parentType
+
+ negMap = self.__negMap.copy()
+ negMap.update(tagMap.getNegMap())
+
+ return self.__class__(
+ posMap, negMap, defType,
+ )
+
+ def getPosMap(self): return self.__posMap.copy()
+ def getNegMap(self): return self.__negMap.copy()
+ def getDef(self): return self.__defType
« no previous file with comments | « third_party/google-endpoints/pyasn1/type/tag.py ('k') | third_party/google-endpoints/pyasn1/type/univ.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698