本文整理汇总了Python中docutils.utils.get_source_line方法的典型用法代码示例。如果您正苦于以下问题:Python utils.get_source_line方法的具体用法?Python utils.get_source_line怎么用?Python utils.get_source_line使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.utils
的用法示例。
在下文中一共展示了utils.get_source_line方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _warn_node
# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import get_source_line [as 别名]
def _warn_node(self, msg, node, **kwargs):
if not msg.startswith('nonlocal image URI found:'):
self._warnfunc(msg, '%s:%s' % get_source_line(node))
示例2: _warn_node
# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import get_source_line [as 别名]
def _warn_node(self, msg, node, **kwargs):
if not msg.startswith('nonlocal image URI found:'):
self._warnfunc(msg, '%s:%s' % get_source_line(node), **kwargs)
示例3: _warn_node
# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import get_source_line [as 别名]
def _warn_node(self, msg, node, **kwargs):
if msg.startswith('nonlocal image URI found:'):
return
self._warnfunc(msg, '%s:%s' % get_source_line(node))
示例4: visit_image
# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import get_source_line [as 别名]
def visit_image(self, node):
# Capture the image file.
if 'uri' in node.attributes:
source = node.attributes['uri']
if not (source.startswith('http:') or source.startswith('https:')):
if not source.startswith(os.sep):
docsource, line = utils.get_source_line(node)
if docsource:
dirname = os.path.dirname(docsource)
if dirname:
source = '%s%s%s' % (dirname, os.sep, source, )
if not self.check_file_exists(source):
self.document.reporter.warning(
'Cannot find image file %s.' % (source, ))
return
else:
return
if source in self.image_dict:
filename, destination = self.image_dict[source]
else:
self.image_count += 1
filename = os.path.split(source)[1]
destination = 'Pictures/1%08x%s' % (self.image_count, filename, )
if source.startswith('http:') or source.startswith('https:'):
try:
imgfile = urllib2.urlopen(source)
content = imgfile.read()
imgfile.close()
imgfile2 = tempfile.NamedTemporaryFile('wb', delete=False)
imgfile2.write(content)
imgfile2.close()
imgfilename = imgfile2.name
source = imgfilename
except urllib2.HTTPError, e:
self.document.reporter.warning(
"Can't open image url %s." % (source, ))
spec = (source, destination,)
else:
示例5: _warn_node
# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import get_source_line [as 别名]
def _warn_node(self, msg, node, **kwargs):
if not (
msg.startswith('nonlocal image URI found:') or
'Unexpected indentation' in msg or
'Definition list ends without a blank line' in msg or
'document isn\'t included in any toctree' in msg
):
self._warnfunc(msg, '%s:%s' % get_source_line(node))
示例6: _warn_node
# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import get_source_line [as 别名]
def _warn_node(self, msg, node):
if not msg.startswith('nonlocal image URI found:'):
self._warnfunc(msg, '%s:%s' % get_source_line(node))
示例7: visit_image
# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import get_source_line [as 别名]
def visit_image(self, node):
# Capture the image file.
if 'uri' in node.attributes:
source = node.attributes['uri']
if not source.startswith('http:'):
if not source.startswith(os.sep):
docsource, line = utils.get_source_line(node)
if docsource:
dirname = os.path.dirname(docsource)
if dirname:
source = '%s%s%s' % (dirname, os.sep, source, )
if not self.check_file_exists(source):
self.document.reporter.warning(
'Cannot find image file %s.' % (source, ))
return
else:
return
if source in self.image_dict:
filename, destination = self.image_dict[source]
else:
self.image_count += 1
filename = os.path.split(source)[1]
destination = 'Pictures/1%08x%s' % (self.image_count, filename, )
if source.startswith('http:'):
try:
imgfile = urllib.request.urlopen(source)
content = imgfile.read()
imgfile.close()
imgfile2 = tempfile.NamedTemporaryFile('wb', delete=False)
imgfile2.write(content)
imgfile2.close()
imgfilename = imgfile2.name
source = imgfilename
except urllib.error.HTTPError as e:
self.document.reporter.warning(
"Can't open image url %s." % (source, ))
spec = (source, destination,)
else:
spec = (os.path.abspath(source), destination,)
self.embedded_file_list.append(spec)
self.image_dict[source] = (source, destination,)
# Is this a figure (containing an image) or just a plain image?
if self.in_paragraph:
el1 = self.current_element
else:
el1 = SubElement(self.current_element, 'text:p',
attrib={'text:style-name': self.rststyle('textbody')})
el2 = el1
if isinstance(node.parent, docutils.nodes.figure):
el3, el4, el5, caption = self.generate_figure(node, source,
destination, el2)
attrib = {}
el6, width = self.generate_image(node, source, destination,
el5, attrib)
if caption is not None:
el6.tail = caption
else: #if isinstance(node.parent, docutils.nodes.image):
el3 = self.generate_image(node, source, destination, el2)
示例8: visit_image
# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import get_source_line [as 别名]
def visit_image(self, node):
# Capture the image file.
if 'uri' in node.attributes:
source = node.attributes['uri']
if not (source.startswith('http:') or source.startswith('https:')):
if not source.startswith(os.sep):
docsource, line = utils.get_source_line(node)
if docsource:
dirname = os.path.dirname(docsource)
if dirname:
source = '%s%s%s' % (dirname, os.sep, source, )
if not self.check_file_exists(source):
self.document.reporter.warning(
'Cannot find image file %s.' % (source, ))
return
else:
return
if source in self.image_dict:
filename, destination = self.image_dict[source]
else:
self.image_count += 1
filename = os.path.split(source)[1]
destination = 'Pictures/1%08x%s' % (self.image_count, filename, )
if source.startswith('http:') or source.startswith('https:'):
try:
imgfile = urllib.request.urlopen(source)
content = imgfile.read()
imgfile.close()
imgfile2 = tempfile.NamedTemporaryFile('wb', delete=False)
imgfile2.write(content)
imgfile2.close()
imgfilename = imgfile2.name
source = imgfilename
except urllib.error.HTTPError as e:
self.document.reporter.warning(
"Can't open image url %s." % (source, ))
spec = (source, destination,)
else:
spec = (os.path.abspath(source), destination,)
self.embedded_file_list.append(spec)
self.image_dict[source] = (source, destination,)
# Is this a figure (containing an image) or just a plain image?
if self.in_paragraph:
el1 = self.current_element
else:
el1 = SubElement(self.current_element, 'text:p',
attrib={'text:style-name': self.rststyle('textbody')})
el2 = el1
if isinstance(node.parent, docutils.nodes.figure):
el3, el4, el5, caption = self.generate_figure(node, source,
destination, el2)
attrib = {}
el6, width = self.generate_image(node, source, destination,
el5, attrib)
if caption is not None:
el6.tail = caption
else: #if isinstance(node.parent, docutils.nodes.image):
el3 = self.generate_image(node, source, destination, el2)
示例9: visit_image
# 需要导入模块: from docutils import utils [as 别名]
# 或者: from docutils.utils import get_source_line [as 别名]
def visit_image(self, node):
# Capture the image file.
if 'uri' in node.attributes:
source = node.attributes['uri']
if not (source.startswith('http:') or source.startswith('https:')):
if not source.startswith(os.sep):
docsource, line = utils.get_source_line(node)
if docsource:
dirname = os.path.dirname(docsource)
if dirname:
source = '%s%s%s' % (dirname, os.sep, source, )
if not self.check_file_exists(source):
self.document.reporter.warning(
'Cannot find image file %s.' % (source, ))
return
else:
return
if source in self.image_dict:
filename, destination = self.image_dict[source]
else:
self.image_count += 1
filename = os.path.split(source)[1]
destination = 'Pictures/1%08x%s' % (self.image_count, filename, )
if source.startswith('http:') or source.startswith('https:'):
try:
imgfile = urlopen(source)
content = imgfile.read()
imgfile.close()
imgfile2 = tempfile.NamedTemporaryFile('wb', delete=False)
imgfile2.write(content)
imgfile2.close()
imgfilename = imgfile2.name
source = imgfilename
except HTTPError:
self.document.reporter.warning(
"Can't open image url %s." % (source, ))
spec = (source, destination,)
else:
spec = (os.path.abspath(source), destination,)
self.embedded_file_list.append(spec)
self.image_dict[source] = (source, destination,)
# Is this a figure (containing an image) or just a plain image?
if self.in_paragraph:
el1 = self.current_element
else:
el1 = SubElement(
self.current_element, 'text:p',
attrib={'text:style-name': self.rststyle('textbody')})
el2 = el1
if isinstance(node.parent, docutils.nodes.figure):
el3, el4, el5, caption = self.generate_figure(
node, source,
destination, el2)
attrib = {}
el6, width = self.generate_image(
node, source, destination,
el5, attrib)
if caption is not None:
el6.tail = caption
else: # if isinstance(node.parent, docutils.nodes.image):
self.generate_image(node, source, destination, el2)