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

Unified Diff: third_party/google-endpoints/libpasteurize/fixes/fix_throw.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
Index: third_party/google-endpoints/libpasteurize/fixes/fix_throw.py
diff --git a/third_party/google-endpoints/libpasteurize/fixes/fix_throw.py b/third_party/google-endpoints/libpasteurize/fixes/fix_throw.py
new file mode 100644
index 0000000000000000000000000000000000000000..c0feed1ead7ad7368bdb628597dbaea65b4a0bd3
--- /dev/null
+++ b/third_party/google-endpoints/libpasteurize/fixes/fix_throw.py
@@ -0,0 +1,23 @@
+u"""Fixer for 'g.throw(E(V).with_traceback(T))' -> 'g.throw(E, V, T)'"""
+
+from lib2to3 import fixer_base
+from lib2to3.pytree import Node, Leaf
+from lib2to3.pgen2 import token
+from lib2to3.fixer_util import Comma
+
+class FixThrow(fixer_base.BaseFix):
+
+ PATTERN = u"""
+ power< any trailer< '.' 'throw' >
+ trailer< '(' args=power< exc=any trailer< '(' val=any* ')' >
+ trailer< '.' 'with_traceback' > trailer< '(' trc=any ')' > > ')' > >
+ """
+
+ def transform(self, node, results):
+ syms = self.syms
+ exc, val, trc = (results[u"exc"], results[u"val"], results[u"trc"])
+ val = val[0] if val else Leaf(token.NAME, u"None")
+ val.prefix = trc.prefix = u" "
+ kids = [exc.clone(), Comma(), val.clone(), Comma(), trc.clone()]
+ args = results[u"args"]
+ args.children = kids

Powered by Google App Engine
This is Rietveld 408576698