A
download refcounting.py
Language: Python
LOC: 42
Project Info
Docutils
Server: BerliOS (SVNHTTP)
Type: svn
...sandbox\py‑rest‑doc\sphinx\
   __init__.py
   _jinja.py
   addnodes.py
   builder.py
   console.py
   directives.py
   environment.py
   highlighting.py
   htmlhelp.py
   json.py
   refcounting.py
   roles.py
   search.py
   smartypants.py
   stemmer.py
   util.py
   writer.py

# -*- coding: utf-8 -*-
"""
    sphinx.refcounting
    ~~~~~~~~~~~~~~~~~~

    Handle reference counting annotations, based on refcount.py
    and anno-api.py.

    :copyright: 2007 by Georg Brandl.
    :license: Python license.
"""
from __future__ import with_statement


class RCEntry:
    def __init__(self, name):
        self.name = name
        self.args = []
        self.result_type = ''
        self.result_refs = None


class Refcounts(dict):
    @classmethod
    def fromfile(cls, filename):
        d = cls()
        with open(filename, 'r') as fp:
            for line in fp:
                line = line.strip()
                if line[:1] in ("", "#"):
                    # blank lines and comments
                    continue
                parts = line.split(":", 4)
                if len(parts) != 5:
                    raise ValueError("Wrong field count in %r" % line)
                function, type, arg, refcount, comment = parts
                # Get the entry, creating it if needed:
                try:
                    entry = d[function]
                except KeyError:
                    entry = d[function] = RCEntry(function)
                if not refcount or refcount == "null":
                    refcount = None
                else:
                    refcount = int(refcount)
                # Update the entry with the new parameter or the result information.
                if arg:
                    entry.args.append((arg, type, refcount))
                else:
                    entry.result_type = type
                    entry.result_refs = refcount
        return d

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us