Exemple #1
0
def load(fp,
         expand_includes=True,
         include_position=False,
         include_comments=False,
         **kwargs):
    """
    Load a Mapfile from an open file or file-like object.

    Parameters
    ----------

    fp: file
        A file-like object - as with all Mapfiles this should be encoded in "utf-8"
    expand_includes: boolean
        Load any ``INCLUDE`` files in the MapFile
    include_comments: boolean
         Include or discard comment strings from the Mapfile - *experimental*
    include_position: boolean
         Include the position of the Mapfile tokens in the output

    Returns
    -------

    dict
        A Python dictionary representing the Mapfile in the mappyfile format

    Example
    -------

    To open a Mapfile from a file and return it as a dictionary object::

        with open('mymap.map') as fp:
            d = mappyfile.load(fp)

    Notes
    -----

    Partial Mapfiles can also be opened, for example a file containing a ``LAYER`` object.
    """
    p = Parser(expand_includes=expand_includes,
               include_comments=include_comments,
               **kwargs)
    ast = p.load(fp)
    m = MapfileToDict(include_position=include_position,
                      include_comments=include_comments,
                      **kwargs)
    d = m.transform(ast)
    return d
Exemple #2
0
def load(fp, expand_includes=True, include_position=False, include_comments=False):
    """
    Load a Mapfile from a file-like object

    :param fp: A file-like object
    :param boolean expand_includes: Load any ``INCLUDE`` files in the MapFile
    :param boolean include_comments: Include or discard comment strings from
                                     the Mapfile - *experimental*
    :param boolean include_position: Include the position of the Mapfile tokens in the output
    """
    p = Parser(expand_includes=expand_includes,
               include_comments=include_comments)
    ast = p.load(fp)
    m = MapfileToDict(include_position=include_position,
                      include_comments=include_comments)
    d = m.transform(ast)
    return d
Exemple #3
0
def load(fp,
         expand_includes=True,
         include_position=False,
         include_comments=False):
    """
    Load a Mapfile from a file-like object

    :param fp: A file-like object
    :param boolean expand_includes: Load any ``INCLUDE`` files in the MapFile
    :param boolean include_comments: Include or discard comment strings from
                                     the Mapfile - *experimental*
    :param boolean include_position: Include the position of the Mapfile tokens in the output
    """
    p = Parser(expand_includes=expand_includes,
               include_comments=include_comments)
    ast = p.load(fp)
    m = MapfileToDict(include_position=include_position,
                      include_comments=include_comments)
    d = m.transform(ast)
    return d