我们从Python开源项目中,提取了以下33个代码示例,用于说明如何使用docutils.utils.get_source_line()。
def _warn_node(self, msg, node, *args, **kwargs): if not msg.startswith('nonlocal image URI found:'): self._warnfunc(msg, '%s:%s' % get_source_line(node))
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)
def _supress_nonlocal_image_warn(self, msg, node, **kwargs): if not msg.startswith('nonlocal image URI found:'): self._warnfunc(msg, '%s:%s' % get_source_line(node), **kwargs)
def _warn_node(self, msg, node, **kwargs): if msg.startswith('nonlocal image URI found:'): return self._warnfunc(msg, '%s:%s' % get_source_line(node))
def _supress_nonlocal_image_warn(self, msg, node, **kwargs): from docutils.utils import get_source_line if not msg.startswith('nonlocal image URI found:'): self._warnfunc(msg, '{0!s}:{1!s}'.format(*get_source_line(node)))
def _warn_node(self, msg, node, **kwargs): if not msg.startswith('nonlocal image URI found:'): self._warnfunc(msg, '%s:%s' % get_source_line(node))
def _warn_node(self, msg, node): if not msg.startswith('nonlocal image URI found:'): self._warnfunc(msg, '%s:%s' % get_source_line(node))
def warn_node(self, msg, node): """Like :meth:`warn`, but with source information taken from *node*.""" self._warnfunc(msg, '%s:%s' % get_source_line(node))
def _supress_nonlocal_image_warn(self, msg, node, **kwargs): if not msg.startswith('nonlocal image URI found:'): self._warnfunc(msg, '{0!s}:{1!s}'.format(*get_source_line(node)), **kwargs)
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 = 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: 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)
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: 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)
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)