Exemple #1
0
 def __init__(self, request, context=None):
     logger.debug("mobilejp __init__ start")
     #logger.debug(request)
     logger.debug("mobilejp __init__ end")
     user_agent = request.META.get('HTTP_USER_AGENT', '')
     web_user_agent = request.REQUEST.get('X-GREE-User-Agent', '')
     self._featurephone_check(request, context)
     self._smartphone_check(user_agent)
     self._pc_check()
     self._webview_check(web_user_agent, request)
Exemple #2
0
    def process_request(self, request):
        logger.debug('emoji_request')
        assert hasattr(request, 'device'), "The mobilejp emoji middleware requires User-Agent middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'mobilejp.middleware.mobile.UserAgentMobileMiddleware'."

        device = request.device
        if device.is_ezweb:
            request.encoding = 'x_sjis_kddi'
        elif device.is_softbank:
            request.encoding = 'x_utf8_softbank'
        elif device.is_docomo:
            # docomo, willcom, nonmobile
            request.encoding = 'x_sjis_docomo'
Exemple #3
0
    def process_request(self, request):
        logger.debug('emoji_request')
        assert hasattr(
            request, 'device'
        ), "The mobilejp emoji middleware requires User-Agent middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'mobilejp.middleware.mobile.UserAgentMobileMiddleware'."

        device = request.device
        if device.is_ezweb:
            request.encoding = 'x_sjis_kddi'
        elif device.is_softbank:
            request.encoding = 'x_utf8_softbank'
        elif device.is_docomo:
            # docomo, willcom, nonmobile
            request.encoding = 'x_sjis_docomo'
Exemple #4
0
    def process_response(self, request, response):
        logger.debug('emoji_response')
        if not request.device.is_featurephone:
            return response

        try:
            content_type = response['content-type']
        except KeyError:
            return response

        if (not content_type.startswith('text/html')
                and not content_type.startswith('application/xhtml+xml')):
            return response

        if request.device.is_docomo:
            # override content type
            content_type = 'application/xhtml+xml'

        if request.device.is_softbank and request.encoding == 'x_utf8_softbank':
            response._headers['content-type'] = ('Content-Type',
                                                 '%s; charset=UTF-8' %
                                                 content_type.split(";", 1)[0])
        else:
            response._headers['content-type'] = ('Content-Type',
                                                 '%s; charset=Shift_JIS' %
                                                 content_type.split(";", 1)[0])

        charset = request.encoding

        str_content = smart_str(''.join(response._container).strip(),
                                charset,
                                errors='xmlcharrefreplace')
        str_content = to_str(str_content, charset)
        content = str_content.decode(charset)

        #        print "process_response------0"
        #        print content
        #        print "process_response------1"
        #        if request.device.is_softbank():
        #            content = EMOJI_RE.sub(emoji_repl, content)

        response._charset = charset
        response.content = content

        return response
Exemple #5
0
    def process_response(self, request, response):

        if not request.path.startswith("/m/"):
            return response

        d = datetime.datetime.now()

        content_type = response.get('Content-Type', "")
        if ((not content_type.startswith('text/html')
             and not content_type.startswith('application/xhtml+xml'))
                or response.status_code != 200):
            return response

        content = response.content

        if not content:
            return response

        device = request.device
        if device.is_nonmobile():
            return response

        c = CssInclude()

        if device.is_docomo():
            c.setAgentDocomo()
        elif device.is_softbank():
            c.setAgentSoftBank()
        elif device.is_ezweb():
            c.setAgentAu()

        if request.device.display.is_vga():
            c.setVga()

        content = c.apply(content)

        response.content = content

        dd = datetime.datetime.now()
        r = dd - d
        logger.debug('(%s/%s)' % (r.seconds, r.microseconds))

        return response
