Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(42)

Delta Between Two Patch Sets: src/org/python/core/PyBaseExceptionDerived.java

Issue 2888: __findattr__ refactor (Closed) SVN Base: https://jython.svn.sourceforge.net/svnroot/jython/branches/asm
Left Patch Set: Created 1 year, 2 months ago
Right Patch Set: This is the actually commited patch (on r5155), in case you have more comments Created 1 year, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* Generated file, do not modify. See jython/src/templates/gderived.py. */ 1 /* Generated file, do not modify. See jython/src/templates/gderived.py. */
2 package org.python.core; 2 package org.python.core;
3 3
4 public class PyBaseExceptionDerived extends PyBaseException implements Slotted { 4 public class PyBaseExceptionDerived extends PyBaseException implements Slotted {
5 5
6 public PyObject getSlot(int index) { 6 public PyObject getSlot(int index) {
7 return slots[index]; 7 return slots[index];
8 } 8 }
9 9
10 public void setSlot(int index,PyObject value) { 10 public void setSlot(int index,PyObject value) {
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 if (impl!=null) 943 if (impl!=null)
944 return impl.__get__(this,self_type).__call__(args,keywords); 944 return impl.__get__(this,self_type).__call__(args,keywords);
945 return super.__call__(args,keywords); 945 return super.__call__(args,keywords);
946 } finally { 946 } finally {
947 --ts.recursion_depth; 947 --ts.recursion_depth;
948 } 948 }
949 } 949 }
950 950
951 public PyObject __findattr_ex__(String name) { 951 public PyObject __findattr_ex__(String name) {
952 PyType self_type=getType(); 952 PyType self_type=getType();
953 // TODO: We should speed this up. As the __getattribute__ slot almost ne ver
954 // changes, it is a good candidate for caching, as PyClass does wi th
955 // __getattr__. See #1102.
953 PyObject getattribute=self_type.lookup("__getattribute__"); 956 PyObject getattribute=self_type.lookup("__getattribute__");
954 PyString py_name=null; 957 PyString py_name=null;
955 PyException firstAttributeError=null; 958 PyException firstAttributeError=null;
956 try { 959 try {
957 if (getattribute!=null) { 960 if (getattribute!=null) {
958 return getattribute.__get__(this,self_type).__call__(py_name=PyS tring.fromInterned(name)); 961 py_name=PyString.fromInterned(name);
962 return getattribute.__get__(this,self_type).__call__(py_name);
959 } else { 963 } else {
960 // XXX: This shouldn't happen, becase PyObject exposes 964 Py.Warning(String.format("__getattribute__ not found on type %s" ,self_type.getName()));
961 // __getattribute__.
962 //
963 // And, by the way, invoking object__getattribute__ is the
964 // common case. We should optimize that to avoid doing the
965 // '__getattribute__' lookup each time.
966 PyObject ret=super.__findattr_ex__(name); 965 PyObject ret=super.__findattr_ex__(name);
967 if (ret!=null) { 966 if (ret!=null) {
968 return ret; 967 return ret;
969 } // else: pass through to __getitem__ invocation 968 } // else: pass through to __getitem__ invocation
970 } 969 }
971 } catch (PyException e) { 970 } catch (PyException e) {
972 if (!Py.matchException(e,Py.AttributeError)) { 971 if (!Py.matchException(e,Py.AttributeError)) {
973 throw e; 972 throw e;
974 } else { 973 } else {
975 firstAttributeError=e; // saved to avoid swallowing custom Attri buteErrors 974 firstAttributeError=e; // saved to avoid swallowing custom Attri buteErrors
976 // and pass through to __getattr__ invocation. 975 // and pass through to __getattr__ invocation.
977 } 976 }
978 } 977 }
979 PyObject getattr=self_type.lookup("__getattr__"); 978 PyObject getattr=self_type.lookup("__getattr__");
980 if (getattr!=null) { 979 if (getattr!=null) {
981 return getattr.__get__(this,self_type).__call__(py_name!=null?py_nam e:PyString.fromInterned(name)); 980 if (py_name==null) {
981 py_name=PyString.fromInterned(name);
982 }
983 return getattr.__get__(this,self_type).__call__(py_name);
982 } 984 }
983 if (firstAttributeError!=null) { 985 if (firstAttributeError!=null) {
984 throw firstAttributeError; 986 throw firstAttributeError;
985 } else { 987 }
986 return null; 988 return null;
987 }
988 } 989 }
989 990
990 public void __setattr__(String name,PyObject value) { 991 public void __setattr__(String name,PyObject value) {
991 PyType self_type=getType(); 992 PyType self_type=getType();
992 PyObject impl=self_type.lookup("__setattr__"); 993 PyObject impl=self_type.lookup("__setattr__");
993 if (impl!=null) { 994 if (impl!=null) {
994 impl.__get__(this,self_type).__call__(PyString.fromInterned(name),va lue); 995 impl.__get__(this,self_type).__call__(PyString.fromInterned(name),va lue);
995 return; 996 return;
996 } 997 }
997 super.__setattr__(name,value); 998 super.__setattr__(name,value);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 if (impl!=null) 1099 if (impl!=null)
1099 return impl.__get__(this,self_type).__call__(Py.java2py(c)).__tojava __(Object.class); 1100 return impl.__get__(this,self_type).__call__(Py.java2py(c)).__tojava __(Object.class);
1100 return super.__tojava__(c); 1101 return super.__tojava__(c);
1101 } 1102 }
1102 1103
1103 public Object __coerce_ex__(PyObject o) { 1104 public Object __coerce_ex__(PyObject o) {
1104 PyType self_type=getType(); 1105 PyType self_type=getType();
1105 PyObject impl=self_type.lookup("__coerce__"); 1106 PyObject impl=self_type.lookup("__coerce__");
1106 if (impl!=null) { 1107 if (impl!=null) {
1107 PyObject res=impl.__get__(this,self_type).__call__(o); 1108 PyObject res=impl.__get__(this,self_type).__call__(o);
1108 if (res==null||res==Py.None) 1109 if (res==Py.NotImplemented)
1109 return res; 1110 return Py.None;
1110 if (!(res instanceof PyTuple)) 1111 if (!(res instanceof PyTuple))
1111 throw Py.TypeError("coercion should return None or 2-tuple"); 1112 throw Py.TypeError("__coerce__ didn't return a 2-tuple");
1112 return((PyTuple)res).getArray(); 1113 return((PyTuple)res).getArray();
1113 } 1114 }
1114 return super.__coerce_ex__(o); 1115 return super.__coerce_ex__(o);
1115 } 1116 }
1116 1117
1117 public String toString() { 1118 public String toString() {
1118 PyType self_type=getType(); 1119 PyType self_type=getType();
1119 PyObject impl=self_type.lookup("__repr__"); 1120 PyObject impl=self_type.lookup("__repr__");
1120 if (impl!=null) { 1121 if (impl!=null) {
1121 PyObject res=impl.__get__(this,self_type).__call__(); 1122 PyObject res=impl.__get__(this,self_type).__call__();
1122 if (!(res instanceof PyString)) 1123 if (!(res instanceof PyString))
1123 throw Py.TypeError("__repr__ returned non-string (type "+res.get Type().fastGetName()+")"); 1124 throw Py.TypeError("__repr__ returned non-string (type "+res.get Type().fastGetName()+")");
1124 return((PyString)res).toString(); 1125 return((PyString)res).toString();
1125 } 1126 }
1126 return super.toString(); 1127 return super.toString();
1127 } 1128 }
1128 1129
1129 } 1130 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r483