Esempio n. 1
0
 def process_response(self, request, response):
     if response.status_code < 400 and settings.REQUEST_ONLY_ERRORS:
         return response
     
     allow = patterns(True, *settings.REQUEST_ALLOW_PATHS)
     if not allow.resolve(request.path[1:]):
         return response
     
     ignore = patterns(False, *settings.REQUEST_IGNORE_PATHS)
     if ignore.resolve(request.path[1:]):
         return response
     
     if request.is_ajax() and settings.REQUEST_IGNORE_AJAX:
         return response
     
     if request.META.get('REMOTE_ADDR') in settings.REQUEST_IGNORE_IP:
         return response
     
     if getattr(request, 'user', False):
         if request.user.username in settings.REQUEST_IGNORE_USERNAME:
             return response
     
     r = Request()
     r.from_http_request(request, response)
     
     return response
Esempio n. 2
0
    def process_response(self, request, response):
        if request.method.lower() not in settings.REQUEST_VALID_METHOD_NAMES:
            return response

        if response.status_code < 400 and settings.REQUEST_ONLY_ERRORS:
            return response

        ignore = patterns(False, *settings.REQUEST_IGNORE_PATHS)
        if ignore.resolve(request.path[1:]):
            return response

        if request.is_ajax() and settings.REQUEST_IGNORE_AJAX:
            return response

        if request.META.get('REMOTE_ADDR') in settings.REQUEST_IGNORE_IP:
            return response

        ignore = patterns(False, *settings.REQUEST_IGNORE_USER_AGENTS)
        if ignore.resolve(request.META.get('HTTP_USER_AGENT', '')):
            return response

        if getattr(request, 'user', False):
            if request.user.username in settings.REQUEST_IGNORE_USERNAME:
                return response

        r = Request()
        r.from_http_request(request, response)

        return response
    def process_response(self, request, response):
        if request.method.lower() not in settings.REQUEST_VALID_METHOD_NAMES:
            return response

        if response.status_code < 400 and settings.REQUEST_ONLY_ERRORS:
            return response

        ignore = patterns(False, *settings.REQUEST_IGNORE_PATHS)
        if ignore.resolve(request.path[1:]):
            return response

        if request.is_ajax() and settings.REQUEST_IGNORE_AJAX:
            return response

        if request.META.get('REMOTE_ADDR') in settings.REQUEST_IGNORE_IP:
            return response

        ignore = patterns(False, *settings.REQUEST_IGNORE_USER_AGENTS)
        if ignore.resolve(request.META.get('HTTP_USER_AGENT', '')):
            return response

        if getattr(request, 'user', False):
            if request.user.username in settings.REQUEST_IGNORE_USERNAME:
                return response

        r = Request()
        r.from_http_request(request, response)

        return response
Esempio n. 4
0
    def test_named_patterns(self):
        named = patterns(False, (r'^/admin/$', 'name'))
        self.assertEqual(named.resolve('/admin/'),
                         ('name', {}))
        self.assertEqual(named.resolve('/login'),
                         False)

        named = patterns(False, [r'^/admin/$', 'name'])
        self.assertEqual(named.resolve('/admin/'),
                         ('name', {}))
        self.assertEqual(named.resolve('/login'),
                         False)
Esempio n. 5
0
    def process_response(self, request, response):
        if response.status_code < 400 and settings.REQUEST_ONLY_ERRORS:
            return response
        
        ignore = patterns(False, *settings.REQUEST_IGNORE_PATHS)
        if ignore.resolve(request.path[1:]):
            return response
        
        if request.is_ajax() and settings.REQUEST_IGNORE_AJAX:
            return response
        
        if request.META.get('REMOTE_ADDR') in settings.REQUEST_IGNORE_IP:
            return response
        
        if getattr(request, 'user', False):
            if request.user.username in settings.REQUEST_IGNORE_USERNAME:
                return response
        
        if not getattr(request, 'session', None):
            return response

        r = Request()
        now = datetime.datetime.now()
        path = request.path
        if path[len(path)-1] != '/':
            path = path + '/'
    
        if path in settings.REQUEST_ALWAYS_INSERT_FROM_URLS:
            try:
                request.session['last_request_log'] = now
            except:
                pass
            r.from_http_request(request, response, commit=False)
            record_request(r)
            return response

        try:
            last_log = request.session['last_request_log']
            if settings.REQUEST_USER_TRACKING_LOGAGAIN_DELAY:
                last_log_limit = last_log + \
                    settings.REQUEST_USER_TRACKING_LOGAGAIN_DELAY
                if now < last_log_limit :
                    return response
        except KeyError:
            pass 
        request.session['last_request_log'] = now
        r.from_http_request(request, response, commit=False)
        record_request(r)
        return response
