Anonymous avatar Anonymous committed 9d057ba

add getattro method

Comments (0)

Files changed (3)

 svrv_getattr(PySvRV_Object *self, PyObject *name)
 {   
     PyObject *val;
-	register char *sname = PyString_AsString(name);
-    //printf("getattr : %s\n", name);
+    PyObject *dict;
+    SV *sv;
+    sv = self->sv;
+	dict = self->ref_dict;
+    register char *sname = PyString_AsString(name);
+    //printf("getattr : %s\n", sname);
+    
     if (strcmp(sname, "__dict__") == 0) {
-	    Py_INCREF(self->ref_dict);
-        val = self->ref_dict;
+	    //Py_INCREF(self->ref_dict);
+        val = dict;
+    }else if(strcmp(sname, "__members__") == 0){
+        val = PyList_New(0);
+    }else if(strcmp(sname, "__methods__") == 0){
+        val = PyList_New(0);
+    }else if(strcmp(sname, "__class__") == 0){
+        if(SvOBJECT(SvRV(sv))){
+            val = PyString_FromString(self->module);
+        }else{
+            val = Py_BuildValue("");
+        }
+    }else{
+        val = PyDict_GetItem(dict, name);
     }
-	
+    if(val == NULL)
+        val = Py_None;
     return val;
 }
 
             if(perlmethod == NULL)
                 return -1;
 
-            if(PyDict_SetItemString(dict, method_name, (PyObject *)perlmethod) < 0)
+            if(PyDict_SetItem(dict, n, (PyObject *)perlmethod) < 0)
                 return -1;
             
         }
     PyObject *list;
     sv = self->sv;
     if(SvOBJECT(SvRV(sv))){
+        self->module = module;
         //printf("is object %s\n", module);
         list = get_methodnames(self->interp, module);
         return add_perlmethods(self, list);
     SV *sv;
     Perl_Object *interp;
     PyObject *ref_dict;
-    char *method;
+    char *module;
 } PySvRV_Object;
 
 typedef struct {

tests/test_perl.py

     ua1 = p.call_ctor("new", "LWP::UserAgent")
     ua2 = p.call_ctor("new", "LWP::UserAgent")
     ua3 = p.call_ctor("new", "LWP::UserAgent")
-    assert ua1 != None
-    print ua1.__dict__
+    #assert ua1 != None
+    print dir(ua1)
+    print ua1.timeout
     #print dir(ua1)
     #print type(ua1)
     #print locals()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.