當前位置: 首頁>>代碼示例>>Python>>正文


Python xmlreader.InputSource方法代碼示例

本文整理匯總了Python中xml.sax.xmlreader.InputSource方法的典型用法代碼示例。如果您正苦於以下問題:Python xmlreader.InputSource方法的具體用法?Python xmlreader.InputSource怎麽用?Python xmlreader.InputSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在xml.sax.xmlreader的用法示例。


在下文中一共展示了xmlreader.InputSource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_expat_nsattrs_wattr

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_expat_nsattrs_wattr(self):
        parser = create_parser(1)
        gather = self.AttrGatherer()
        parser.setContentHandler(gather)

        parser.feed("<doc xmlns:ns='%s' ns:attr='val'/>" % ns_uri)
        parser.close()

        attrs = gather._attrs

        self.assertEqual(attrs.getLength(), 1)
        self.assertEqual(attrs.getNames(), [(ns_uri, "attr")])
        self.assertTrue((attrs.getQNames() == [] or
                         attrs.getQNames() == ["ns:attr"]))
        self.assertEqual(len(attrs), 1)
        self.assertTrue(attrs.has_key((ns_uri, "attr")))
        self.assertEqual(attrs.get((ns_uri, "attr")), "val")
        self.assertEqual(attrs.get((ns_uri, "attr"), 25), "val")
        self.assertEqual(attrs.items(), [((ns_uri, "attr"), "val")])
        self.assertEqual(attrs.values(), ["val"])
        self.assertEqual(attrs.getValue((ns_uri, "attr")), "val")
        self.assertEqual(attrs[(ns_uri, "attr")], "val")

    # ===== InputSource support 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:test_sax.py

示例2: test_expat_nsattrs_wattr

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_expat_nsattrs_wattr(self):
        parser = create_parser(1)
        gather = self.AttrGatherer()
        parser.setContentHandler(gather)

        parser.feed("<doc xmlns:ns='%s' ns:attr='val'/>" % ns_uri)
        parser.close()

        attrs = gather._attrs

        self.assertEqual(attrs.getLength(), 1)
        self.assertEqual(attrs.getNames(), [(ns_uri, "attr")])
        self.assertTrue((attrs.getQNames() == [] or
                         attrs.getQNames() == ["ns:attr"]))
        self.assertEqual(len(attrs), 1)
        self.assertIn((ns_uri, "attr"), attrs)
        self.assertEqual(attrs.get((ns_uri, "attr")), "val")
        self.assertEqual(attrs.get((ns_uri, "attr"), 25), "val")
        self.assertEqual(list(attrs.items()), [((ns_uri, "attr"), "val")])
        self.assertEqual(list(attrs.values()), ["val"])
        self.assertEqual(attrs.getValue((ns_uri, "attr")), "val")
        self.assertEqual(attrs[(ns_uri, "attr")], "val")

    # ===== InputSource support 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:26,代碼來源:test_sax.py

示例3: test_expat_nsattrs_no_namespace

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_expat_nsattrs_no_namespace():
    parser = make_parser()
    parser.setFeature(handler.feature_namespaces, 1)
    gather = AttrGatherer()
    parser.setContentHandler(gather)

    a_name = "id" ; a_val = "val"
    parser.parse(StringIO("<doc %s='%s'/>" % (a_name, a_val) ))

    attrs = gather._attrs

    return attrs.getLength() == 1 and \
           attrs.getNames() == [(None, a_name)] and \
           attrs.getQNames() == [a_name] and \
           len(attrs) == 1 and \
           attrs.has_key((None, a_name)) and \
           attrs.keys() == [(None, a_name)] and \
           attrs.get((None, a_name)) == a_val and \
           attrs.get((None, a_name), 25) == a_val and \
           attrs.items() == [((None, a_name), a_val)] and \
           attrs.values() == [a_val] and \
           attrs.getValue((None, a_name)) == a_val and \
           attrs[(None, a_name)] == a_val

# ===== InputSource support 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:27,代碼來源:test_sax.py

示例4: __init__

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def __init__(self, namespaceHandling=0, bufsize=2**16-20):
        xmlreader.IncrementalParser.__init__(self, bufsize)
        self._source = xmlreader.InputSource()
        self._parser = None
        self._namespaces = namespaceHandling
        self._lex_handler_prop = None
        self._parsing = 0
        self._entity_stack = []
        self._external_ges = 1
        self._interning = None

    # XMLReader methods 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:14,代碼來源:expatreader.py

示例5: parse

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def parse(self, source):
        "Parse an XML document from a URL or an InputSource."
        source = saxutils.prepare_input_source(source)

        self._source = source
        self.reset()
        self._cont_handler.setDocumentLocator(ExpatLocator(self))
        xmlreader.IncrementalParser.parse(self, source) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:10,代碼來源:expatreader.py