Exemple #6
0
    def process_response(self, request, response):

        if not request.path.startswith("/m/"):
            return response

        d = datetime.datetime.now()
        
        content_type = response.get('Content-Type',"")
        if ((not content_type.startswith('text/html') and
             not content_type.startswith('application/xhtml+xml')) or
            response.status_code != 200):
            return response
        
        content = response.content
        
        if not content:
            return response

        device = request.device
        if device.is_nonmobile():
            return response

        c = CssInclude()
        
        if device.is_docomo():
            c.setAgentDocomo()
        elif device.is_softbank():
            c.setAgentSoftBank()
        elif device.is_ezweb():
            c.setAgentAu()

        if request.device.display.is_vga():
            c.setVga()
                    
        content = c.apply(content)
        
        response.content = content

        dd = datetime.datetime.now()
        r = dd - d
        logger.debug('(%s/%s)' % (r.seconds, r.microseconds))

        return response
Exemple #7
0
    def process_response(self, request, response):
        logger.debug('emoji_response')
        if not request.device.is_featurephone:
            return response

        try:
            content_type = response['content-type']
        except KeyError:
            return response

        if (not content_type.startswith('text/html') and
            not content_type.startswith('application/xhtml+xml')):
            return response

        if request.device.is_docomo:
            # override content type
            content_type = 'application/xhtml+xml'

        if request.device.is_softbank and request.encoding == 'x_utf8_softbank':
            response._headers['content-type'] = ('Content-Type',
                                             '%s; charset=UTF-8' % content_type.split(";", 1)[0])
        else:
            response._headers['content-type'] = ('Content-Type',
                                             '%s; charset=Shift_JIS' % content_type.split(";", 1)[0])

        charset = request.encoding

        str_content = smart_str(''.join(response._container).strip(), charset, errors='xmlcharrefreplace')
        str_content = to_str(str_content, charset)
        content = str_content.decode(charset)
        
#        print "process_response------0"
#        print content
#        print "process_response------1"
#        if request.device.is_softbank():
#            content = EMOJI_RE.sub(emoji_repl, content)

        response._charset = charset
        response.content = content

        return response
Exemple #8
0
    def process_response(self, request, response):
        logger.debug("strip_response")

        if not request.path.startswith("/m/"):
            return response

        content_type = response.get('Content-Type', "")
        if ((not content_type.startswith('text/html') and
             not content_type.startswith('application/xhtml+xml')) or
                response.status_code != 200):
            return response

        content = response.content

        if not content:
            return response

        content = _strip(content)

        response.content = content
        return response
Exemple #9
0
    def process_response(self, request, response):
        logger.debug("strip_response")

        if not request.path.startswith("/m/"):
            return response

        content_type = response.get('Content-Type', "")
        if ((not content_type.startswith('text/html')
             and not content_type.startswith('application/xhtml+xml'))
                or response.status_code != 200):
            return response

        content = response.content

        if not content:
            return response

        content = _strip(content)

        response.content = content
        return response
Exemple #10
0
    def process_response(self, request, response):
        logger.debug('qvga_size_response')

        if not request.path.startswith("/m/"):
            return response

        content_type = response.get('Content-Type', "")
        if not content_type.startswith("text/html"):
            return response

        if not hasattr(request, 'device'):
            return response

        if not hasattr(request.device.detect, 'display'):
            return response

        if not request.device.detect.display.is_vga():
            return response

        #VGA対応端末なので適用
        content = response.content
        response.content = _replace_html(content)
        return response
Exemple #11
0
    def _webview_check(self, user_agent, request):
        """
        UserAgent情報からWebView式別などを行う
        """
        logger.debug("mobilejp _webview_check start")
        logger.debug("mobilejp useragent: %s" % user_agent)
        logger.debug("mobilejp check webview %s" % WEBVIEW_RE.search(user_agent))
        logger.debug("mobilejp check session:: %s" % request.session.get('is_webview'))
        logger.debug("mobilejp check session items:: %s" % request.session.items())
        logger.debug("mobilejp _webview_check end")

        if WEBVIEW_RE.search(user_agent) or request.session.get('is_webview'):
            self.is_webview = True