Esempio n. 6
0
browsers = patterns(
    ('Unknown', {}),
    # Browsers
    (r'AOL (?P<version>[\d+\.\d+]+)', 'AOL'),
    (r'Mozilla/(?P<mozilla_version>[-.\w]+) \(compatible; ( ?)MSIE (?P<msie_version>[-.\w]+);( ?)( ?)America Online Browser (?P<version>[-.\w]+);', 'AOL'),
    (r'Camino/(?P<version>[-.\w]+)', 'Camino'),
    (r'Chrome/(?P<version>[-.\w]+)', 'Google Chrome'),
    (r'Firefox(/(?P<version>[-.\w]+)?)', 'Firefox'),
    (r'Mozilla/(?P<mozilla_version>[-.\w]+) \(compatible; ( ?)MSIE (?P<version>[-.\w]+);( ?)( ?)(Win|Mac)', 'Internet Explorer'),
    (r'Konqueror/(?P<version>[-.\w]+)', 'Konqueror'),
    (r'Opera( |/)(?P<version>[-.\w]+)', 'Opera'),
    (r'OmniWeb(/(?P<version>[-.\w]+)?)', 'OmniWeb'),
    (r'Safari/(?P<version>[-.\w]+)', 'Safari'),
    (r'(Netscape([\d]?)|Navigator)/(?P<version>[-.\w]+)', 'Netscape'),
    (r'Wget/(?P<version>[-.\w]+)', 'Wget'),

    (r'Minefield(/(?P<version>[-.\w]+)?)', 'Firefox'),  # Firefox nightly trunk builds
    (r'Shiretoko(/(?P<version>[-.\w]+)?)', 'Firefox'),  # Firefox testing browser
    (r'GranParadiso(/(?P<version>[-.\w]+)?)', 'Firefox'),  # Firefox testing browser
    (r'Iceweasel(/(?P<version>[-.\w]+)?)', 'Firefox'),  # Debian re-branded firefox

    # RSS Reader
    (r'(NetNewsWire|NewsGatorOnline)/(?P<version>[-.\w]+)', 'NetNewsWire'),
    (r'Feedfetcher-Google', 'Google Reader'),

    # Bots
    (r'Googlebot', 'Google'),
    (r'Yahoo! Slurp', 'Yahoo'),
    (r'msnbot', 'MSN Bot'),
    (r'(Baiduspider|BaiduImagespider)', 'Baiduspider'),
    (r'Ask Jeeves', 'Ask Jeeves'),
    (r'FollowSite', 'FollowSite'),
    (r'WebAlta Crawler', 'WebAlta Crawler'),
    (r'ScoutJet', 'ScoutJet'),
    (r'SurveyBot', 'domaintools.com'),
    (r'Gigabot', 'Gigabot'),
    (r'Speedy Spider', 'entireweb'),
    (r'discobot', 'Discovery Engine'),
    (r'Purebot(/(?P<version>[-.\w]+)?);', 'Purity search'),
    (r'Yandex(/(?P<version>[-.\w]+)?)', 'Yandex'),
    (r'PostRank(/(?P<version>[-.\w]+)?)', 'PostRank'),
    (r'Mozilla/(?P<mozilla_version>[-.\w]+) \(compatible; DotBot/(?P<version>[-.\w]+); http://www.dotnetdotcom.org/, [email protected]\)', 'Dotbot'),
    (r'IrssiUrlLog(/(?P<version>[-.\w]+)?)', 'irssi'),
    (r'Linguee Bot \(http://www.linguee.com/bot; [email protected]\)', 'Linguee'),
    (r'Sphider', 'Sphider'),

    # Other
    (r'Mediapartners-Google', 'Google Ads'),
    (r'Apple-PubSub', 'Apple-PubSub'),
    (r'Python-urllib', 'Python'),
)
Esempio n. 7
0
    (415, _('Unsupported Media Type')),
    (416, _('Requested Range Not Satisfiable')),
    (417, _('Expectation Failed')),
    (418, _('I\'m a teapot')),  # April Fools
    (422, _('Unprocessable Entity (WebDAV)')),
    (423, _('Locked (WebDAV)')),
    (424, _('Failed Dependency (WebDAV)')),
    (425, _('Unordered Collection')),
    (426, _('Upgrade Required')),
    (449, _('Retry With')),

    # Server Error
    (500, _('Internal Server Error')),
    (501, _('Not Implemented')),
    (502, _('Bad Gateway')),
    (503, _('Service Unavailable')),
    (504, _('Gateway Timeout')),
    (505, _('HTTP Version Not Supported')),
    (506, _('Variant Also Negotiates')),
    (507, _('Insufficient Storage (WebDAV)')),
    (509, _('Bandwidth Limit Exceeded')),
    (510, _('Not Extended')),
)

