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

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

Issue 2888: __findattr__ refactor (Closed) Base URL: https://jython.svn.sourceforge.net/svnroot/jython/branches/asm
Left Patch Set: Created 16 years, 7 months ago
Right Patch Set: This is the actually commited patch (on r5155), in case you have more comments Created 16 years, 7 months ago
Left:
Right:
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
« no previous file with change/comment | « src/org/python/core/PyTableCode.java ('k') | src/org/python/core/PyType.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 PyTupleDerived extends PyTuple implements Slotted { 4 public class PyTupleDerived extends PyTuple 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 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 if (impl!=null) 967 if (impl!=null)
968 return impl.__get__(this,self_type).__call__(args,keywords); 968 return impl.__get__(this,self_type).__call__(args,keywords);
969 return super.__call__(args,keywords); 969 return super.__call__(args,keywords);
970 } finally { 970 } finally {
971 --ts.recursion_depth; 971 --ts.recursion_depth;
972 } 972 }
973 } 973 }
974 974
975 public PyObject __findattr_ex__(String name) { 975 public PyObject __findattr_ex__(String name) {
976 PyType self_type=getType(); 976 PyType self_type=getType();
977 // TODO: We should speed this up. As the __getattribute__ slot almost ne ver
978 // changes, it is a good candidate for caching, as PyClass does wi th
979 // __getattr__. See #1102.
977 PyObject getattribute=self_type.lookup("__getattribute__"); 980 PyObject getattribute=self_type.lookup("__getattribute__");
978 PyString py_name=null; 981 PyString py_name=null;
979 PyException firstAttributeError=null; 982 PyException firstAttributeError=null;
980 try { 983 try {
981 if (getattribute!=null) { 984 if (getattribute!=null) {
982 return getattribute.__get__(this,self_type).__call__(py_name=PyS tring.fromInterned(name)); 985 py_name=PyString.fromInterned(name);
986 return getattribute.__get__(this,self_type).__call__(py_name);
983 } else { 987 } else {
984 // XXX: This shouldn't happen, becase PyObject exposes 988 Py.Warning(String.format("__getattribute__ not found on type %s" ,self_type.getName()));
985 // __getattribute__.·
986 //
987 // And, by the way, invoking object__getattribute__ is the·
988 // common case. We should optimize that to avoid doing the
989 // '__getattribute__' lookup each time.·
990 PyObject ret=super.__findattr_ex__(name); 989 PyObject ret=super.__findattr_ex__(name);
991 if (ret!=null) { 990 if (ret!=null) {
992 return ret; 991 return ret;
993 } // else: pass through to __getitem__ invocation 992 } // else: pass through to __getitem__ invocation
994 } 993 }
995 } catch (PyException e) { 994 } catch (PyException e) {
996 if (!Py.matchException(e,Py.AttributeError)) { 995 if (!Py.matchException(e,Py.AttributeError)) {
997 throw e; 996 throw e;
998 } else { 997 } else {
999 firstAttributeError=e; // saved to avoid swallowing custom Attri buteErrors 998 firstAttributeError=e; // saved to avoid swallowing custom Attri buteErrors
1000 // and pass through to __getattr__ invocation. 999 // and pass through to __getattr__ invocation.
1001 } 1000 }
1002 } 1001 }
1003 PyObject getattr=self_type.lookup("__getattr__"); 1002 PyObject getattr=self_type.lookup("__getattr__");
1004 if (getattr!=null) { 1003 if (getattr!=null) {
1005 return getattr.__get__(this,self_type).__call__(py_name!=null?py_nam e:PyString.fromInterned(name)); 1004 if (py_name==null) {
1005 py_name=PyString.fromInterned(name);
1006 }
1007 return getattr.__get__(this,self_type).__call__(py_name);
1006 } 1008 }
1007 if (firstAttributeError!=null) { 1009 if (firstAttributeError!=null) {
1008 throw firstAttributeError; 1010 throw firstAttributeError;
1009 } else { 1011 }
1010 return null; 1012 return null;
1011 }
1012 } 1013 }
1013 1014
1014 public void __setattr__(String name,PyObject value) { 1015 public void __setattr__(String name,PyObject value) {
1015 PyType self_type=getType(); 1016 PyType self_type=getType();
1016 PyObject impl=self_type.lookup("__setattr__"); 1017 PyObject impl=self_type.lookup("__setattr__");
1017 if (impl!=null) { 1018 if (impl!=null) {
1018 impl.__get__(this,self_type).__call__(PyString.fromInterned(name),va lue); 1019 impl.__get__(this,self_type).__call__(PyString.fromInterned(name),va lue);
1019 return; 1020 return;
1020 } 1021 }
1021 super.__setattr__(name,value); 1022 super.__setattr__(name,value);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 if (impl!=null) 1123 if (impl!=null)
1123 return impl.__get__(this,self_type).__call__(Py.java2py(c)).__tojava __(Object.class); 1124 return impl.__get__(this,self_type).__call__(Py.java2py(c)).__tojava __(Object.class);
1124 return super.__tojava__(c); 1125 return super.__tojava__(c);
1125 } 1126 }
1126 1127
1127 public Object __coerce_ex__(PyObject o) { 1128 public Object __coerce_ex__(PyObject o) {
1128 PyType self_type=getType(); 1129 PyType self_type=getType();
1129 PyObject impl=self_type.lookup("__coerce__"); 1130 PyObject impl=self_type.lookup("__coerce__");
1130 if (impl!=null) { 1131 if (impl!=null) {
1131 PyObject res=impl.__get__(this,self_type).__call__(o); 1132 PyObject res=impl.__get__(this,self_type).__call__(o);
1132 if (res==null||res==Py.None) 1133 if (res==Py.NotImplemented)
1133 return res; 1134 return Py.None;
1134 if (!(res instanceof PyTuple)) 1135 if (!(res instanceof PyTuple))
1135 throw Py.TypeError("coercion should return None or 2-tuple"); 1136 throw Py.TypeError("__coerce__ didn't return a 2-tuple");
1136 return((PyTuple)res).getArray(); 1137 return((PyTuple)res).getArray();
1137 } 1138 }
1138 return super.__coerce_ex__(o); 1139 return super.__coerce_ex__(o);
1139 } 1140 }
1140 1141
1141 public String toString() { 1142 public String toString() {
1142 PyType self_type=getType(); 1143 PyType self_type=getType();
1143 PyObject impl=self_type.lookup("__repr__"); 1144 PyObject impl=self_type.lookup("__repr__");
1144 if (impl!=null) { 1145 if (impl!=null) {
1145 PyObject res=impl.__get__(this,self_type).__call__(); 1146 PyObject res=impl.__get__(this,self_type).__call__();
1146 if (!(res instanceof PyString)) 1147 if (!(res instanceof PyString))
1147 throw Py.TypeError("__repr__ returned non-string (type "+res.get Type().fastGetName()+")"); 1148 throw Py.TypeError("__repr__ returned non-string (type "+res.get Type().fastGetName()+")");
1148 return((PyString)res).toString(); 1149 return((PyString)res).toString();
1149 } 1150 }
1150 return super.toString(); 1151 return super.toString();
1151 } 1152 }
1152 1153
1153 } 1154 }
LEFTRIGHT

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