Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from photons_products import Products
from docutils.parsers.rst import Directive
from docutils import statemachine
import enum
class ShowListDirective(Directive):
has_content = True
def run(self):
want = self.content[0]
parts = want.split(".")
if len(parts) == 1:
thing = __import__(want)
else:
thing = getattr(
__import__(".".join(parts[:-1]), globals(), locals(), [parts[-1]], 0), parts[-1]
)
if len(self.content) > 1:
thing = getattr(thing, self.content[1])
option_spec = {'class': directives.class_option,
'name': directives.unchanged}
has_content = True
def run(self):
self.assert_has_content()
text = '\n'.join(self.content)
node = nodes.compound(text)
node['classes'] += self.options.get('class', [])
self.add_name(node)
self.state.nested_parse(self.content, self.content_offset, node)
return [node]
class Container(Directive):
optional_arguments = 1
final_argument_whitespace = True
option_spec = {'name': directives.unchanged}
has_content = True
def run(self):
self.assert_has_content()
text = '\n'.join(self.content)
try:
if self.arguments:
classes = directives.class_option(self.arguments[0])
else:
classes = []
except ValueError:
raise self.error(
# Convert tabs to spaces, if `tab_width` is positive.
if tab_width >= 0:
text = rawtext.expandtabs(tab_width)
else:
text = rawtext
literal_block = nodes.literal_block(rawtext, text, source=path)
literal_block.line = 1
return [literal_block]
else:
include_lines = statemachine.string2lines(
rawtext, tab_width, convert_whitespace=1)
self.state_machine.insert_input(include_lines, path)
return []
class Raw(Directive):
"""
Pass through content unchanged
Content is included in output based on type argument
Content may be included inline (content section of directive) or
imported from a file or url.
"""
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
option_spec = {'file': directives.path,
'url': directives.uri,
'encoding': directives.encoding}
nodes.inline('', '%s.' % text,
classes=['versionmodified']),
translatable=False)
node.append(para)
env = self.state.document.settings.env
env.get_domain('changeset').note_changeset(node)
return [node] + messages
# Support for including Misc/NEWS
issue_re = re.compile('(?:[Ii]ssue #|bpo-)([0-9]+)')
whatsnew_re = re.compile(r"(?im)^what's new in (.*?)\??$")
class MiscNews(Directive):
has_content = False
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = False
option_spec = {}
def run(self):
fname = self.arguments[0]
source = self.state_machine.input_lines.source(
self.lineno - self.state_machine.input_offset - 1)
source_dir = getenv('PY_MISC_NEWS_DIR')
if not source_dir:
source_dir = path.dirname(path.abspath(source))
fpath = path.join(source_dir, fname)
self.state.document.settings.record_dependencies.add(fpath)
try:
pass
if len(lines) and state_machine:
state_machine.insert_input(
lines, state_machine.input_lines.source(0))
logger.debug(
"report_directive.run: profile: finished: collecting: %s" % tag)
logger.debug(
"report_directive.run: profile: finished: rst: %s:%i" %
(str(document), lineno))
return []
class report_directive(Directive):
required_arguments = 1
optional_arguments = 0
has_content = True
final_argument_whitespace = True
# build option spec
option_spec = get_option_spec()
def run(self):
document = self.state.document.current_source
logger = Component.get_logger()
logger.info("report_directive: starting: %s:%i" %
(str(document), self.lineno))
env = self.state.document.settings.env
import inspect
from docutils import statemachine
from docutils.parsers.rst import directives, Directive
import sphinx
from sphinx.roles import XRefRole
from sphinx.domains.python import PyXRefRole
if sphinx.__version__ < '1.0.1':
raise RuntimeError("Sphinx 1.0.1 or newer is required")
from brian2.core.preferences import prefs
from .docscrape_sphinx import get_doc_object, SphinxDocString
class BrianPrefsDirective(Directive):
'''
A sphinx 'Directive' for automatically generated documentation of Brian preferences.
The directive takes an optional argument, the basename of the preferences
to document. In addition, you can specify a `nolinks` option which means
that no target links for the references are added. Do this if you document
preferences in more then one place.
Examples
--------
Document one category of preferences and generate links::
.. document_brian_prefs:: core
Document all preferences without generating links::
# -*- encoding:utf-8 -*-
# Author: Taoge
from __future__ import unicode_literals
import os
from docutils import nodes
from docutils.parsers.rst import Directive, directives
from common import get_template
from gaode import Gaode, GDError
class poi_node(nodes.General, nodes.Element):
pass
class POIDirective(Directive):
has_content = True
option_spec = {
'name': directives.unchanged_required,
'address': directives.unchanged_required,
'link': directives.unchanged_required,
'scene': directives.unchanged_required,
'recommend': directives.unchanged_required,
}
def run(self):
name = self.options["name"]
address = self.options["address"]
link = self.options["link"]
scene = self.options["scene"]
recommend = self.options['recommend']
content = self.content.data
, parallel_read_safe = True
, parallel_write_safe = True
)
# ==============================================================================
class kernel_doc_man( # pylint: disable=invalid-name
nodes.Invisible, nodes.Element):
# ==============================================================================
"""Node to mark a section as *manpage*"""
def skip_kernel_doc_man(self, node): # pylint: disable=unused-argument
raise nodes.SkipNode
# ==============================================================================
class KernelDocMan(Directive):
# ==============================================================================
required_arguments = 1
optional_arguments = 0
def run(self):
man_node = kernel_doc_man()
man_node["manpage"] = self.arguments[0]
return [man_node]
# ==============================================================================
class Section2Manpage(Transform):
# ==============================================================================
u"""Transforms a *section* tree into an *manpage* tree.
The structural layout of a man-page differs from the one produced, by the
''' This is called at the start of processing an activecode node. If activecode had recursive nodes
etc and did not want to do all of the processing in visit_ac_node any finishing touches could be
added here.
'''
pass
def process_activcode_nodes(app,env,docname):
pass
def purge_activecodes(app,env,docname):
pass
class ActiveCode(Directive):
required_arguments = 1
optional_arguments = 1
has_content = True
option_spec = {
'nocanvas':directives.flag,
'nopre':directives.flag,
'above':directives.flag, # put the canvas above the code
'autorun':directives.flag,
'caption':directives.unchanged,
'include':directives.unchanged,
'hidecode':directives.flag,
'language':directives.unchanged,
'tour_1':directives.unchanged,
'tour_2':directives.unchanged,
'tour_3':directives.unchanged,
'tour_4':directives.unchanged,
Example::
.. youtube:: anwy2MPT5RE
:height: 315
:width: 560
:align: left
:copyright: (c) 2012 by Danilo Bargen.
:license: BSD 3-clause
"""
def align(argument):
"""Conversion function for the "align" option."""
return directives.choice(argument, ('left', 'center', 'right'))
class IframeVideo(Directive):
has_content = True
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = False
option_spec = {
'height': directives.nonnegative_int,
'width': directives.nonnegative_int,
'align': align,
'css': directives.unchanged,
}
default_width = 500
default_height = 281
def run(self):
self.options['video_id'] = directives.uri(self.arguments[0])
self.options['caption'] = '<br>'.join(self.content)