def test_return_value(self):
     fd = open(
         os.path.join(here, 'apache-log-files', 'librarian-oneline.log'))
     host, date, status, request = get_host_date_status_and_request(
         fd.readline())
     self.assertEqual(host, '201.158.154.121')
     self.assertEqual(date, '[13/Jun/2008:18:38:57 +0100]')
     self.assertEqual(status, '200')
     self.assertEqual(request,
                      'GET /15166065/gnome-do-0.5.0.1.tar.gz HTTP/1.1')
 def test_return_value(self):
     fd = open(
         os.path.join(here, 'apache-log-files', 'librarian-oneline.log'))
     host, date, status, request = get_host_date_status_and_request(
         fd.readline())
     self.assertEqual(host, '201.158.154.121')
     self.assertEqual(date, '[13/Jun/2008:18:38:57 +0100]')
     self.assertEqual(status, '200')
     self.assertEqual(
         request, 'GET /15166065/gnome-do-0.5.0.1.tar.gz HTTP/1.1')
 def test_parsing_line_with_quotes_inside_user_agent_and_referrer(self):
     # Some lines have quotes as part of the referrer and/or user agent,
     # and they are parsed just fine too.
     line = (r'84.113.215.193 - - [25/Jan/2009:15:48:07 +0000] "GET '
             r'/10133748/cramfsswap_1.4.1.tar.gz HTTP/1.0" 200 12341 '
             r'"http://foo.bar/?baz=\"bang\"" '
             r'"\"Nokia2630/2.0 (05.20) Profile/MIDP-2.1 '
             r'Configuration/CLDC-1.1\""')
     host, date, status, request = get_host_date_status_and_request(line)
     self.assertEqual(host, '84.113.215.193')
     self.assertEqual(date, '[25/Jan/2009:15:48:07 +0000]')
     self.assertEqual(status, '200')
     self.assertEqual(request,
                      'GET /10133748/cramfsswap_1.4.1.tar.gz HTTP/1.0')
 def test_parsing_line_with_quotes_inside_user_agent_and_referrer(self):
     # Some lines have quotes as part of the referrer and/or user agent,
     # and they are parsed just fine too.
     line = (r'84.113.215.193 - - [25/Jan/2009:15:48:07 +0000] "GET '
             r'/10133748/cramfsswap_1.4.1.tar.gz HTTP/1.0" 200 12341 '
             r'"http://foo.bar/?baz=\"bang\"" '
             r'"\"Nokia2630/2.0 (05.20) Profile/MIDP-2.1 '
             r'Configuration/CLDC-1.1\""')
     host, date, status, request = get_host_date_status_and_request(line)
     self.assertEqual(host, '84.113.215.193')
     self.assertEqual(date, '[25/Jan/2009:15:48:07 +0000]')
     self.assertEqual(status, '200')
     self.assertEqual(
         request, 'GET /10133748/cramfsswap_1.4.1.tar.gz HTTP/1.0')
 def test_parsing_line_with_spaces_in_username(self):
     # Some lines have spaces in the username, left unquoted by
     # Apache. They can still be parsed OK, since no other fields
     # have similar issues.
     line = (r'1.1.1.1 - Some User [25/Jan/2009:15:48:07 +0000] "GET '
             r'/10133748/cramfsswap_1.4.1.tar.gz HTTP/1.0" 200 12341 '
             r'"http://foo.bar/?baz=\"bang\"" '
             r'"\"Nokia2630/2.0 (05.20) Profile/MIDP-2.1 '
             r'Configuration/CLDC-1.1\""')
     host, date, status, request = get_host_date_status_and_request(line)
     self.assertEqual(host, '1.1.1.1')
     self.assertEqual(date, '[25/Jan/2009:15:48:07 +0000]')
     self.assertEqual(status, '200')
     self.assertEqual(request,
                      'GET /10133748/cramfsswap_1.4.1.tar.gz HTTP/1.0')
 def test_parsing_line_with_spaces_in_username(self):
     # Some lines have spaces in the username, left unquoted by
     # Apache. They can still be parsed OK, since no other fields
     # have similar issues.
     line = (r'1.1.1.1 - Some User [25/Jan/2009:15:48:07 +0000] "GET '
             r'/10133748/cramfsswap_1.4.1.tar.gz HTTP/1.0" 200 12341 '
             r'"http://foo.bar/?baz=\"bang\"" '
             r'"\"Nokia2630/2.0 (05.20) Profile/MIDP-2.1 '
             r'Configuration/CLDC-1.1\""')
     host, date, status, request = get_host_date_status_and_request(line)
     self.assertEqual(host, '1.1.1.1')
     self.assertEqual(date, '[25/Jan/2009:15:48:07 +0000]')
     self.assertEqual(status, '200')
     self.assertEqual(
         request, 'GET /10133748/cramfsswap_1.4.1.tar.gz HTTP/1.0')