<commit_before>#!/usr/bin/env python

import os
import sys
import optparse
import cascadenik
import tempfile
import mapnik

try:
    import xml.etree.ElementTree as ElementTree
    from xml.etree.ElementTree import Element
except ImportError:
    try:
        import lxml.etree as ElementTree
        from lxml.etree import Element
    except ImportError:
        import elementtree.ElementTree as ElementTree
        from elementtree.ElementTree import Element

def main(file, **kwargs):
    """ Given an input layers file and a directory, print the compiled
        XML file to stdout and save any encountered external image files
        to the named directory.
    """
    mmap = mapnik.Map(1, 1)
    # allow [zoom] filters to work
    mmap.srs = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null'
    load_kwargs = dict([(k, v) for (k, v) in kwargs.items() if k in ('target_dir', 'move_local_files')])
    cascadenik.load_map(mmap, file, **load_kwargs)
    
    (handle, filename) = tempfile.mkstemp(suffix='.xml', prefix='cascadenik-mapnik-')
    os.close(handle)
    mapnik.save_map(mmap, filename)
    
    if kwargs.get('pretty'):
        doc = ElementTree.fromstring(open(filename, 'rb').read())
        print doc
        cascadenik._compile.indent(doc)
        f = open(filename, 'wb')
        doc.write(f)
        f.close()
        
    if kwargs.get('compiled'):
        os.rename(filename, kwargs['compiled'])
    else:
        print open(filename, 'r').read()
        os.unlink(filename)
    return 0

parser = optparse.OptionParser(usage="""%prog [options] <mml> <xml>""", version='%prog ' + cascadenik.VERSION)

parser.add_option('-d', '--dir', dest='target_dir',
                  default=None,<commit_msg>Fixed xml writing for stdlib etree<commit_after>#!/usr/bin/env python

import os
import sys
import optparse
import cascadenik
import tempfile
import mapnik

try:
    import xml.etree.ElementTree as ElementTree
    from xml.etree.ElementTree import Element
except ImportError:
    try:
        import lxml.etree as ElementTree
        from lxml.etree import Element
    except ImportError:
        import elementtree.ElementTree as ElementTree
        from elementtree.ElementTree import Element

def main(file, **kwargs):
    """ Given an input layers file and a directory, print the compiled
        XML file to stdout and save any encountered external image files
        to the named directory.
    """
    mmap = mapnik.Map(1, 1)
    # allow [zoom] filters to work
    mmap.srs = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null'
    load_kwargs = dict([(k, v) for (k, v) in kwargs.items() if k in ('target_dir', 'move_local_files')])
    cascadenik.load_map(mmap, file, **load_kwargs)
    
    (handle, filename) = tempfile.mkstemp(suffix='.xml', prefix='cascadenik-mapnik-')
    os.close(handle)
    mapnik.save_map(mmap, filename)
    
    if kwargs.get('pretty'):
        doc = ElementTree.fromstring(open(filename, 'rb').read())
        cascadenik._compile.indent(doc)
        f = open(filename, 'wb')
        ElementTree.ElementTree(doc).write(f)
        f.close()
        
    if kwargs.get('compiled'):
        os.rename(filename, kwargs['compiled'])
    else:
        print open(filename, 'r').read()
        os.unlink(filename)
    return 0

parser = optparse.OptionParser(usage="""%prog [options] <mml> <xml>""", version='%prog ' + cascadenik.VERSION)

parser.add_option('-d', '--dir', dest='target_dir',
                  default=None,
{'fraction_non_alphanumeric': 0.12632459564974902, 'fraction_numerical': 0.016174010039040714, 'mean_word_length': 3.108820160366552, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 13}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7110322', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1175, 'n_words': 302}