Skip to content

Commit

Permalink
drop python2
Browse files Browse the repository at this point in the history
Signed-off-by: Roberto Scolaro <roberto.scolaro21@gmail.com>
  • Loading branch information
therealbobo committed Oct 7, 2024
1 parent a3a6e55 commit 839a6b7
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions test/libsinsp_e2e/resources/fake_docker.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/usr/bin/env python2
#!/usr/bin/env python3

# https://stackoverflow.com/questions/21650370/setting-up-an-http-server-that-listens-over-a-file-socket

import SocketServer
import socketserver
import os
import re
import socket
import sys
import time
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from http.server import HTTPServer, BaseHTTPRequestHandler


DELAY = 0.0
CONTAINER_JSON = '''{
Expand Down Expand Up @@ -223,18 +222,16 @@

CONTAINER_REQUEST = re.compile('^(?:/v1.[0-9]*)?/containers/([0-9a-f]+)/json')


class FakeDockerHTTPHandler(BaseHTTPRequestHandler):

def _send_response(self, resp):
self.send_header('Content-Length', len(resp))
resp_bytes = resp.encode('utf-8') # Convert to bytes
self.send_header('Content-Length', len(resp_bytes))
self.send_header('Connection', 'close')
self.end_headers()
self.wfile.write(resp)
self.wfile.write(resp_bytes)

# noinspection PyPep8Naming
def do_GET(self):

matches = CONTAINER_REQUEST.match(self.path)
if matches:
if DELAY < 0:
Expand All @@ -256,9 +253,8 @@ def do_GET(self):
class UnixHTTPServer(HTTPServer):
address_family = socket.AF_UNIX

# noinspection PyAttributeOutsideInit
def server_bind(self):
SocketServer.TCPServer.server_bind(self)
socketserver.TCPServer.server_bind(self)
self.server_name = 'localhost'
self.server_port = 0

Expand All @@ -268,19 +264,16 @@ def get_request(self):


if __name__ == '__main__':
# noinspection PyBroadException
try:
DELAY = float(sys.argv[1])
except Exception:
pass

# noinspection PyBroadException
try:
socket_path = sys.argv[2]
except Exception:
socket_path = '/tmp/http.socket'

# noinspection PyBroadException
try:
os.unlink(socket_path)
except Exception:
Expand Down

0 comments on commit 839a6b7

Please sign in to comment.