summaryrefslogtreecommitdiff
path: root/tests/smbserver.py
diff options
context:
space:
mode:
authorMarc Hoersken <info@marc-hoersken.de>2020-03-17 10:36:25 +0100
committerMarc Hoersken <info@marc-hoersken.de>2020-03-19 03:26:19 +0100
commit3c9066fce54b78cc8b46e82eba033aaa373cdef1 (patch)
tree25620b454e007eb89162bf9437cfaadb2bdf5db4 /tests/smbserver.py
parent8d9802b0aed12932612847f4267a42d08b7bfa71 (diff)
downloadcurl-3c9066fce54b78cc8b46e82eba033aaa373cdef1.tar.gz
tests: make Python-based servers compatible with Python 2 and 3
Update smbserver.py and negtelnetserver.py to be compatible with Python 3 while staying backwards-compatible to support Python 2. Fix string encoding and handling of echoed and transferred data. Tested with both Python 2.7.17 and Python 3.7.7 Reported-by: Daniel Stenberg Assisted-by: Kamil Dudka Reviewed-by: Marcel Raad Fixes #5104 Closes #5110
Diffstat (limited to 'tests/smbserver.py')
-rwxr-xr-xtests/smbserver.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/tests/smbserver.py b/tests/smbserver.py
index d7abf8d47..d320fb21e 100755
--- a/tests/smbserver.py
+++ b/tests/smbserver.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Project ___| | | | _ \| |
@@ -6,7 +6,7 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
-# Copyright (C) 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 2017 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
@@ -22,7 +22,7 @@
"""Server for testing SMB"""
from __future__ import (absolute_import, division, print_function)
-# unicode_literals)
+# NOTE: the impacket configuration is not unicode_literals compatible!
import argparse
import os
import sys
@@ -52,7 +52,7 @@ log = logging.getLogger(__name__)
SERVER_MAGIC = "SERVER_MAGIC"
TESTS_MAGIC = "TESTS_MAGIC"
VERIFIED_REQ = "verifiedserver"
-VERIFIED_RSP = b"WE ROOLZ: {pid}\n"
+VERIFIED_RSP = "WE ROOLZ: {pid}\n"
def smbserver(options):
@@ -267,7 +267,7 @@ class TestSmbServer(imp_smbserver.SMBSERVER):
if requested_filename == VERIFIED_REQ:
log.debug("[SMB] Verifying server is alive")
- contents = VERIFIED_RSP.format(pid=os.getpid())
+ contents = VERIFIED_RSP.format(pid=os.getpid()).encode('utf-8')
self.write_to_fid(fid, contents)
return fid, filename
@@ -288,7 +288,7 @@ class TestSmbServer(imp_smbserver.SMBSERVER):
filename, fid, requested_filename)
try:
- contents = self.ctd.get_test_data(requested_filename)
+ contents = self.ctd.get_test_data(requested_filename).encode('utf-8')
self.write_to_fid(fid, contents)
return fid, filename