<commit_before>__author__ = 'katharine'

import PyV8 as v8
from geolocation import Geolocation


class Navigator(v8.JSClass):
    def __init__(self, runtime):
        # W3C spec says that if geolocation is disabled, navigator.geolocation should not exist.
        # if 'location' in runtime.manifest.get('capabilities', []):
        if True:
            self.geolocation = Geolocation(runtime)<commit_msg>Implement location restriction more thoroughly.<commit_after>__author__ = 'katharine'

import PyV8 as v8
from geolocation import Geolocation
from javascript.exceptions import JSRuntimeException

class Navigator(v8.JSClass):
    def __init__(self, runtime):
        self._runtime = runtime
        # W3C spec says that if geolocation is disabled, navigator.geolocation should not exist.
        if 'location' in runtime.manifest.get('capabilities', []):
            self.geolocation = Geolocation(runtime)

    def __getattr__(self, item):
        # __getattr__ is only called if something does not exist. Therefore, if it's called, geolocation
        # does not exist.
        # This approach lets us report it doesn't exist if tested for (e.g. `'geolocation' in navigator`),
        # but throw an informative exception if it's accessed.
        if item == 'geolocation':
            raise JSRuntimeException(
                self._runtime,
                "You must add 'location' to the appinfo.json capabilities array to access geolocation."
            )
        else:
            raise AttributeError

{'fraction_non_alphanumeric': 0.0760079312623926, 'fraction_numerical': 0.005287508261731659, 'mean_word_length': 2.9121447028423773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3723699', 'n_tokens_mistral': 419, 'n_tokens_neox': 406, 'n_words': 141}