[py-svn] r33718 - in py/dist/py/apigen: rest rest/testing tracer tracer/testing
fijal at codespeak.net
fijal at codespeak.net
Wed Oct 25 15:38:55 CEST 2006
Author: fijal
Date: Wed Oct 25 15:38:52 2006
New Revision: 33718
Modified:
py/dist/py/apigen/rest/genrest.py
py/dist/py/apigen/rest/testing/test_rest.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:
Added crosslinks.
Modified: py/dist/py/apigen/rest/genrest.py
==============================================================================
--- py/dist/py/apigen/rest/genrest.py (original)
+++ py/dist/py/apigen/rest/genrest.py Wed Oct 25 15:38:52 2006
@@ -9,6 +9,7 @@
from py.__.apigen.tracer.docstorage import DocStorageAccessor
from py.__.rst.rst import * # XXX Maybe we should list it here
+from py.__.apigen.tracer import model
class AbstractLinkWriter(object):
""" Class implementing writing links to source code.
@@ -244,8 +245,6 @@
continue
elif module != '':
continue
- print 'retrieving method list for', name
- print 'method list:', self.get_method_list(name)
ret.append((name, self.get_method_list(name)))
return ret
@@ -265,6 +264,19 @@
def get_method_list(self, classname):
return self.dsa.get_class_methods(classname)
+ def process_type_link(self, _type, lst):
+ # now we do simple type dispatching and provide a link in this case
+ data = self.dsa.get_type_desc(_type)
+ if not data:
+ for i in _type.striter():
+ if isinstance(i, str):
+ lst.append(i)
+ else:
+ self.process_type_link(i, lst)
+ return
+ name, _desc_type = data
+ lst.append(Link(str(_type), _desc_type + "_" + name + ".html"))
+
def write_function(self, functionname, belowchar='-'):
# XXX I think the docstring should either be split on \n\n and cleaned
# from indentation, or treated as ReST too (although this is obviously
@@ -273,13 +285,36 @@
LiteralBlock(self.dsa.get_function_doc(functionname)),
LiteralBlock(self.dsa.get_function_definition(functionname))]
+ lst.append(Paragraph("where:"))
args, retval = self.dsa.get_function_signature(functionname)
- arg_str = "\n".join(["%s :: %s" % (str(name), str(type))
- for name, type in args])
- arg_str += "\n" + "Return value :: %s" % str(retval)
- lst.append(Paragraph("where:"))
- lst.append(LiteralBlock(arg_str))
+ for name, _type in args + [('Return value', retval)]:
+ l = []
+ self.process_type_link(_type, l)
+ items = []
+ next = "%s :: " % name
+ for item in l:
+ if isinstance(item, str):
+ next += item
+ else:
+ if next:
+ items.append(Text(next))
+ next = ""
+ items.append(item)
+ if next:
+ items.append(Text(next))
+ lst.append(ListItem(*items))
+ #if link:
+ # link_str, link_target = link
+ # lst.append(ListItem(Quote("%s :: %s" % (name, pre_str)),
+ # Link(link_str, link_target), Quote(post_str)))
+ #else:
+ # lst.append(ListItem(Quote("%s :: %s%s" % (name, _type))))
+
+ #arg_str = "\n".join(["%s :: %s" % (str(name), str(type))
+ # for name, type in args])
+ #arg_str += "\n" + "Return value :: %s" % str(retval)
+ #lst.append(LiteralBlock(arg_str))
# XXX missing implementation of dsa.get_function_location()
#filename, lineno = self.dsa.get_function_location(functionname)
Modified: py/dist/py/apigen/rest/testing/test_rest.py
==============================================================================
--- py/dist/py/apigen/rest/testing/test_rest.py (original)
+++ py/dist/py/apigen/rest/testing/test_rest.py Wed Oct 25 15:38:52 2006
@@ -294,9 +294,9 @@
source = tempdir.join("function_blah.txt").read()
call_point = source.find("Call sites\:")
assert call_point != -1
- assert source.find("a :: <Int>") < call_point
- assert source.find("b :: <String>") < call_point
- assert source.find("c :: <Instance of <Class(C)>>") < call_point
+ assert source.find("a \:\: <Int>") < call_point
+ assert source.find("b \:\: <String>") < call_point
+ assert source.find("c \:\: <Instance of Class C>") < call_point
self.check_rest(tempdir)
def test_class_typedefs(self):
@@ -325,5 +325,5 @@
source = tempdir.join("function_xxx.txt").open().read()
call_point = source.find("Call sites\:")
assert call_point != -1
- assert source.find("x :: <Instance of AnyOf(<Class(B)>,<Class(A)>)>") < call_point
+ assert source.find("x \:\: <Instance of AnyOf( `Class B`_ , `Class A`_ )>") < call_point
self.check_rest(tempdir)
Modified: py/dist/py/apigen/tracer/docstorage.py
==============================================================================
--- py/dist/py/apigen/tracer/docstorage.py (original)
+++ py/dist/py/apigen/tracer/docstorage.py Wed Oct 25 15:38:52 2006
@@ -10,7 +10,7 @@
from py.__.apigen.tracer.description import FunctionDesc, ClassDesc, MethodDesc, \
Desc
-from py.__.apigen.tracer.model import guess_type
+from py.__.apigen.tracer import model
class DocStorage(object):
""" Class storing info about API
@@ -25,10 +25,10 @@
def generalize_args(self, desc, frame):
args = [arg for key, arg in frame.getargs()]
#self.call_stack.append((desc, args))
- desc.consider_call([guess_type(arg) for arg in args])
+ desc.consider_call([model.guess_type(arg) for arg in args])
def generalize_retval(self, desc, arg):
- desc.consider_return(guess_type(arg))
+ desc.consider_return(model.guess_type(arg))
def consider_return(self, frame, arg):
assert isinstance(frame, py.code.Frame)
@@ -211,6 +211,16 @@
assert isinstance(desc, ClassDesc)
return sorted(desc.getfields())
+ def get_type_desc(self, _type):
+ # XXX We provice only classes here
+ if not isinstance(_type, model.SomeClass):
+ return None
+ # XXX we might want to cache it at some point
+ for key, desc in self.ds.descs.iteritems():
+ if desc.pyobj == _type.cls:
+ return key, 'class'
+ return None
+
#def get_object_info(self, key):
#
Modified: py/dist/py/apigen/tracer/model.py
==============================================================================
--- py/dist/py/apigen/tracer/model.py (original)
+++ py/dist/py/apigen/tracer/model.py Wed Oct 25 15:38:52 2006
@@ -35,6 +35,10 @@
def __ne__(self, other):
return not self == other
+
+ # this is to provide possibility of eventually linking some stuff
+ def striter(self):
+ yield str(self)
class SomeUnion(object):
# empty typedef
@@ -55,10 +59,18 @@
return not self == other
def __repr__(self):
- return "AnyOf(%s)" % ",".join([str(i) for i in list(self.possibilities)])
+ return "AnyOf(%s)" % ", ".join([str(i) for i in list(self.possibilities)])
def gettypedef(self):
return (None, None)
+
+ def striter(self):
+ yield "AnyOf("
+ for num, i in enumerate(self.possibilities):
+ yield i
+ if num != len(self.possibilities) - 1:
+ yield ", "
+ yield ")"
class SomeBoolean(SomeObject):
typedef = types.BooleanType
@@ -92,7 +104,7 @@
return self
def __repr__(self):
- return "<Class(%s)>" % self.cls.__name__
+ return "Class %s" % self.cls.__name__
class SomeCode(SomeObject):
typedef = types.CodeType
@@ -146,6 +158,11 @@
def __repr__(self):
return "<Instance of %s>" % str(self.classdef)
+ def striter(self):
+ yield "<Instance of "
+ yield self.classdef
+ yield ">"
+
typedef = types.InstanceType
class SomeInt(SomeObject):
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 Wed Oct 25 15:38:52 2006
@@ -97,3 +97,16 @@
assert isinstance(f.classdef, SomeUnion)
assert len(f.classdef.possibilities) == 2
+def test_striter():
+ class A(object):
+ pass
+
+ class B(object):
+ pass
+
+ g = guess_type(A).unionof(guess_type(A()))
+ l = list(g.striter())
+ assert l[0] == "AnyOf("
+ assert isinstance(l[1], SomeClass)
+ assert l[2] == ", "
+ assert isinstance(l[3], SomeInstance)
More information about the py-svn
mailing list