Imports

    >>> from owslib import tms

You can find a list of servers at
http://svn.osgeo.org/gdal/trunk/gdal/frmts/wms/WMSServerList.txt

Find out what a TMS has to offer. Service metadata:

    >>> service = tms.TileMapService('http://odims.ospar.org/geoserver/gwc/service/tms/1.0.0', timeout=120)
    >>> service.identification.title
    'Tile Map Service'
    >>> service.identification.abstract
    'A Tile Map Service served by GeoWebCache'
    >>> service.identification.keywords
    []
    >>> service.identification.version
    '1.0.0'
    >>> service.identification.url
    'https://odims.ospar.org/geoserver/gwc/'
    >>> len(service.contents) > 0
    True
    >>> tm = service.contents['http://odims.ospar.org/geoserver/gwc/service/tms/1.0.0/geonode%3Aospar_offshore_renewables_2010_01@EPSG%3A4326@png']
    >>> tm.title
    'ospar_offshore_renewables_2010_01'

you can filter the contents by profile and srs:
    >>> len(service.items())
    664
    >>> len(service.items('EPSG:900913'))
    332
    >>> len(service.items(profile='global-mercator'))
    332
    >>> len(service.items('EPSG:900913', profile='global-mercator'))
    332
    >>> len(service.items('EPSG:4326', profile='global-mercator'))
    0
    >>> sorted(service.items('EPSG:4326'))[0]  # doctest: +ELLIPSIS
    ('http://odims.ospar.org/geoserver/gwc/service/tms/1.0.0/geonode%3AMarine_protected_area__OSPAR____Global_view__polygon_@EPSG%3A4326@gif', <owslib.tms.ContentMetadata object at ...>)

The details of the TileMap are fetched on demand
    >>> tm._tile_map == None
    True
    >>> tm.title
    'ospar_offshore_renewables_2010_01'
    >>> tm.abstract
    >>> tm._tile_map == None
    False
    >>> tm.srs
    'EPSG:4326'
    >>> tm.extension
    'png'
    >>> tm.height
    256
    >>> tm.width
    256
    >>> tm.mimetype
    'image/png'
    >>> tm.boundingBox
    (-180.0, -90.0, 180.0, 90.0)
    >>> tm.origin
    (-180.0, -90.0)




You can get tiles by their x,y,z indices, the title of the tilemap, projection and mime-type
    >>> service.gettile(10,10,0, title='bluemarble', srs='EPSG:4326', mimetype='image/png').geturl()    #doctest: +SKIP
    'http://demo.opengeo.org/geoserver/gwc/service/tms/1.0.0/bluemarble@EPSG%3A4326@png/0/10/10.png'
    >>> service.gettile(10,10,1, title='bluemarble', srs='EPSG:4326', mimetype='image/jpeg').geturl()   #doctest: +SKIP
    'http://demo.opengeo.org/geoserver/gwc/service/tms/1.0.0/bluemarble@EPSG%3A4326@jpeg/1/10/10.jpeg'

if mimetype is ommited the tile is fetched from the first TileMap found:
    >>> service.gettile(10,10,1, title='bluemarble', srs='EPSG:900913').geturl()    #doctest: +SKIP
    'http://demo.opengeo.org/geoserver/gwc/service/tms/1.0.0/bluemarble@EPSG%3A900913@jpeg/1/10/10.jpeg'

You can also specify the Tilemap by id:
    >>> service.gettile(10,10,0, 'http://demo.opengeo.org/geoserver/gwc/service/tms/1.0.0/bluemarble@EPSG%3A900913@jpeg').geturl()    #doctest: +SKIP
    'http://demo.opengeo.org/geoserver/gwc/service/tms/1.0.0/bluemarble@EPSG%3A900913@jpeg/0/10/10.jpeg'

An extensive test  with:
    >>> servers = [
    ...     'http://demo.opengeo.org/geoserver/gwc/service/tms/1.0.0',
    ...     'http://demo.opengeo.org/geoserver/gwc/service/tms/1.0.0',
    ...     'http://osm.omniscale.net/proxy/tms/1.0.0',
    ...     'http://apps.esdi-humboldt.cz/mapproxy/tms/1.0.0',
    ...     'http://apps.esdi-humboldt.cz/cgi-bin/tilecache/tilecache.cgi/1.0.0',
    ... #    'http://tilecache.osgeo.org/wms-c/tilecache.py/1.0.0/',
    ...     'http://tileserver.maptiler.com/tms',
    ...     ]

# uncomment if you want to test all of the above
#    >>> for server in servers:
#    ...     service = tms.TileMapService(server)
#    ...     service.identification.title
#    ...     service.identification.version
#    ...     len(service.items())
#    ...     len(service.items('EPSG:900913'))
#    ...     len(service.items(profile='global-mercator'))
#    ...     len(service.items('EPSG:4326'))
#    ...     for  tm in service.contents.values():
#    ...         tm.title
#    ...         tm._tile_map == None
#    ...         tm.abstract
#    ...         tm._tile_map
#    ...         tm.srs
#    ...         tm.mimetype
#    ...         tm.extension
#    ...         tm.boundingBox
#    ...         tm.origin
#    ...         tm.type