engines = patterns(
    None,
    (r'^https?:\/\/([\.\w]+)?yahoo.*(?:&|\?)p=(?P<keywords>[\+-_\w]+)', 'Yahoo'),
    (r'^https?:\/\/([\.\w]+)?google.*(?:&|\?)q=(?P<keywords>[\+-_\w]+)', 'Google'),
    (r'^https?:\/\/([\.\w]+)?bing.*(?:&|\?)q=(?P<keywords>[\+-_\w]+)', 'Bing'),
)
Esempio n. 8
0
 def __init__(self):
     self.exceptions = patterns(False, *settings.REQUEST_IGNORE_PATHS)
Esempio n. 9
0
browsers = patterns(
    ("Unknown", {}),
    # Browsers
    (r"AOL (?P<version>[\d+\.\d+]+)", "AOL"),
    (
        r"Mozilla/(?P<mozilla_version>[-.\w]+) \(compatible; ( ?)MSIE (?P<msie_version>[-.\w]+);( ?)( ?)America Online Browser (?P<version>[-.\w]+);",
        "AOL",
    ),
    (r"Camino/(?P<version>[-.\w]+)", "Camino"),
    (r"Chrome/(?P<version>[-.\w]+)", "Google Chrome"),
    (r"Firefox(/(?P<version>[-.\w]+)?)", "Firefox"),
    (
        r"Mozilla/(?P<mozilla_version>[-.\w]+) \(compatible; ( ?)MSIE (?P<version>[-.\w]+);( ?)( ?)(Win|Mac)",
        "Internet Explorer",
    ),
    (r"Konqueror/(?P<version>[-.\w]+)", "Konqueror"),
    (r"Opera( |/)(?P<version>[-.\w]+)", "Opera"),
    (r"OmniWeb(/(?P<version>[-.\w]+)?)", "OmniWeb"),
    (r"Safari/(?P<version>[-.\w]+)", "Safari"),
    (r"(Netscape([\d]?)|Navigator)/(?P<version>[-.\w]+)", "Netscape"),
    (r"Wget/(?P<version>[-.\w]+)", "Wget"),
    (r"Minefield(/(?P<version>[-.\w]+)?)", "Firefox"),  # Firefox nightly trunk builds
    (r"Shiretoko(/(?P<version>[-.\w]+)?)", "Firefox"),  # Firefox testing browser
    (r"GranParadiso(/(?P<version>[-.\w]+)?)", "Firefox"),  # Firefox testing browser
    (r"Iceweasel(/(?P<version>[-.\w]+)?)", "Firefox"),  # Debian re-branded firefox
    # RSS Reader
    (r"(NetNewsWire|NewsGatorOnline)/(?P<version>[-.\w]+)", "NetNewsWire"),
    (r"Feedfetcher-Google", "Google Reader"),
    # Bots
    (r"Googlebot", "Google"),
    (r"Yahoo! Slurp", "Yahoo"),
    (r"msnbot", "MSN Bot"),
    (r"(Baiduspider|BaiduImagespider)", "Baiduspider"),
    (r"Ask Jeeves", "Ask Jeeves"),
    (r"FollowSite", "FollowSite"),
    (r"WebAlta Crawler", "WebAlta Crawler"),
    (r"ScoutJet", "ScoutJet"),
    (r"SurveyBot", "domaintools.com"),
    (r"Gigabot", "Gigabot"),
    (r"Speedy Spider", "entireweb"),
    (r"discobot", "Discovery Engine"),
    (r"Purebot(/(?P<version>[-.\w]+)?);", "Purity search"),
    (r"Yandex(/(?P<version>[-.\w]+)?)", "Yandex"),
    (r"PostRank(/(?P<version>[-.\w]+)?)", "PostRank"),
    (
        r"Mozilla/(?P<mozilla_version>[-.\w]+) \(compatible; DotBot/(?P<version>[-.\w]+); http://www.dotnetdotcom.org/, [email protected]\)",
        "Dotbot",
    ),
    (r"IrssiUrlLog(/(?P<version>[-.\w]+)?)", "irssi"),
    (r"Linguee Bot \(http://www.linguee.com/bot; [email protected]\)", "Linguee"),
    (r"Sphider", "Sphider"),
    # Other
    (r"Mediapartners-Google", "Google Ads"),
    (r"Apple-PubSub", "Apple-PubSub"),
    (r"Python-urllib", "Python"),
)
Esempio n. 10
0
browsers = patterns(
    ('Unknown', {}),
    # Browsers
    (r'AOL (?P<version>[\d+\.\d+]+)', 'AOL'),
    (r'Mozilla/(?P<mozilla_version>[-.\w]+) \(compatible; ( ?)MSIE (?P<msie_version>[-.\w]+);( ?)( ?)America Online Browser (?P<version>[-.\w]+);',
     'AOL'),
    (r'Camino/(?P<version>[-.\w]+)', 'Camino'),
    (r'Chrome/(?P<version>[-.\w]+)', 'Google Chrome'),
    (r'Firefox(/(?P<version>[-.\w]+)?)', 'Firefox'),
    (r'Mozilla/(?P<mozilla_version>[-.\w]+) \(compatible; ( ?)MSIE (?P<version>[-.\w]+);( ?)( ?)(Win|Mac)',
     'Internet Explorer'),
    (r'Konqueror/(?P<version>[-.\w]+)', 'Konqueror'),
    (r'Opera( |/)(?P<version>[-.\w]+)', 'Opera'),
    (r'OmniWeb(/(?P<version>[-.\w]+)?)', 'OmniWeb'),
    (r'Safari/(?P<version>[-.\w]+)', 'Safari'),
    (r'(Netscape([\d]?)|Navigator)/(?P<version>[-.\w]+)', 'Netscape'),
    (r'Wget/(?P<version>[-.\w]+)', 'Wget'),
    (r'Minefield(/(?P<version>[-.\w]+)?)',
     'Firefox'),  # Firefox nightly trunk builds
    (r'Shiretoko(/(?P<version>[-.\w]+)?)',
     'Firefox'),  # Firefox testing browser
    (r'GranParadiso(/(?P<version>[-.\w]+)?)',
     'Firefox'),  # Firefox testing browser
    (r'Iceweasel(/(?P<version>[-.\w]+)?)',
     'Firefox'),  # Debian re-branded firefox

    # RSS Reader
    (r'(NetNewsWire|NewsGatorOnline)/(?P<version>[-.\w]+)', 'NetNewsWire'),
    (r'Feedfetcher-Google', 'Google Reader'),

    # Bots
    (r'Googlebot', 'Google'),
    (r'Yahoo! Slurp', 'Yahoo'),
    (r'msnbot', 'MSN Bot'),
    (r'(Baiduspider|BaiduImagespider)', 'Baiduspider'),
    (r'Ask Jeeves', 'Ask Jeeves'),
    (r'FollowSite', 'FollowSite'),
    (r'WebAlta Crawler', 'WebAlta Crawler'),
    (r'ScoutJet', 'ScoutJet'),
    (r'SurveyBot', 'domaintools.com'),
    (r'Gigabot', 'Gigabot'),
    (r'Speedy Spider', 'entireweb'),
    (r'discobot', 'Discovery Engine'),
    (r'Purebot(/(?P<version>[-.\w]+)?);', 'Purity search'),
    (r'Yandex(/(?P<version>[-.\w]+)?)', 'Yandex'),
    (r'PostRank(/(?P<version>[-.\w]+)?)', 'PostRank'),
    (r'Mozilla/(?P<mozilla_version>[-.\w]+) \(compatible; DotBot/(?P<version>[-.\w]+); http://www.dotnetdotcom.org/, [email protected]\)',
     'Dotbot'),
    (r'IrssiUrlLog(/(?P<version>[-.\w]+)?)', 'irssi'),
    (r'Linguee Bot \(http://www.linguee.com/bot; [email protected]\)',
     'Linguee'),
    (r'Sphider', 'Sphider'),

    # Other
    (r'Mediapartners-Google', 'Google Ads'),
    (r'Apple-PubSub', 'Apple-PubSub'),
    (r'Python-urllib', 'Python'),
)
Esempio n. 11
0
 def setUp(self):
     self.unkn_pat = r'^foobar$'
     self.pat1 = r'^foo$'
     self.pat2 = r'^bar$'
     self.pats = router.patterns(self.unkn_pat, self.pat1, self.pat2)
Esempio n. 12
0
 def test_unnamed_patterns(self):
     self.assertEqual(patterns(False, r'^/admin/$').resolve('/admin/'),
                      ('', {}))
     self.assertEqual(patterns(False, r'^/admin/$').resolve('/login/'),
                      False)