<commit_before>from wtforms.widgets import TextArea


def lat(pt):
    return getattr(pt, "lat", getattr(pt, "x", pt[0]))


def lng(pt):
    return getattr(pt, "lng", getattr(pt, "y", pt[1]))


class LeafletWidget(TextArea):
    """
        `Leaflet <http://leafletjs.com/>`_ styled map widget. Inherits from
        `TextArea` so that geographic data can be stored via the <textarea>
        (and edited there if the user's browser does not have Javascript).

        You must include leaflet.js, form.js and leaflet stylesheet for it to
        work. You also need leaflet.draw.js (and its stylesheet) for it to be
        editable.
    """
    def __init__(
            self, width=300, height=300, center=None,
            zoom=None, min_zoom=None, max_zoom=None, max_bounds=None):
        self.width = width
        self.height = height
        self.center = center
        self.zoom = zoom
        self.min_zoom = min_zoom
        self.max_zoom = max_zoom
        self.max_bounds = max_bounds

    def __call__(self, field, **kwargs):
        kwargs.setdefault('data-role', 'leaflet')
        gtype = getattr(field, "geometry_type", "GEOMETRY")
        kwargs.setdefault('data-geometry-type', gtype)

        # set optional values from constructor
        if not kwargs.has_key("data-width"):
            kwargs["data-width"] = self.width
        if not kwargs.has_key("data-height"):
            kwargs["data-height"] = self.height
        if self.center:
            kwargs["data-lat"] = lat(self.center)<commit_msg>Python 3 does not have .has-key on dicts<commit_after>from wtforms.widgets import TextArea


def lat(pt):
    return getattr(pt, "lat", getattr(pt, "x", pt[0]))


def lng(pt):
    return getattr(pt, "lng", getattr(pt, "y", pt[1]))


class LeafletWidget(TextArea):
    """
        `Leaflet <http://leafletjs.com/>`_ styled map widget. Inherits from
        `TextArea` so that geographic data can be stored via the <textarea>
        (and edited there if the user's browser does not have Javascript).

        You must include leaflet.js, form.js and leaflet stylesheet for it to
        work. You also need leaflet.draw.js (and its stylesheet) for it to be
        editable.
    """
    def __init__(
            self, width=300, height=300, center=None,
            zoom=None, min_zoom=None, max_zoom=None, max_bounds=None):
        self.width = width
        self.height = height
        self.center = center
        self.zoom = zoom
        self.min_zoom = min_zoom
        self.max_zoom = max_zoom
        self.max_bounds = max_bounds

    def __call__(self, field, **kwargs):
        kwargs.setdefault('data-role', 'leaflet')
        gtype = getattr(field, "geometry_type", "GEOMETRY")
        kwargs.setdefault('data-geometry-type', gtype)

        # set optional values from constructor
        if not "data-width" in kwargs:
            kwargs["data-width"] = self.width
        if not "data-height" in kwargs:
            kwargs["data-height"] = self.height
        if self.center:
            kwargs["data-lat"] = lat(self.center)
{'fraction_non_alphanumeric': 0.1149200130590924, 'fraction_numerical': 0.00555011426705844, 'mean_word_length': 2.497716894977169, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2629962', 'n_tokens_mistral': 958, 'n_tokens_neox': 924, 'n_words': 270}