[py-svn] r33605 - in py/dist/py/apigen: rest tracer tracer/testing
fijal at codespeak.net
fijal at codespeak.net
Mon Oct 23 17:30:25 CEST 2006
Author: fijal
Date: Mon Oct 23 17:30:23 2006
New Revision: 33605
Modified:
py/dist/py/apigen/rest/genrest.py
py/dist/py/apigen/tracer/description.py
py/dist/py/apigen/tracer/docstorage.py
py/dist/py/apigen/tracer/model.py
py/dist/py/apigen/tracer/testing/test_model.py
Log:
Some minor changes and fixes. Right now it seems that it needs some serious testing (it does not crash on pylib though).
Modified: py/dist/py/apigen/rest/genrest.py
==============================================================================
--- py/dist/py/apigen/rest/genrest.py (original)
+++ py/dist/py/apigen/rest/genrest.py Mon Oct 23 17:30:23 2006
@@ -220,7 +220,12 @@
#call_sites.append(LiteralBlock(call_site.source))
# XXX: For now, we just paste here the filename of that
#call_sites.append(Paragraph(link_str))
- source = frame.code.source()
+ try:
+ source = frame.code.source()
+ except KeyboardInterrupt, SystemError:
+ raise
+ except:
+ source = "*Cannot get source*"
lines = []
for num, line in enumerate(source):
if num == call_site.lineno - frame.code.firstlineno - 1:
Modified: py/dist/py/apigen/tracer/description.py
==============================================================================
--- py/dist/py/apigen/tracer/description.py (original)
+++ py/dist/py/apigen/tracer/description.py Mon Oct 23 17:30:23 2006
@@ -122,7 +122,8 @@
# This is a hack. We're trying to return as much close to __init__
# of us as possible, but still hashable object
if hasattr(self.pyobj, '__init__'):
- if hasattr(self.pyobj.__init__, 'im_func'):
+ if hasattr(self.pyobj.__init__, 'im_func') and \
+ hasattr(self.pyobj.__init__.im_func, 'func_code'):
result = self.pyobj.__init__.im_func.func_code
else:
result = self.pyobj.__init__
Modified: py/dist/py/apigen/tracer/docstorage.py
==============================================================================
--- py/dist/py/apigen/tracer/docstorage.py (original)
+++ py/dist/py/apigen/tracer/docstorage.py Mon Oct 23 17:30:23 2006
@@ -100,7 +100,7 @@
return (key, desc) # How to do it better? I want a desc to be a key
# value, but I cannot get full object if I do a lookup
- def from_pkg(self, module):
+ def from_pkg(self, module, keep_frames=False):
self.module = module
keys = module.__package__.exportdefs.keys()
d = {}
@@ -110,13 +110,55 @@
for elem in chain:
base = getattr(base, elem)
d[key] = base
- self.from_dict(d)
+ self.from_dict(d, keep_frames)
return self
def from_module(self, func):
raise NotImplementedError("From module")
-class DocStorageAccessor(object):
+class AbstractDocStorageAccessor(object):
+ def __init__(self):
+ raise NotImplementedError("Purely virtual object")
+
+ def get_function_names(self):
+ """ Returning names of all functions
+ """
+
+ def get_class_names(self):
+ """ Returning names of all classess
+ """
+
+ def get_function_doc(self, name):
+ """ Returning __doc__ of a function
+ """
+
+ def get_function_definition(self, name):
+ """ Returns definition of a function (source)
+ """
+
+ def get_function_signature(self, name):
+ """ Returns types of a function
+ """
+
+ def get_function_callpoints(self, name):
+ """ Returns list of all callpoints
+ """
+
+ def get_module_name(self):
+ pass
+
+ def get_class_methods(self, name):
+ """ Returns all methods of a class
+ """
+
+ #def get_object_info(self, key):
+ #
+
+ def get_module_info(self):
+ """ Returns module information
+ """
+
+class DocStorageAccessor(AbstractDocStorageAccessor):
""" Set of helper functions to access DocStorage, separated in different
class to keep abstraction
"""
Modified: py/dist/py/apigen/tracer/model.py
==============================================================================
--- py/dist/py/apigen/tracer/model.py (original)
+++ py/dist/py/apigen/tracer/model.py Mon Oct 23 17:30:23 2006
@@ -18,12 +18,23 @@
def unionof(self, other):
if isinstance(other, SomeImpossibleValue):
return self
+ if isinstance(other, SomeUnion):
+ return other.unionof(self)
if self.gettypedef() is other.gettypedef():
return self
return SomeUnion([self, other])
def gettypedef(self):
return self.typedef
+
+ def __hash__(self):
+ return hash(self.__class__)
+
+ def __eq__(self, other):
+ return self.__class__ == other.__class__
+
+ def __ne__(self, other):
+ return not self == other
class SomeUnion(object):
# empty typedef
@@ -31,6 +42,16 @@
self.possibilities = possibilities
def unionof(self, other):
+ if isinstance(other, SomeUnion):
+ poss = []
+ our_poss = {}
+ for p in self.possibilities:
+ our_poss[p] = True
+ for p in other.possibilities:
+ if not p in our_poss:
+ poss.append(p)
+ poss += self.possibilities
+ return SomeUnion(poss)
return SomeUnion(self.possibilities + [other])
def __repr__(self):
Modified: py/dist/py/apigen/tracer/testing/test_model.py
==============================================================================
--- py/dist/py/apigen/tracer/testing/test_model.py (original)
+++ py/dist/py/apigen/tracer/testing/test_model.py Mon Oct 23 17:30:23 2006
@@ -8,13 +8,13 @@
import types
import py
+def check_guess(val, t):
+ assert isinstance(guess_type(val), t)
+
def test_basic():
""" This tests checks every object that we might want
to track
"""
- def check_guess(val, t):
- assert isinstance(guess_type(val), t)
-
check_guess(3, SomeInt)
check_guess(3., SomeFloat)
check_guess(True, SomeBoolean)
@@ -47,5 +47,23 @@
check_guess({}, SomeDict)
check_guess(sys.exc_info, SomeBuiltinFunction)
+def test_anyof():
+ def check_lst(lst):
+ a = guess_type(lst[0])
+ for i in lst[1:]:
+ a = unionof(a, guess_type(i))
+ d = dict([(i, True) for i in a.possibilities])
+ assert len(a.possibilities) == len(d)
+ for i in a.possibilities:
+ assert not isinstance(i, SomeUnion)
+ return a
+
+ ret = check_lst([3, 4, 3., "aa"])
+ assert len(ret.possibilities) == 3
+ ret = check_lst([3, 4, 3.])
+ ret2 = check_lst([1, "aa"])
+ ret3 = unionof(ret, ret2)
+ assert len(ret3.possibilities) == 3
+
def test_union():
py.test.skip("We're not thinking about type unions right now")
More information about the py-svn
mailing list