VirtualBox

Ignore:
Timestamp:
Jan 17, 2018 3:47:10 PM (7 years ago)
Author:
vboxsync
Message:

testdriver: More python 3 adjustments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testdriver/txsclient.py

    r70541 r70611  
    3838import threading;
    3939import time;
    40 import types;
    4140import zlib;
    4241import uuid;
     
    366365                            abPayload.append(ord(sUtf8[i]))
    367366                    abPayload.append(0);
    368                 elif isinstance(o, types.LongType):
     367                elif isinstance(o, long):
    369368                    if o < 0 or o > 0xffffffff:
    370369                        reporter.fatal('sendMsg: uint32_t payload is out of range: %s' % (hex(o)));
     
    736735            elif o is not None:
    737736                aoPayload.append('|');
    738                 o.uTxsClientCrc32 = zlib.crc32('');
     737                o.uTxsClientCrc32 = zlib.crc32(b'');
    739738            else:
    740739                aoPayload.append('');
     
    10811080            # Push data packets until eof.
    10821081            #
    1083             uMyCrc32 = zlib.crc32("");
     1082            uMyCrc32 = zlib.crc32(b'');
    10841083            while True:
    10851084                # Read up to 64 KB of data.
     
    11471146        return rc;
    11481147
    1149     def taskDownloadString(self, sRemoteFile):
     1148    def taskDownloadString(self, sRemoteFile, sEncoding = 'utf-8', fIgnoreEncodingErrors = True):
    11501149        # Wrap sContent in a file like class.
    11511150        class OutStringFile(object): # pylint: disable=R0903
     
    11601159        rc = self.taskDownloadCommon(sRemoteFile, oLocalString);
    11611160        if rc is True:
    1162             if not oLocalString.asContent:
    1163                 rc = '';
    1164             else:
    1165                 rc = ''.join(oLocalString.asContent);
     1161            rc = '';
     1162            for sBuf in oLocalString.asContent:
     1163                if hasattr(sBuf, 'decode'):
     1164                    rc += sBuf.decode(sEncoding, 'ignore' if fIgnoreEncodingErrors else 'strict');
     1165                else:
     1166                    rc += sBuf;
    11661167        return rc;
    11671168
     
    11731174            # Process data packets until eof.
    11741175            #
    1175             uMyCrc32 = zlib.crc32("");
     1176            uMyCrc32 = zlib.crc32(b'');
    11761177            while rc is True:
    11771178                cbMsg, sOpcode, abPayload = self.recvReply();
     
    16101611        return self.asyncToSync(self.asyncDownloadFile, sRemoteFile, sLocalFile, cMsTimeout, fIgnoreErrors);
    16111612
    1612     def asyncDownloadString(self, sRemoteFile, cMsTimeout = 30000, fIgnoreErrors = False):
     1613    def asyncDownloadString(self, sRemoteFile, sEncoding = 'utf-8', fIgnoreEncodingErrors = True,
     1614                            cMsTimeout = 30000, fIgnoreErrors = False):
    16131615        """
    16141616        Initiates a download string task.
     
    16181620        The task returns a byte string on success, False on failure (logged).
    16191621        """
    1620         return self.startTask(cMsTimeout, fIgnoreErrors, "downloadString", self.taskDownloadString, (sRemoteFile,));
    1621 
    1622     def syncDownloadString(self, sRemoteFile, cMsTimeout = 30000, fIgnoreErrors = False):
     1622        return self.startTask(cMsTimeout, fIgnoreErrors, "downloadString",
     1623                              self.taskDownloadString, (sRemoteFile, sEncoding, fIgnoreEncodingErrors));
     1624
     1625    def syncDownloadString(self, sRemoteFile, sEncoding = 'utf-8', fIgnoreEncodingErrors = True,
     1626                           cMsTimeout = 30000, fIgnoreErrors = False):
    16231627        """Synchronous version."""
    1624         return self.asyncToSync(self.asyncDownloadString, sRemoteFile, cMsTimeout, fIgnoreErrors);
     1628        return self.asyncToSync(self.asyncDownloadString, sRemoteFile, sEncoding, fIgnoreEncodingErrors,
     1629                                cMsTimeout, fIgnoreErrors);
    16251630
    16261631    def asyncUnpackFile(self, sRemoteFile, sRemoteDir, cMsTimeout = 30000, fIgnoreErrors = False):
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette