# Path: TileStache/py3_compat.py
# def is_string_type(val):
# 
# Path: TileStache/py3_compat.py
# def is_string_type(val):
# 
# 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


from time import time
from os.path import exists
from itertools import count
from glob import glob
from tempfile import mkstemp
from .py3_compat import reduce, urlopen, urljoin, urlparse, allocate_lock
from .py3_compat import unichr
from TileStache.Core import KnownUnknown
from TileStache.Geography import getProjectionByName
    from PIL import Image
import os
import logging
import json
    import mapnik
    import Image
    #

    offset, outgrid = len(grid1['keys']), []

    def newchar(char1, char2):
        """ Return a new encoded character based on two inputs.
        """
        id1, id2 = decode_char(char1), decode_char(char2)

        if grid2['keys'][id2] == '':
            # transparent pixel, use the bottom character
            return encode_id(id1)

        else:
            # opaque pixel, use the top character
            return encode_id(id2 + offset)

    for (row1, row2) in zip(grid1['grid'], grid2['grid']):
        outrow = [newchar(c1, c2) for (c1, c2) in zip(row1, row2)]
        outgrid.append(''.join(outrow))

    return dict(keys=outkeys, data=outdata, grid=outgrid)

def encode_id(id):
    id += 32
    if id >= 34:
        id = id + 1
    if id >= 92:
        id = id + 1
    if id > 127:

# Path: TileStache/py3_compat.py
# def is_string_type(val):
# 
# Path: TileStache/py3_compat.py
# def is_string_type(val):
# 
# 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/Mapnik.py
from time import time
from os.path import exists
from itertools import count
from glob import glob
from tempfile import mkstemp
from .py3_compat import reduce, urlopen, urljoin, urlparse, allocate_lock
from .py3_compat import unichr
from TileStache.Core import KnownUnknown
from TileStache.Geography import getProjectionByName
    from PIL import Image
import os
import logging
import json
    import mapnik
    import Image

    #

    offset, outgrid = len(grid1['keys']), []

    def newchar(char1, char2):
        """ Return a new encoded character based on two inputs.
        """
        id1, id2 = decode_char(char1), decode_char(char2)

        if grid2['keys'][id2] == '':
            # transparent pixel, use the bottom character
            return encode_id(id1)

        else:
            # opaque pixel, use the top character
            return encode_id(id2 + offset)

    for (row1, row2) in zip(grid1['grid'], grid2['grid']):
        outrow = [newchar(c1, c2) for (c1, c2) in zip(row1, row2)]
        outgrid.append(''.join(outrow))

    return dict(keys=outkeys, data=outdata, grid=outgrid)

def encode_id(id):
    id += 32
    if id >= 34:
        id = id + 1
    if id >= 92:
        id = id + 1
    if id > 127:

        return unichr(id)