MCPcopy
hub / github.com/pandas-dev/pandas / _transform_doc

Method _transform_doc

pandas/io/formats/xml.py:528–566  ·  view source on GitHub ↗

Parse stylesheet from file or buffer and run it. This method will parse stylesheet object into tree for parsing conditionally by its specific object type, then transforms original tree with XSLT script.

(self)

Source from the content-addressed store, hash-verified

526 return SubElement
527
528 def _transform_doc(self) -> bytes:
529 """
530 Parse stylesheet from file or buffer and run it.
531
532 This method will parse stylesheet object into tree for parsing
533 conditionally by its specific object type, then transforms
534 original tree with XSLT script.
535 """
536 from lxml.etree import (
537 XSLT,
538 XMLParser,
539 fromstring,
540 parse,
541 )
542
543 style_doc = self.stylesheet
544 assert style_doc is not None # is ensured by caller
545
546 handle_data = get_data_from_filepath(
547 filepath_or_buffer=style_doc,
548 encoding=self.encoding,
549 compression=self.compression,
550 storage_options=self.storage_options,
551 )
552
553 with handle_data as xml_data:
554 curr_parser = XMLParser(encoding=self.encoding)
555
556 if isinstance(xml_data, io.StringIO):
557 xsl_doc = fromstring(
558 xml_data.getvalue().encode(self.encoding), parser=curr_parser
559 )
560 else:
561 xsl_doc = parse(xml_data, parser=curr_parser)
562
563 transformer = XSLT(xsl_doc)
564 new_doc = transformer(self.root)
565
566 return bytes(new_doc)

Callers 1

_build_treeMethod · 0.95

Calls 3

get_data_from_filepathFunction · 0.90
parseFunction · 0.85
encodeMethod · 0.80

Tested by

no test coverage detected