mirror of
https://github.com/powerline/powerline.git
synced 2025-07-27 07:44:36 +02:00
Do not leak environment and home directory in documentation
Fixes #1329
This commit is contained in:
parent
6b0cd3d37c
commit
ff49538c04
@ -1,6 +1,8 @@
|
|||||||
# vim:fileencoding=utf-8:noet
|
# vim:fileencoding=utf-8:noet
|
||||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from inspect import formatargspec
|
from inspect import formatargspec
|
||||||
|
|
||||||
from sphinx.ext import autodoc
|
from sphinx.ext import autodoc
|
||||||
@ -29,6 +31,34 @@ class ThreadedDocumenter(autodoc.FunctionDocumenter):
|
|||||||
return formatargspec(*argspec, formatvalue=formatvalue).replace('\\', '\\\\')
|
return formatargspec(*argspec, formatvalue=formatvalue).replace('\\', '\\\\')
|
||||||
|
|
||||||
|
|
||||||
|
class Repr(object):
|
||||||
|
def __init__(self, repr_contents):
|
||||||
|
self.repr_contents = repr_contents
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<{0}>'.format(self.repr_contents)
|
||||||
|
|
||||||
|
|
||||||
|
class EnvironDocumenter(autodoc.AttributeDocumenter):
|
||||||
|
@classmethod
|
||||||
|
def can_document_member(cls, member, membername, isattr, parent):
|
||||||
|
if type(member) is dict and member.get('environ') is os.environ:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def import_object(self, *args, **kwargs):
|
||||||
|
ret = super(EnvironDocumenter, self).import_object(*args, **kwargs)
|
||||||
|
if not ret:
|
||||||
|
return ret
|
||||||
|
self.object = self.object.copy()
|
||||||
|
if 'home' in self.object:
|
||||||
|
self.object.update(home=Repr('home directory'))
|
||||||
|
self.object.update(environ=Repr('environ dictionary'))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
autodoc.setup(app)
|
autodoc.setup(app)
|
||||||
app.add_autodocumenter(ThreadedDocumenter)
|
app.add_autodocumenter(ThreadedDocumenter)
|
||||||
|
app.add_autodocumenter(EnvironDocumenter)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user