Example #1
0
def application(environ, start_response):
    """
    Developing locally?

        gunicorn -b 0.0.0.0:7000 -w 12 -k sync -t 90 --max-requests 5000 \
            -n gunicorn-theme_update services.wsgi.theme_update:application

    """

    status = '200 OK'
    with statsd.timer('services.theme_update'):
        try:
            locale, id_ = url_re.match(environ['PATH_INFO']).groups()
            locale = (locale or 'en-US').lstrip('/')
            id_ = int(id_)
        except AttributeError:  # URL path incorrect.
            start_response('404 Not Found', [])
            return ['']

        try:
            update = ThemeUpdate(locale, id_, environ.get('QUERY_STRING'))
            output = update.get_json()
            if not output:
                start_response('404 Not Found', [])
                return ['']
            start_response(status, update.get_headers(len(output)))
        except Exception:
            log_exception(environ['PATH_INFO'])
            raise

    return [output]
Example #2
0
def application(environ, start_response):
    """
    Developing locally?

        gunicorn -b 0.0.0.0:7000 -w 12 -k sync -t 90 --max-requests 5000 \
            -n gunicorn-theme_update services.wsgi.theme_update:application

    """

    status = '200 OK'
    with statsd.timer('services.theme_update'):
        try:
            locale, id_ = url_re.match(environ['PATH_INFO']).groups()
            locale = (locale or 'en-US').lstrip('/')
            id_ = int(id_)
        except AttributeError:  # URL path incorrect.
            start_response('404 Not Found', [])
            return ['']

        try:
            update = ThemeUpdate(locale, id_, environ.get('QUERY_STRING'))
            output = update.get_json()
            if not output:
                start_response('404 Not Found', [])
                return ['']
            start_response(status, update.get_headers(len(output)))
        except Exception:
            log_exception(environ['PATH_INFO'])
            raise

    return [output]
Example #3
0
def application(environ, start_response):
    """
    Developing locally?

        gunicorn -b 0.0.0.0:7000 -w 12 -k sync -t 90 --max-requests 5000 \
            -n gunicorn-theme_update services.wsgi.theme_update:application

    """

    status = "200 OK"
    with statsd.timer("services.theme_update"):
        data = environ["wsgi.input"].read()
        try:
            locale, id_ = url_re.match(environ["PATH_INFO"]).groups()
            locale = (locale or "en-US").lstrip("/")
            id_ = int(id_)
        except AttributeError:  # URL path incorrect.
            start_response("404 Not Found", [])
            return [""]

        try:
            update = ThemeUpdate(locale, id_, environ.get("QUERY_STRING"))
            output = update.get_json()
            if not output:
                start_response("404 Not Found", [])
                return [""]
            start_response(status, update.get_headers(len(output)))
        except:
            log_exception(environ["PATH_INFO"])
            raise

    return [output]
Example #4
0
    def base64_icon(self, addon_id):
        path = self.image_path('icon.jpg')
        if not os.path.isfile(path):
            return ''

        try:
            with open(path, 'r') as f:
                return base64.b64encode(f.read())
        except IOError, e:
            if len(e.args) == 1:
                log_exception('I/O error: {0}'.format(e[0]))
            else:
                log_exception('I/O error({0}): {1}'.format(e[0], e[1]))
            return ''
Example #5
0
    def base64_icon(self, addon_id):
        path = self.image_path('icon.jpg')
        if not os.path.isfile(path):
            return ''

        try:
            with open(path, 'r') as f:
                return base64.b64encode(f.read())
        except IOError, e:
            if len(e.args) == 1:
                log_exception('I/O error: {0}'.format(e[0]))
            else:
                log_exception('I/O error({0}): {1}'.format(e[0], e[1]))
            return ''
Example #6
0
def application(environ, start_response):
    """
    Developing locally?

        gunicorn -b 0.0.0.0:7000 -w 12 -k sync -t 90 --max-requests 5000 \
            -n gunicorn-theme_update services.wsgi.theme_update:application

    """

    status = '200 OK'
    with statsd.timer('services.theme_update'):
        try:
            locale, id_ = url_re.match(environ['PATH_INFO']).groups()
            locale = (locale or 'en-US').lstrip('/')
            id_ = int(id_)
        except AttributeError:  # URL path incorrect.
            start_response('404 Not Found', [])
            return ['']

        try:
            query_string = environ.get('QUERY_STRING')
            update = MigratedUpdate(locale, id_, query_string)
            is_migrated = update.is_migrated
            user_agent_string = environ.get('HTTP_USER_AGENT')
            update_log.info(
                "HTTP_USER_AGENT %s; is_migrated: %s, is_android_ua: %s",
                user_agent_string, is_migrated,
                is_android_ua(user_agent_string))
            if not is_migrated:
                update = LWThemeUpdate(locale, id_, query_string)
            elif is_android_ua(user_agent_string):
                update = None
            output = update.get_json() if update else None
            if not output:
                start_response('404 Not Found', [])
                return ['']
            start_response(status, update.get_headers(len(output)))
        except Exception:
            log_exception(environ['PATH_INFO'])
            raise

    return [output]
Example #7
0
def application(environ, start_response):
    """
    Developing locally?

        gunicorn -b 0.0.0.0:7000 -w 12 -k sync -t 90 --max-requests 5000 \
            -n gunicorn-theme_update services.wsgi.theme_update:application

    """

    with statsd.timer('services.theme_update'):
        try:
            locale, id_ = url_re.match(environ['PATH_INFO']).groups()
            locale = (locale or 'en-US').lstrip('/')
            id_ = int(id_)
        except AttributeError:  # URL path incorrect.
            start_response('404 Not Found', [])
            return ['']

        try:
            query_string = environ.get('QUERY_STRING')
            update = MigratedUpdate(locale, id_, query_string)
            is_migrated = update.is_migrated
            if is_migrated:
                output = (
                    update.get_json() if settings.MIGRATED_LWT_UPDATES_ENABLED
                    else None)
            else:
                update = LWThemeUpdate(locale, id_, query_string)
                output = update.get_json()

            if not output:
                start_response('404 Not Found', [])
                return ['']
            start_response('200 OK', update.get_headers(len(output)))
        except Exception:
            log_exception(environ['PATH_INFO'])
            raise

    return [output.encode('utf-8')]
Example #8
0
def application(environ, start_response):
    """
    Developing locally?

        gunicorn -b 0.0.0.0:7000 -w 12 -k sync -t 90 --max-requests 5000 \
            -n gunicorn-theme_update services.wsgi.theme_update:application

    """

    with statsd.timer('services.theme_update'):
        try:
            locale, id_ = url_re.match(environ['PATH_INFO']).groups()
            locale = (locale or 'en-US').lstrip('/')
            id_ = int(id_)
        except AttributeError:  # URL path incorrect.
            start_response('404 Not Found', [])
            return ['']

        try:
            query_string = environ.get('QUERY_STRING')
            update = MigratedUpdate(locale, id_, query_string)
            is_migrated = update.is_migrated
            if is_migrated:
                output = (update.get_json()
                          if settings.MIGRATED_LWT_UPDATES_ENABLED else None)
            else:
                update = LWThemeUpdate(locale, id_, query_string)
                output = update.get_json()

            if not output:
                start_response('404 Not Found', [])
                return ['']
            start_response('200 OK', update.get_headers(len(output)))
        except Exception:
            log_exception(environ['PATH_INFO'])
            raise

    return [output.encode('utf-8')]