You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2008/05/16 17:58:13 UTC

svn commit: r657112 - in /incubator/qpid/trunk/qpid/python/qpid: invoker.py spec010.py spec08.py util.py

Author: rhs
Date: Fri May 16 08:58:12 2008
New Revision: 657112

URL: http://svn.apache.org/viewvc?rev=657112&view=rev
Log:
QPID-947: initialize docstrings for protocol methods from the spec

Modified:
    incubator/qpid/trunk/qpid/python/qpid/invoker.py
    incubator/qpid/trunk/qpid/python/qpid/spec010.py
    incubator/qpid/trunk/qpid/python/qpid/spec08.py
    incubator/qpid/trunk/qpid/python/qpid/util.py

Modified: incubator/qpid/trunk/qpid/python/qpid/invoker.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/invoker.py?rev=657112&r1=657111&r2=657112&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/invoker.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/invoker.py Fri May 16 08:58:12 2008
@@ -23,6 +23,9 @@
 
   def METHOD(self, name, resolved):
     method = lambda *args, **kwargs: self.invoke(resolved, args, kwargs)
+    method.__name__ = resolved.pyname
+    method.__doc__ = resolved.pydoc
+    method.__module__ = self.__class__.__module__
     self.__dict__[name] = method
     return method
 

Modified: incubator/qpid/trunk/qpid/python/qpid/spec010.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/spec010.py?rev=657112&r1=657111&r2=657112&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/spec010.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/spec010.py Fri May 16 08:58:12 2008
@@ -19,7 +19,7 @@
 
 import os, cPickle, datatypes
 from codec010 import StringCodec
-from util import mtime
+from util import mtime, fill
 
 class Node:
 
@@ -201,9 +201,10 @@
 
 class Composite(Type, Coded):
 
-  def __init__(self, name, code, size, pack, children):
+  def __init__(self, name, label, code, size, pack, children):
     Coded.__init__(self, code)
     Type.__init__(self, name, children)
+    self.label = label
     self.fields = []
     self.size = size
     self.pack = pack
@@ -254,11 +255,30 @@
       if flags & (0x1 << i):
         f.type.encode(codec, values[f.name])
 
+  def docstring(self):
+    docs = []
+    if self.label:
+      docs.append(self.label)
+    docs += [d.text for d in self.docs]
+    s = "\n\n".join([fill(t, 2) for t in docs])
+    for f in self.fields:
+      fdocs = []
+      if f.label:
+        fdocs.append(f.label)
+      else:
+        fdocs.append("")
+      fdocs += [d.text for d in f.docs]
+      s += "\n\n" + "\n\n".join([fill(fdocs[0], 4, f.name)] +
+                                [fill(t, 4) for t in fdocs[1:]])
+    return s
+
+
 class Field(Named, Node, Lookup):
 
-  def __init__(self, name, type, children):
+  def __init__(self, name, label, type, children):
     Named.__init__(self, name)
     Node.__init__(self, children)
+    self.label = label
     self.type = type
     self.exceptions = []
 
@@ -284,6 +304,8 @@
     if self.code is not None:
       self.spec.structs[self.code] = self
     self.spec.structs_by_name[self.name] = self
+    self.pyname = self.name
+    self.pydoc = self.docstring()
 
   def __str__(self):
     fields = ",\n    ".join(["%s: %s" % (f.name, f.type.qname)
@@ -303,8 +325,8 @@
 
 class Instruction(Composite, Segment):
 
-  def __init__(self, name, code, children):
-    Composite.__init__(self, name, code, 0, 2, children)
+  def __init__(self, name, label, code, children):
+    Composite.__init__(self, name, label, code, 0, 2, children)
     Segment.__init__(self)
     self.track = None
     self.handlers = []
@@ -315,12 +337,14 @@
 
   def register(self, node):
     Composite.register(self, node)
-    self.spec.instructions[self.qname.replace(".", "_")] = self
+    self.pyname = self.qname.replace(".", "_")
+    self.pydoc = self.docstring()
+    self.spec.instructions[self.pyname] = self
 
 class Control(Instruction):
 
-  def __init__(self, name, code, children):
-    Instruction.__init__(self, name, code, children)
+  def __init__(self, name, code, label, children):
+    Instruction.__init__(self, name, code, label, children)
     self.response = None
 
   def register(self, node):
@@ -332,8 +356,8 @@
 
 class Command(Instruction):
 
-  def __init__(self, name, code, children):
-    Instruction.__init__(self, name, code, children)
+  def __init__(self, name, label, code, children):
+    Instruction.__init__(self, name, label, code, children)
     self.result = None
     self.exceptions = []
     self.segments = []
@@ -599,7 +623,7 @@
     return Role(id(r["@name"]), self.children(r))
 
   def do_control(self, c):
-    return Control(id(c["@name"]), self.code(c), self.children(c))
+    return Control(id(c["@name"]), c["@label"], self.code(c), self.children(c))
 
   def do_rule(self, r):
     return Rule(id(r["@name"]), self.children(r))
@@ -611,14 +635,14 @@
     return Response(id(r["@name"]), self.children(r))
 
   def do_field(self, f):
-    return Field(id(f["@name"]), id(f["@type"]), self.children(f))
+    return Field(id(f["@name"]), f["@label"], id(f["@type"]), self.children(f))
 
   def do_struct(self, s):
-    return Struct(id(s["@name"]), self.code(s), num(s["@size"]),
+    return Struct(id(s["@name"]), s["@label"], self.code(s), num(s["@size"]),
                   num(s["@pack"]), self.children(s))
 
   def do_command(self, c):
-    return Command(id(c["@name"]), self.code(c), self.children(c))
+    return Command(id(c["@name"]), c["@label"], self.code(c), self.children(c))
 
   def do_segments(self, s):
     return Anonymous(self.children(s))

Modified: incubator/qpid/trunk/qpid/python/qpid/spec08.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/spec08.py?rev=657112&r1=657111&r2=657112&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/spec08.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/spec08.py Fri May 16 08:58:12 2008
@@ -29,7 +29,8 @@
 situations.
 """
 
-import re, textwrap, new, mllib, qpid
+import re, new, mllib, qpid
+from util import fill
 
 class SpecContainer:
 
@@ -449,15 +450,6 @@
     pass
   return name
 
-def fill(text, indent, heading = None):
-  sub = indent * " "
-  if heading:
-    init = (indent - 2) * " " + heading + " -- "
-  else:
-    init = sub
-  w = textwrap.TextWrapper(initial_indent = init, subsequent_indent = sub)
-  return w.fill(" ".join(text.split()))
-
 class Rule(Metadata):
 
   PRINT = ["text", "implement", "tests"]

Modified: incubator/qpid/trunk/qpid/python/qpid/util.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/util.py?rev=657112&r1=657111&r2=657112&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/util.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/util.py Fri May 16 08:58:12 2008
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-import os, socket, time
+import os, socket, time, textwrap
 
 def connect(host, port):
   sock = socket.socket()
@@ -65,3 +65,14 @@
     condition.notifyAll()
   finally:
     condition.release()
+
+def fill(text, indent, heading = None):
+  sub = indent * " "
+  if heading:
+    if not text:
+      return (indent - 2) * " " + heading
+    init = (indent - 2) * " " + heading + " -- "
+  else:
+    init = sub
+  w = textwrap.TextWrapper(initial_indent = init, subsequent_indent = sub)
+  return w.fill(" ".join(text.split()))