Ejemplo n.º 1
0
class RobotsTxt(rend.Page):
    """A page combining some built-in robots.txt material with etc/robots.txt
	if it exists.
	"""
    builtin = utils.fixIndentation(
        """
		Disallow: /login
		Disallow: /seffe
		""", "")

    def _getContent(self):
        content = self.builtin
        try:
            with open(os.path.join(base.getConfig("webDir"),
                                   "robots.txt")) as f:
                content = content + "\n" + f.read()
        except IOError:
            pass
        return content

    def renderHTTP(self, ctx):
        request = inevow.IRequest(ctx)
        request.setHeader("content-type", "text/plain")
        return self._getContent()

    def locateChild(self, segments):
        return None
Ejemplo n.º 2
0
    def addNormalizedPara(self, stuff):
        """adds stuff to the document, making sure it's not glued to any
		previous material and removing whitespace as necessary for docstrings.
		"""
        self.makeSpace()
        self.content.append(
            utils.fixIndentation(stuff, "", governingLine=2) + "\n")
	def getCode(self):
		"""returns the body code indented with two spaces.
		"""
		if self.code is base.NotGiven:
			return ""
		else:
			return utils.fixIndentation(self.code, "  ", governingLine=1)
	def getBodyCode(self):
		"""returns the body code un-indented.
		"""
		collectedCode = []
		for frag in self.codeFrags:
			collectedCode.append(
				utils.fixIndentation(frag, "", governingLine=1))
		return "\n".join(collectedCode)
Ejemplo n.º 5
0
    def addDefinition(self, defHead, defBody):
        """adds a definition list-style item .

		defBody is re-indented with two spaces, defHead is assumed to only
		contain a single line.
		"""
        self.content.append(defHead + "\n")
        self.content.append(
            utils.fixIndentation(defBody, "  ", governingLine=2) + "\n")
 def deco(f):
     f.adqlUDF_name = name
     f.adqlUDF_signature = f.adqlUDF_name + signature.strip()
     f.adqlUDF_doc = utils.fixIndentation(doc, "", 1).strip()
     f.adqlUDF_returntype = returntype
     f.adqlUDF_unit = unit
     f.adqlUDF_ucd = ucd
     UFUNC_REGISTRY[f.adqlUDF_name.upper()] = f
     return f
 def onElementComplete(self):
     self._onElementCompleteNext(CustomPageFunction)
     vars = globals().copy()
     vars["service"] = self.parent
     exec("def %s(ctx, data):\n%s" %
          (self.name,
           utils.fixIndentation(self.content_,
                                newIndent="  ",
                                governingLine=1).rstrip())) in vars
     self.func = vars[self.name]
Ejemplo n.º 8
0
 def feed(self, ctx, instance, literal):
     if ctx.restricted:
         raise common.RestrictedElement("codeItems")
     attrdef.UnicodeAttribute.feed(self, ctx, instance, literal)
     src = utils.fixIndentation(getattr(instance, self.name_),
                                "  ",
                                governingLine=1)
     src = "def makeRows():\n" + src + "\n"
     instance.iterRowsFromCode = utils.compileFunction(
         src, "makeRows", useGlobals={"context": ctx})
Ejemplo n.º 9
0
def _compileRenderer(source, queryMeta):
	"""returns a function object from source.

	Source must be the function body of a renderer.  The variable data
	contains the entire row, and the thing must return a string or at
	least stan (it can use T.tag).
	"""
	code = ("def format(data):\n"+
		utils.fixIndentation(source, "  ")+"\n")
	return rmkfuncs.makeProc("format", code, "", None, 
		queryMeta=queryMeta, source=source, T=T)
