示例#1
0
    def runTest(self):
        href = kml.href.Href()
        href.SetUrl('http://foo.com/foo.kml')
        href.SetBasename('bar.jpeg')
        url = href.Href()
        assert url == 'http://foo.com/bar.jpeg'

        href = kml.href.Href()
        href.SetUrl('http://foo.com/dir/foo.kml')
        href.SetBasename('bar.jpeg')
        url = href.Href()
        assert url == 'http://foo.com/dir/bar.jpeg'
示例#2
0
    def runTest(self):
        wms_scheme = 'http'
        wms_host = 'wms.jpl.nasa.gov'
        wms_path = 'wms.cgi'
        wms_queries = [
            'VERSION=1.1.1', 'REQUEST=GetMap', 'SRS=EPSG:4326', 'WIDTH=256',
            'HEIGHT=256', 'LAYERS=BMNG', 'TRANSPARENT=TRUE', 'FORMAT=image/png'
        ]
        wms_month = 'Aug'
        wms_north = 20
        wms_south = 10
        wms_east = -80
        wms_west = -100

        want = 'http://wms.jpl.nasa.gov/wms.cgi?VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG:4326&WIDTH=256&HEIGHT=256&LAYERS=BMNG&TRANSPARENT=TRUE&FORMAT=image/png&STYLES=Aug&BBOX=-100.000000,10.000000,-80.000000,20.000000'

        href = kml.href.Href()
        href.SetScheme(wms_scheme)
        href.SetHostname(wms_host)
        href.SetPath(wms_path)
        for wq in wms_queries:
            href.AddQuery(wq)
        href.AddQueryNameValue('STYLES', wms_month)
        region = kml.region.Region(wms_north, wms_south, wms_east, wms_west,
                                   '0')
        href.AddQuery(kml.wms.WMSBBOX(region))
        hrefstr = href.Href()
        assert hrefstr == want, 'bad url [%s]' % hrefstr
示例#3
0
 def runTest(self):
     parent_path = 'http://foo.com/able/baker/foo.kml'
     dotdot_path = '../charlie/goo.kml'
     want_path = 'http://foo.com/able/charlie/goo.kml'
     href = kml.href.Href()
     href.SetUrl(parent_path)
     href.SetBasename(dotdot_path)
     assert href.Href() == want_path, 'dot dot href failed'
示例#4
0
 def HandleNode(self, href, node, llab, lod):
     parent = href.Href()
     href_nodelist = node.getElementsByTagName('href')
     for href_node in href_nodelist:
         child = kml.kmlparse.GetText(href_node)
         self._SaveLink(parent, child)
     if self.__gather_html:
         self._GatherHtmlLinks(parent, node)
示例#5
0
 def HandleNode(self, href, node, llab, lod):
   self.__node_count += 1
   parent = href.Href()
   self._Print('P  ',parent)
   for icon_node in node.getElementsByTagName('Icon'):
     href_nodelist = icon_node.getElementsByTagName('href')
     for href_node in href_nodelist:
       self._Fetch(parent, kml.kmlparse.GetText(href_node))
示例#6
0
    def Walk(self, kmlfile, llab=None, lod=None, maxdepth=-1):
        """
    NOTE: Errors with child links are not propagated to the return value.
    Args:
      kmlfile: pathname or URL to top of KML hierarchy
      llab: LatLonAltBox of parent
      lod: Lod of parent
    Returns:
      True: kmlfile and exists and parses
      False: kmlfile does not exist or fails to parse
    """
        if maxdepth == 0:
            return True
        if maxdepth == -1:
            nmaxdepth = -1
        else:
            nmaxdepth = maxdepth - 1

        if self.__verbose:
            print kmlfile

        href = kml.href.Href()
        href.SetUrl(kmlfile)
        if os.path.isdir(kmlfile):
            kmldata = GetNetworkLinksFromTree(kmlfile)
        elif os.path.isfile(kmlfile) and kmlfile.endswith('.tgz'):
            kmldata = GetNetworkLinksFromTar(kmlfile, self.__encoding)
        elif kmlfile.endswith('.kmz'):
            kmz = kml.kmz.Kmz(kmlfile)
            if kmz:
                kmldata = kmz.ReadKml()
            else:
                if self.__verbose:
                    print 'kmz failed:', kmlfile
                return False
        else:
            kmldata = kml.href.FetchUrl(href.Href())

        doc = kml.kmlparse.ParseStringUsingCodec(kmldata, self.__encoding)
        if not doc:
            if self.__verbose:
                print kmlfile, 'load or parse error'
            return False

        if not self.__node_handler:
            return False

        self.__node_handler.HandleNode(href, doc, llab, lod)

        self._WalkNetworkLinks(kmlfile, doc, nmaxdepth)

        if self.__walk_style_urls:
            self._WalkStyleUrls(kmlfile, doc)

        return True
示例#7
0
 def HandleNode(self, href, node, llab, lod):
     self.__node_count += 1
     parent = href.Href()
     self._Print('P  ', parent)
     href_nodelist = node.getElementsByTagName('href')
     for href_node in href_nodelist:
         self.__kml_link_count += 1
         child = kml.kmlparse.GetText(href_node)
         self.Fetch(parent, child)
     if self.__check_html:
         self._CheckHtml(parent, node)
示例#8
0
 def runTest(self):
     href = kml.href.Href()
     href.SetUrl('foo/goo.kml')
     href.SetBasename('bar/baz.kml')
     assert href.Href() == 'foo/bar/baz.kml', 'relative file bad'
示例#9
0
 def runTest(self):
     href = kml.href.Href()
     href.SetUrl('http://foo.com/dir/foo/hi.kml')
     href.SetBasename('hello.kml')
     assert href.Href() == 'http://foo.com/dir/foo/hello.kml'