コード例 #1
0
    def get_handler(self, *args, **options):
        """
        Entry point to plug the bsync feature.
        """
        try:
            env = load_env()
        except IOError:
            env = {}

        # XXX: In Django 1.8 this changes to:
        # if 'PORT' in env and not options.get('addrport'):
        #     options['addrport'] = env['PORT']

        if 'PORT' in env and not args:
            args = (env['PORT'],)

        # We're subclassing runserver, which spawns threads for its
        # autoreloader with RUN_MAIN set to true, we have to check for
        # this to avoid running gulp twice.
        if not os.getenv('RUN_MAIN', False):
            pool = ThreadPoolExecutor(max_workers=1)

            gulp_thread = pool.submit(self.start_gulp)
            gulp_thread.add_done_callback(self.gulp_exited_cb)

        handler = super(Command, self).get_handler(*args, **options)
        
        if options['use_bsync']:
            self.bsync_request(**options)
        return handler
コード例 #2
0
def test_load_env_defaults():
    """
    Test loading the default .env file.
    """
    env = load_env()

    assert_env(env)
コード例 #3
0
ファイル: runserver_mixin.py プロジェクト: poiedk/django-gulp
    def handle(self, *args, **options):
        try:
            env = load_env()
        except IOError:
            env = {}

        # XXX: In Django 1.8 this changes to:
        # if 'PORT' in env and not options.get('addrport'):
        #     options['addrport'] = env['PORT']

        if 'PORT' in env and not args:
            args = (env['PORT'],)

        # We're subclassing runserver, which spawns threads for its
        # autoreloader with RUN_MAIN set to true, we have to check for
        # this to avoid running gulp twice.
        if not os.getenv('RUN_MAIN', False):
            pool = ThreadPoolExecutor(max_workers=1)

            gulp_thread = pool.submit(self.start_gulp)
            gulp_thread.add_done_callback(self.gulp_exited_cb)

        return super(RunserverMixin, self).handle(*args, **options)
コード例 #4
0
class SanitizeEnvProcessor(Processor):
    """
    Sanitize the environment to prevent leaking data like credit cards and
    passwords.
    """

    MASK = '*' * 8
    FIELDS = []

    try:
        env = load_env()

        if env:
            FIELDS = [k for k, _ in env]
    except IOError:
        pass

    VALUES_RE = re.compile(r'^(?:\d[ -]*?){13,16}$')

    def sanitize(self, key, value):
        if value is None:
            return

        if not key:  # key can be a NoneType
            return value

        key = key.lower()

        for field in self.FIELDS:
            if field in key:
                # store mask as a fixed length for security
                return self.MASK

        return value

    def filter_stacktrace(self, data):
        for frame in data.get('frames', []):
            if 'vars' not in frame:
                continue

            frame['vars'] = varmap(self.sanitize, frame['vars'])

    def filter_http(self, data):
        for n in ('data', 'cookies', 'headers', 'env', 'query_string'):
            if n not in data:
                continue

            if isinstance(data[n], six.string_types) and '=' in data[n]:
                # at this point we've assumed it's a standard HTTP query
                querybits = []

                for bit in data[n].split('&'):
                    chunk = bit.split('=')
                    if len(chunk) == 2:
                        querybits.append((chunk[0], self.sanitize(*chunk)))
                    else:
                        querybits.append(chunk)

                data[n] = '&'.join('='.join(k) for k in querybits)
            else:
                data[n] = varmap(self.sanitize, data[n])