# Path: TileStache/Core.py
# class KnownUnknown(Exception):
#     """ There are known unknowns. That is to say, there are things that we now know we don't know.
# 
#         This exception gets thrown in a couple places where common mistakes are made.
#     """
#     pass


import json
import os
    import mapnik
from os.path import exists
from TileStache.Core import KnownUnknown
from TileStache.Geography import getProjectionByName
    from urllib.parse import urljoin, urlparse
    from urlparse import urljoin, urlparse
from tempfile import mkstemp
from urllib import urlopen
        # extract a gridview excluding the buffer
        grid_view = grid.view(self.buffer, self.buffer, width, height)
        # then encode the grid array as utf, resample to 1/scale the size, and dump features
        grid_utf = grid_view.encode('utf', resolution=self.scale, add_features=True)

        if self.wrapper is None:
            return SaveableResponse(json.dumps(grid_utf))
        else:
            return SaveableResponse(self.wrapper + '(' + json.dumps(grid_utf) + ')')

    def getTypeByExtension(self, extension):
        """ Get mime-type and format by file extension.

            This only accepts "json".
        """
        if extension.lower() != 'json':
            raise KnownUnknown('MapnikGrid only makes .json tiles, not "%s"' % extension)

        return 'application/json; charset=utf-8', 'JSON'

class SaveableResponse:
    """ Wrapper class for JSON response that makes it behave like a PIL.Image object.

        TileStache.getTile() expects to be able to save one of these to a buffer.
    """
    def __init__(self, content):
        self.content = content

    def save(self, out, format):
        if format != 'JSON':

# Path: TileStache/Core.py
# class KnownUnknown(Exception):
#     """ There are known unknowns. That is to say, there are things that we now know we don't know.
# 
#         This exception gets thrown in a couple places where common mistakes are made.
#     """
#     pass


# Path: TileStache/Goodies/Providers/MapnikGrid.py
import json
import os
    import mapnik
from os.path import exists
from TileStache.Core import KnownUnknown
from TileStache.Geography import getProjectionByName
    from urllib.parse import urljoin, urlparse
    from urlparse import urljoin, urlparse
from tempfile import mkstemp
from urllib import urlopen

        # extract a gridview excluding the buffer
        grid_view = grid.view(self.buffer, self.buffer, width, height)
        # then encode the grid array as utf, resample to 1/scale the size, and dump features
        grid_utf = grid_view.encode('utf', resolution=self.scale, add_features=True)

        if self.wrapper is None:
            return SaveableResponse(json.dumps(grid_utf))
        else:
            return SaveableResponse(self.wrapper + '(' + json.dumps(grid_utf) + ')')

    def getTypeByExtension(self, extension):
        """ Get mime-type and format by file extension.

            This only accepts "json".
        """
        if extension.lower() != 'json':
            raise KnownUnknown('MapnikGrid only makes .json tiles, not "%s"' % extension)

        return 'application/json; charset=utf-8', 'JSON'

class SaveableResponse:
    """ Wrapper class for JSON response that makes it behave like a PIL.Image object.

        TileStache.getTile() expects to be able to save one of these to a buffer.
    """
    def __init__(self, content):
        self.content = content

    def save(self, out, format):
        if format != 'JSON':

            raise KnownUnknown('MapnikGrid only saves .json tiles, not "%s"' % format)