Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apachedex
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Vincent Pelletier
apachedex
Commits
ffdc722a
Commit
ffdc722a
authored
Dec 19, 2023
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update for python3 >= 3.9
drop support for python 2
parent
943a005d
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
144 deletions
+122
-144
apachedex/__init__.py
apachedex/__init__.py
+89
-120
apachedex/tests.py
apachedex/tests.py
+32
-21
setup.py
setup.py
+1
-3
No files found.
apachedex/__init__.py
View file @
ffdc722a
This diff is collapsed.
Click to expand it.
apachedex/tests.py
View file @
ffdc722a
...
@@ -3,10 +3,10 @@ import sys
...
@@ -3,10 +3,10 @@ import sys
import
json
import
json
import
bz2
import
bz2
import
gzip
import
gzip
from
StringIO
import
StringIO
import
io
import
tempfile
import
tempfile
import
apachedex
import
apachedex
from
.
import
lzma
import
lzma
class
ApacheDEXTestCase
(
unittest
.
TestCase
):
class
ApacheDEXTestCase
(
unittest
.
TestCase
):
...
@@ -15,8 +15,10 @@ class ApacheDEXTestCase(unittest.TestCase):
...
@@ -15,8 +15,10 @@ class ApacheDEXTestCase(unittest.TestCase):
self
.
_original_sys_stdin
=
sys
.
stdin
self
.
_original_sys_stdin
=
sys
.
stdin
self
.
_original_sys_stderr
=
sys
.
stderr
self
.
_original_sys_stderr
=
sys
.
stderr
self
.
_original_sys_stdout
=
sys
.
stdout
self
.
_original_sys_stdout
=
sys
.
stdout
sys
.
stderr
=
StringIO
()
self
.
_stderr_bytes
=
io
.
BytesIO
()
sys
.
stdout
=
StringIO
()
sys
.
stderr
=
io
.
TextIOWrapper
(
self
.
_stderr_bytes
,
write_through
=
True
)
self
.
_stdout_bytes
=
io
.
BytesIO
()
sys
.
stdout
=
io
.
TextIOWrapper
(
self
.
_stdout_bytes
,
write_through
=
True
)
def
tearDown
(
self
):
def
tearDown
(
self
):
sys
.
argv
=
self
.
_original_sys_argv
sys
.
argv
=
self
.
_original_sys_argv
...
@@ -25,17 +27,31 @@ class ApacheDEXTestCase(unittest.TestCase):
...
@@ -25,17 +27,31 @@ class ApacheDEXTestCase(unittest.TestCase):
sys
.
stdout
=
self
.
_original_sys_stdout
sys
.
stdout
=
self
.
_original_sys_stdout
class
TestFiles
(
ApacheDEXTestCase
):
def
test
(
self
):
with
tempfile
.
NamedTemporaryFile
()
as
fin
,
tempfile
.
NamedTemporaryFile
()
as
fout
:
fin
.
write
(
b'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1754'''
)
fin
.
flush
()
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
fin
.
name
,
'--out'
,
fout
.
name
]
apachedex
.
main
()
fout
.
flush
()
fout
.
seek
(
0
)
self
.
assertIn
(
b"<html>"
,
fout
.
read
())
class
TestMalformedInput
(
ApacheDEXTestCase
):
class
TestMalformedInput
(
ApacheDEXTestCase
):
def
test_timestamp_mixed_in_timestamp
(
self
):
def
test_timestamp_mixed_in_timestamp
(
self
):
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
'-'
]
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
'-'
]
sys
.
stdin
=
StringIO
(
sys
.
stdin
=
io
.
StringIO
(
# this first line is valid, but second is not
# this first line is valid, but second is not
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1754
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1754
127.0.0.1 - - [14/Jul/2017:127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1754'''
)
127.0.0.1 - - [14/Jul/2017:127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1754'''
)
apachedex
.
main
()
apachedex
.
main
()
self
.
assertNotIn
(
'Malformed line at -:1'
,
sys
.
stderr
.
getvalue
())
self
.
assertNotIn
(
b'Malformed line at -:1'
,
self
.
_stderr_bytes
.
getvalue
())
self
.
assertIn
(
'Malformed line at -:2'
,
sys
.
stderr
.
getvalue
())
self
.
assertIn
(
b'Malformed line at -:2'
,
self
.
_stderr_bytes
.
getvalue
())
class
TestCharacterEncoding
(
ApacheDEXTestCase
):
class
TestCharacterEncoding
(
ApacheDEXTestCase
):
...
@@ -48,7 +64,7 @@ class TestCharacterEncoding(ApacheDEXTestCase):
...
@@ -48,7 +64,7 @@ class TestCharacterEncoding(ApacheDEXTestCase):
fin
.
flush
()
fin
.
flush
()
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
fin
.
name
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
fin
.
name
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
apachedex
.
main
()
apachedex
.
main
()
self
.
assertNotIn
(
'Malformed line'
,
sys
.
stderr
.
getvalue
())
self
.
assertNotIn
(
b'Malformed line'
,
self
.
_stderr_bytes
.
getvalue
())
with
open
(
fout
.
name
)
as
f
:
with
open
(
fout
.
name
)
as
f
:
self
.
assertTrue
(
json
.
load
(
f
))
self
.
assertTrue
(
json
.
load
(
f
))
...
@@ -74,7 +90,7 @@ class EncodedInputTestMixin:
...
@@ -74,7 +90,7 @@ class EncodedInputTestMixin:
fin
.
flush
()
fin
.
flush
()
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
fin
.
name
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
fin
.
name
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
apachedex
.
main
()
apachedex
.
main
()
self
.
assertNotIn
(
'Malformed line'
,
sys
.
stderr
.
getvalue
())
self
.
assertNotIn
(
b'Malformed line'
,
self
.
_stderr_bytes
.
getvalue
())
with
open
(
fout
.
name
)
as
f
:
with
open
(
fout
.
name
)
as
f
:
self
.
assertTrue
(
json
.
load
(
f
))
self
.
assertTrue
(
json
.
load
(
f
))
...
@@ -86,20 +102,15 @@ class TestBzip2Encoding(ApacheDEXTestCase, EncodedInputTestMixin):
...
@@ -86,20 +102,15 @@ class TestBzip2Encoding(ApacheDEXTestCase, EncodedInputTestMixin):
class
TestZlibEncoding
(
ApacheDEXTestCase
,
EncodedInputTestMixin
):
class
TestZlibEncoding
(
ApacheDEXTestCase
,
EncodedInputTestMixin
):
def
_getInputData
(
self
):
def
_getInputData
(
self
):
f
=
String
IO
()
f
=
io
.
Bytes
IO
()
with
gzip
.
GzipFile
(
mode
=
"w"
,
fileobj
=
f
)
as
gzfile
:
with
gzip
.
GzipFile
(
mode
=
"w"
,
fileobj
=
f
)
as
gzfile
:
gzfile
.
write
(
self
.
DEFAULT_LINE
)
gzfile
.
write
(
self
.
DEFAULT_LINE
)
return
f
.
getvalue
()
return
f
.
getvalue
()
if
lzma
is
not
None
:
class
TestLzmaEncoding
(
ApacheDEXTestCase
,
EncodedInputTestMixin
):
class
TestLzmaEncoding
(
ApacheDEXTestCase
,
EncodedInputTestMixin
):
def
_getInputData
(
self
):
def
_getInputData
(
self
):
return
lzma
.
compress
(
self
.
DEFAULT_LINE
)
return
lzma
.
compress
(
self
.
DEFAULT_LINE
)
else
:
class
TestLzmaEncoding
(
ApacheDEXTestCase
):
def
test
(
self
):
self
.
skipTest
(
"lzma not available"
)
class
TestTimeEnconding
(
ApacheDEXTestCase
):
class
TestTimeEnconding
(
ApacheDEXTestCase
):
...
@@ -107,7 +118,7 @@ class TestTimeEnconding(ApacheDEXTestCase):
...
@@ -107,7 +118,7 @@ class TestTimeEnconding(ApacheDEXTestCase):
def
test_seconds_timing
(
self
):
def
test_seconds_timing
(
self
):
with
tempfile
.
NamedTemporaryFile
()
as
fout
:
with
tempfile
.
NamedTemporaryFile
()
as
fout
:
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
'-'
,
'--logformat'
,
'%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i" %T'
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
'-'
,
'--logformat'
,
'%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i" %T'
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
sys
.
stdin
=
StringIO
(
sys
.
stdin
=
io
.
StringIO
(
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1'''
)
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1'''
)
apachedex
.
main
()
apachedex
.
main
()
...
@@ -119,7 +130,7 @@ class TestTimeEnconding(ApacheDEXTestCase):
...
@@ -119,7 +130,7 @@ class TestTimeEnconding(ApacheDEXTestCase):
def
test_milliseconds_timing
(
self
):
def
test_milliseconds_timing
(
self
):
with
tempfile
.
NamedTemporaryFile
()
as
fout
:
with
tempfile
.
NamedTemporaryFile
()
as
fout
:
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
'-'
,
'--logformat'
,
'%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i" %D'
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
'-'
,
'--logformat'
,
'%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i" %D'
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
sys
.
stdin
=
StringIO
(
sys
.
stdin
=
io
.
StringIO
(
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1000000'''
)
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1000000'''
)
apachedex
.
main
()
apachedex
.
main
()
...
@@ -131,7 +142,7 @@ class TestTimeEnconding(ApacheDEXTestCase):
...
@@ -131,7 +142,7 @@ class TestTimeEnconding(ApacheDEXTestCase):
def
test_microseconds_timing
(
self
):
def
test_microseconds_timing
(
self
):
with
tempfile
.
NamedTemporaryFile
()
as
fout
:
with
tempfile
.
NamedTemporaryFile
()
as
fout
:
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
'-'
,
'--logformat'
,
'%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i" %{ms}T'
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
sys
.
argv
=
[
'apachedex'
,
'--base=/'
,
'-'
,
'--logformat'
,
'%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i" %{ms}T'
,
'-f'
,
'json'
,
'-o'
,
fout
.
name
]
sys
.
stdin
=
StringIO
(
sys
.
stdin
=
io
.
StringIO
(
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1000
'''127.0.0.1 - - [14/Jul/2017:09:41:41 +0200] "GET / HTTP/1.1" 200 7499 "https://example.org/" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36" 1000
'''
)
'''
)
...
...
setup.py
View file @
ffdc722a
...
@@ -64,14 +64,13 @@ setup(
...
@@ -64,14 +64,13 @@ setup(
long_description
=
".. contents::
\
n
\
n
"
+
description
,
long_description
=
".. contents::
\
n
\
n
"
+
description
,
author
=
'Vincent Pelletier'
,
author
=
'Vincent Pelletier'
,
author_email
=
'vincent@nexedi.com'
,
author_email
=
'vincent@nexedi.com'
,
url
=
'http
://git.erp5.org/gitweb
/apachedex.git'
,
url
=
'http
s://lab.nexedi.com/nexedi
/apachedex.git'
,
license
=
'GPL 2+'
,
license
=
'GPL 2+'
,
platforms
=
[
'any'
],
platforms
=
[
'any'
],
classifiers
=
[
classifiers
=
[
'Intended Audience :: Developers'
,
'Intended Audience :: Developers'
,
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)'
,
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)'
,
'Operating System :: OS Independent'
,
'Operating System :: OS Independent'
,
'Programming Language :: Python :: 2.7'
,
'Programming Language :: Python :: 3'
,
'Programming Language :: Python :: 3'
,
'Programming Language :: Python :: Implementation :: PyPy'
,
'Programming Language :: Python :: Implementation :: PyPy'
,
'Programming Language :: Python :: Implementation :: CPython'
,
'Programming Language :: Python :: Implementation :: CPython'
,
...
@@ -90,5 +89,4 @@ setup(
...
@@ -90,5 +89,4 @@ setup(
},
},
test_suite
=
'apachedex.tests'
,
test_suite
=
'apachedex.tests'
,
zip_safe
=
True
,
zip_safe
=
True
,
use_2to3
=
True
,
)
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment