<commit_before>import simplejson as json
import types
import urlparse

import appvalidator.python.copy as copy

from ..constants import DESCRIPTION_TYPES
from ..specprocessor import Spec, LITERAL_TYPE


# This notably excludes booleans.
JSON_LITERALS = types.StringTypes + (int, float)

BANNED_ORIGINS = [
    "gaiamobile.org",
    "mozilla.com",
    "mozilla.org",
]

STYLEGUIDE_URL = "http://www.mozilla.org/styleguide/products/firefox-os/"

_FULL_PERMISSIONS = ("readonly", "readwrite", "readcreate", "createonly")

FXOS_ICON_SIZES = (60, 90, 120)

FILTER_DEF_OBJ = {
    "expected_type": dict,
    "not_empty": True,
    "child_nodes": {
        "required": {"expected_type": bool},
        "value": {
            "expected_type": JSON_LITERALS + (list, tuple),
            "not_empty": True,
            "child_nodes": {"expected_type": JSON_LITERALS},
        },
        "min": {"expected_type": (int, float)},
        "max": {"expected_type": (int, float)},
        "pattern": {"expected_type": types.StringTypes},
        "regexp": {"expected_type": types.StringTypes},  # FXOS 1.0/1.1
        "patternFlags": {
            "expected_type": types.StringTypes,
            "max_length": 4,
            "value_matches": "[igmy]+",
        },
    },
}
FILTER_DEF_OBJ["allowed_once_nodes"] = FILTER_DEF_OBJ["child_nodes"].keys()

WEB_ACTIVITY_HANDLER = {
    "href": {"expected_type": types.StringTypes,
             "process": lambda s: s.process_act_href,
             "not_empty": True},
    "disposition": {"expected_type": types.StringTypes,
                    "values": ["window", "inline"]},
    "filters": {
        "expected_type": dict,
        "allowed_nodes": ["*"],
        "not_empty": True,
        "child_nodes": {
            "*": {
                "expected_type": JSON_LITERALS + (list, dict),
                "not_empty": True,
                "process": lambda s: s.process_act_filter,
            }
        },
    },
    "returnValue": {"expected_type": bool},
}


class WebappSpec(Spec):
    """This object parses and subsequently validates webapp manifest files."""

    SPEC_NAME = "Web App Manifest"
    MORE_INFO = ("You can find more information at "
                 "https://developer.mozilla.org/docs/Web/Apps/Manifest")
    MIN_REQUIRED_ICON_SIZE = 128

    PERMISSIONS = (
        "alarms", "attention", "audio-channel-normal", "audio-channel-content",
        "audio-channel-notification", "audio-channel-alarm",
        "audio-channel-ringer", "audio-channel-telephony",
        "audio-channel-publicnotification", "background-sensors",
        "backgroundservice", "bluetooth", "browser", "camera", "contacts",
        "desktop-notification", "device-storage:apps", "device-storage:music",
        "device-storage:pictures", "device-storage:sdcard",
        "device-storage:videos", "embed-apps", "fmradio", "geolocation",
        "idle", "keyboard", "mobileconnection", "mobilenetwork",
        "network-events", "networkstats-manage", "open-remote-window",
        "permissions", "power", "push", "settings", "sms", "storage",
        "systemXHR", "tcp-socket", "telephony", "time", "voicemail",
        "webapps-manage", "wifi-manage")
    PERMISSIONS_ACCESS = {
        "contacts": _FULL_PERMISSIONS,
        "device-storage:apps": _FULL_PERMISSIONS,
        "device-storage:music": _FULL_PERMISSIONS,
        "device-storage:pictures": _FULL_PERMISSIONS,
        "device-storage:sdcard": _FULL_PERMISSIONS,
        "device-storage:videos": _FULL_PERMISSIONS,
        "settings": ("readonly", "readwrite"),
    }

    SPEC = {
        "expected_type": dict,
        "required_nodes": ["name", "description", "developer"],
        "required_nodes_when": {"default_locale": lambda n: "locales" in n},<commit_msg>Add audio-capture permission (bug 947239)<commit_after>import simplejson as json
import types
import urlparse

import appvalidator.python.copy as copy

from ..constants import DESCRIPTION_TYPES
from ..specprocessor import Spec, LITERAL_TYPE


# This notably excludes booleans.
JSON_LITERALS = types.StringTypes + (int, float)

BANNED_ORIGINS = [
    "gaiamobile.org",
    "mozilla.com",
    "mozilla.org",
]

STYLEGUIDE_URL = "http://www.mozilla.org/styleguide/products/firefox-os/"

_FULL_PERMISSIONS = ("readonly", "readwrite", "readcreate", "createonly")

FXOS_ICON_SIZES = (60, 90, 120)

FILTER_DEF_OBJ = {
    "expected_type": dict,
    "not_empty": True,
    "child_nodes": {
        "required": {"expected_type": bool},
        "value": {
            "expected_type": JSON_LITERALS + (list, tuple),
            "not_empty": True,
            "child_nodes": {"expected_type": JSON_LITERALS},
        },
        "min": {"expected_type": (int, float)},
        "max": {"expected_type": (int, float)},
        "pattern": {"expected_type": types.StringTypes},
        "regexp": {"expected_type": types.StringTypes},  # FXOS 1.0/1.1
        "patternFlags": {
            "expected_type": types.StringTypes,
            "max_length": 4,
            "value_matches": "[igmy]+",
        },
    },
}
FILTER_DEF_OBJ["allowed_once_nodes"] = FILTER_DEF_OBJ["child_nodes"].keys()

WEB_ACTIVITY_HANDLER = {
    "href": {"expected_type": types.StringTypes,
             "process": lambda s: s.process_act_href,
             "not_empty": True},
    "disposition": {"expected_type": types.StringTypes,
                    "values": ["window", "inline"]},
    "filters": {
        "expected_type": dict,
        "allowed_nodes": ["*"],
        "not_empty": True,
        "child_nodes": {
            "*": {
                "expected_type": JSON_LITERALS + (list, dict),
                "not_empty": True,
                "process": lambda s: s.process_act_filter,
            }
        },
    },
    "returnValue": {"expected_type": bool},
}


class WebappSpec(Spec):
    """This object parses and subsequently validates webapp manifest files."""

    SPEC_NAME = "Web App Manifest"
    MORE_INFO = ("You can find more information at "
                 "https://developer.mozilla.org/docs/Web/Apps/Manifest")
    MIN_REQUIRED_ICON_SIZE = 128

    PERMISSIONS = (
        "alarms", "attention", "audio-capture", "audio-channel-normal",
        "audio-channel-content", "audio-channel-notification",
        "audio-channel-alarm", "audio-channel-ringer", "audio-channel-telephony",
        "audio-channel-publicnotification", "background-sensors",
        "backgroundservice", "bluetooth", "browser", "camera", "contacts",
        "desktop-notification", "device-storage:apps", "device-storage:music",
        "device-storage:pictures", "device-storage:sdcard",
        "device-storage:videos", "embed-apps", "fmradio", "geolocation",
        "idle", "keyboard", "mobileconnection", "mobilenetwork",
        "network-events", "networkstats-manage", "open-remote-window",
        "permissions", "power", "push", "settings", "sms", "storage",
        "systemXHR", "tcp-socket", "telephony", "time", "voicemail",
        "webapps-manage", "wifi-manage")
    PERMISSIONS_ACCESS = {
        "contacts": _FULL_PERMISSIONS,
        "device-storage:apps": _FULL_PERMISSIONS,
        "device-storage:music": _FULL_PERMISSIONS,
        "device-storage:pictures": _FULL_PERMISSIONS,
        "device-storage:sdcard": _FULL_PERMISSIONS,
        "device-storage:videos": _FULL_PERMISSIONS,
        "settings": ("readonly", "readwrite"),
    }

    SPEC = {
        "expected_type": dict,
        "required_nodes": ["name", "description", "developer"],
        "required_nodes_when": {"default_locale": lambda n: "locales" in n},
{'fraction_non_alphanumeric': 0.15605559232296493, 'fraction_numerical': 0.004765056254136334, 'mean_word_length': 3.0021186440677967, 'pattern_counts': {'":': 102, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '216980', 'n_tokens_mistral': 2464, 'n_tokens_neox': 2338, 'n_words': 452}