本文整理汇总了Python中sphinx.config.Config.sharepost方法的典型用法代码示例。如果您正苦于以下问题:Python Config.sharepost方法的具体用法?Python Config.sharepost怎么用?Python Config.sharepost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sphinx.config.Config
的用法示例。
在下文中一共展示了Config.sharepost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sphinx.config import Config [as 别名]
# 或者: from sphinx.config.Config import sharepost [as 别名]
def __init__(self, filename, encoding="utf8", raise_exception=False):
"""
create an instance of a blog post from a file or a string
@param filename filename or string
@param encoding encoding
@param raise_exception to raise an exception when the blog cannot be parsed
The constructor creates the following members:
* title
* date
* keywords
* categories
* _filename
* _raw
* rst_obj: the object generated by docutils (@see cl BlogPostDirective)
* pub: Publisher
.. versionchanged:: 1.3
Parameter *raise_exception* was added to catch the standard error.
The constructor aims at getting the text of a blog post, not
interpreting it. The code used to throw warnings or errors due to
unreferenced nodes.
"""
if os.path.exists(filename):
with open(filename, "r", encoding=encoding) as f:
try:
content = f.read()
except UnicodeDecodeError as e:
raise Exception(
'unable to read filename (encoding issue):\n File "{0}", line 1'.format(filename)) from e
self._filename = filename
else:
content = filename
self._filename = None
self._raw = content
overrides = {}
overrides['input_encoding'] = encoding
overrides["out_blogpostlist"] = []
overrides["blog_background"] = False
overrides["sharepost"] = None
overrides.update({'doctitle_xform': True,
'initial_header_level': 2,
'warning_stream': StringIO(),
'out_blogpostlist': [],
'out_runpythonlist': [],
})
config = Config(None, None, overrides=overrides, tags=None)
config.blog_background = False
config.sharepost = None
env = BuildEnvironment(None, None, config=config)
env.temp_data["docname"] = "string"
overrides["env"] = env
errst = sys.stderr
keeperr = StringIO()
sys.stderr = keeperr
output, pub = publish_programmatically(
source_class=docio.StringInput,
source=content,
source_path=None,
destination_class=docio.StringOutput,
destination=None,
destination_path=None,
reader=None,
reader_name='standalone',
parser=None,
parser_name='restructuredtext',
writer=None,
writer_name='null',
settings=None,
settings_spec=None,
settings_overrides=overrides,
config_section=None,
enable_exit_status=None)
sys.stderr = errst
all_err = keeperr.getvalue()
if len(all_err) > 0:
if raise_exception:
raise BlogPostParseError("unable to parse a blogpost:\nERR:\n{0}\nFILE\n{1}\nCONTENT\n{2}".format(
all_err, self._filename, content))
else:
# we assume we just need the content, raising a warnings
# might make some process fail later
# warnings.warn("Raw rst was caught but unable to fully parse a blogpost:\nERR:\n{0}\nFILE\n{1}\nCONTENT\n{2}".format(
# all_err, self._filename, content))
pass
# document = pub.writer.document
objects = pub.settings.out_blogpostlist
if len(objects) != 1:
#.........这里部分代码省略.........