Ejemplo n.º 10
0
def _documentParameters(content, pars):
    content.makeSpace()
    for par in sorted(pars, key=lambda p: p.key):
        if par.late:
            doc = ["Late p"]
        else:
            doc = ["P"]
        doc.append("arameter *%s*\n" % par.key)
        if par.content_:
            doc.append("  defaults to ``%s``;\n" % par.content_)
        if par.description:
            doc.append(utils.fixIndentation(par.description, "  "))
        else:
            doc.append("   UNDOCUMENTED")
        content.addRaw(''.join(doc) + "\n")
    content.makeSpace()
Ejemplo n.º 11
0
def _getModuleFunctionDocs(module):
    """returns documentation for all functions marked with @document in the
	namespace module.
	"""
    res = []
    for name in dir(module):
        if name.startswith("_"):
            # ignore all private attributes, whatever else happens
            continue

        ob = getattr(module, name)
        if hasattr(ob, "buildDocsForThis"):
            if ob.func_doc is None:  # silently ignore if no docstring
                continue
            res.append("*%s%s*" %
                       (name, inspect.formatargspec(*inspect.getargspec(ob))))
            res.append(utils.fixIndentation(ob.func_doc, "  ", 1))
            res.append("")
    return "\n".join(res)
Ejemplo n.º 12
0
    def makeDoc(self, content):
        """adds documentation of macFunc to the RSTFragment content.
		"""
        # macros have args in {}, of course there's no self, and null-arg
        # macros have not {}...
        args, varargs, varkw, defaults = inspect.getargspec(self.macFunc)
        args = inspect.formatargspec(args[1:], varargs, varkw,
                                     defaults).replace("(", "{").replace(
                                         ")",
                                         "}").replace("{}",
                                                      "").replace(", ", "}{")
        content.addRaw("::\n\n  \\%s%s\n\n" % (self.name, args))
        content.addRaw(
            utils.fixIndentation(self.macFunc.func_doc or "undocumented", "",
                                 1).replace("\\", "\\\\"))
        content.addNormalizedPara(
            "Available in " +
            ", ".join(sorted("`Element %s`_" % c.name_
                             for c in self.inObjects)))
Ejemplo n.º 13
0
    def _doAddMeta(self):
        content = self.attrs.pop("content_", "")
        if not self.attrs:  # content only, parse this as a meta stream
            parseMetaStream(self.container, content)

        else:
            try:
                content = utils.fixIndentation(content, "", 1).rstrip()
            except common.Error, ex:
                raise utils.logOldExc(
                    common.StructureError("Bad text in meta value"
                                          " (%s)" % ex))
            if not "name" in self.attrs:
                raise common.StructureError("meta elements must have a"
                                            " name attribute")
            metaKey = self.attrs.pop("name")
            self.container.addMeta(metaKey, content, **self.attrs)

            # meta elements can have children; add these, properly fudging
            # their keys
            for key, content, kwargs in self.children:
                fullKey = "%s.%s" % (metaKey, key)
                self.container.addMeta(fullKey, content, **kwargs)
	def validate(self):
		if self.procDef and self.procDef.type and self.requiredType:
			if self.procDef.type!=self.requiredType:
				raise base.StructureError("The procDef %s has type %s, but"
					" here %s procDefs are required."%(self.procDef.id,
						self.procDef.type, self.requiredType))

		if self.procDef:
			if self.procDef.deprecated:
				if self.getSourcePosition()!="<internally built>":
					# for now, don't warn about these; they typically
					# originate when copying/adapting cores and will just
					# confuse operators
					procId = "unnamed procApp"
					if self.name:
						procId = "procApp %s"%self.name

					base.ui.notifyWarning("%s, %s: %s"%(
						self.getSourcePosition(),
						procId,
						utils.fixIndentation(self.procDef.deprecated, "")))

		self._validateNext(ProcApp)
		self._ensureParsBound()
Ejemplo n.º 15
0
 def __init__(self, script):
     # I need to memorize the script as I may need to recompile
     # it if there's special arguments (yikes!)
     self.code = ("def scriptFun(table, **kwargs):\n" +
                  utils.fixIndentation(script.getSource(), "      ") + "\n")
     ScriptRunner.__init__(self, script)