示例6: parse

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def parse(self, source):
        "Parse an XML document from a URL or an InputSource."
        source = saxutils.prepare_input_source(source)

        self._source = source
        try:
            self.reset()
            self._cont_handler.setDocumentLocator(ExpatLocator(self))
            xmlreader.IncrementalParser.parse(self, source)
        except:
            # bpo-30264: Close the source on error to not leak resources:
            # xml.sax.parse() doesn't give access to the underlying parser
            # to the caller
            self._close_source()
            raise 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:17,代碼來源:expatreader.py

示例7: test_parse_InputSource

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_parse_InputSource(self):
        # accept data without declared but with explicitly specified encoding
        make_xml_file(self.data, 'iso-8859-1', None)
        with io.open(TESTFN, 'rb') as f:
            input = InputSource()
            input.setByteStream(f)
            input.setEncoding('iso-8859-1')
            self.check_parse(input) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_sax.py

示例8: test_byte_stream

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_byte_stream(self):
        # If the source is an InputSource that does not have a character
        # stream but does have a byte stream, use the byte stream.
        src = InputSource(self.file)
        src.setByteStream(self.make_byte_stream())
        prep = prepare_input_source(src)
        self.assertIsNone(prep.getCharacterStream())
        self.checkContent(prep.getByteStream(),
                          b"This is a byte stream.") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_sax.py

示例9: test_system_id

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_system_id(self):
        # If the source is an InputSource that has neither a character
        # stream nor a byte stream, open the system ID.
        src = InputSource(self.file)
        prep = prepare_input_source(src)
        self.assertIsNone(prep.getCharacterStream())
        self.checkContent(prep.getByteStream(),
                          b"This was read from a file.") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_sax.py

示例10: test_expat_inpsource_sysid

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_expat_inpsource_sysid(self):
        parser = create_parser()
        result = StringIO()
        xmlgen = XMLGenerator(result)

        parser.setContentHandler(xmlgen)
        parser.parse(InputSource(TEST_XMLFILE))

        self.assertEqual(result.getvalue(), xml_test_out) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:11,代碼來源:test_sax.py

示例11: test_expat_inpsource_sysid_unicode

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_expat_inpsource_sysid_unicode(self):
        fname = support.TESTFN_UNICODE
        shutil.copyfile(TEST_XMLFILE, fname)
        self.addCleanup(support.unlink, fname)

        parser = create_parser()
        result = StringIO()
        xmlgen = XMLGenerator(result)

        parser.setContentHandler(xmlgen)
        parser.parse(InputSource(fname))

        self.assertEqual(result.getvalue(), xml_test_out) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:test_sax.py

示例12: test_expat_inpsource_byte_stream

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_expat_inpsource_byte_stream(self):
        parser = create_parser()
        result = StringIO()
        xmlgen = XMLGenerator(result)

        parser.setContentHandler(xmlgen)
        inpsrc = InputSource()
        inpsrc.setByteStream(open(TEST_XMLFILE))
        parser.parse(inpsrc)

        self.assertEqual(result.getvalue(), xml_test_out)

    # ===== IncrementalParser support 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:15,代碼來源:test_sax.py

示例13: test_expat_inpsource_location

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_expat_inpsource_location(self):
        parser = create_parser()
        parser.setContentHandler(ContentHandler()) # do nothing
        source = InputSource()
        source.setByteStream(StringIO("<foo bar foobar>"))   #ill-formed
        name = "a file name"
        source.setSystemId(name)
        try:
            parser.parse(source)
            self.fail()
        except SAXException, e:
            self.assertEqual(e.getSystemId(), name) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_sax.py

示例14: resolveEntity

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def resolveEntity(self, publicId, systemId):
            inpsrc = InputSource()
            inpsrc.setByteStream(StringIO("<entity/>"))
            return inpsrc 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:6,代碼來源:test_sax.py

示例15: test_expat_inpsource_stream

# 需要導入模塊: from xml.sax import xmlreader [as 別名]
# 或者: from xml.sax.xmlreader import InputSource [as 別名]
def test_expat_inpsource_stream(self):
        parser = create_parser()
        result = StringIO()
        xmlgen = XMLGenerator(result)

        parser.setContentHandler(xmlgen)
        inpsrc = InputSource()
        inpsrc.setByteStream(open(TEST_XMLFILE))
        parser.parse(inpsrc)

        self.assertEqual(result.getvalue(), xml_test_out)

    # ===== IncrementalParser support 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:15,代碼來源:test_sax.py


注:本文中的xml.sax.xmlreader.InputSource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。