VirtualBox

Changeset 70568 in vbox


Ignore:
Timestamp:
Jan 12, 2018 9:44:37 PM (7 years ago)
Author:
vboxsync
Message:

common/utils.py: More python 3 fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/common/utils.py

    r70567 r70568  
    381381    except:
    382382        return sXcptRet;
    383     return sRet.decode(sEncoding, 'ignore');
     383    if hasattr(sRet, 'decode'):
     384        sRet = sRet.decode(sEncoding, 'ignore');
     385    return sRet;
    384386
    385387def readFile(sFile, sMode = 'rb'):
     
    400402    except:
    401403        sRet = sXcptRet;
    402     if sEncoding is not None:
     404    if sEncoding is not None and hasattr(sRet, 'decode'):
    403405        sRet = sRet.decode(sEncoding, 'ignore');
    404406    return sRet;
     
    588590    Wrapper around subprocess.check_output to deal with its absense in older
    589591    python versions.
    590     Extra keyword: sEncoding='utf-8; for specifying now output is to be decoded.
     592
     593    Extra keywords for specifying now output is to be decoded:
     594        sEncoding='utf-8
     595        fIgnoreEncoding=True/False
    591596    """
    592597    sEncoding = dKeywordArgs.get('sEncoding');
    593598    if sEncoding is not None:   del dKeywordArgs['sEncoding'];
    594599    else:                       sEncoding = 'utf-8';
     600
     601    fIgnoreEncoding = dKeywordArgs.get('fIgnoreEncoding');
     602    if sEncoding is not None:   del dKeywordArgs['fIgnoreEncoding'];
     603    else:                       fIgnoreEncoding = True;
    595604
    596605    _processFixPythonInterpreter(aPositionalArgs, dKeywordArgs);
     
    607616        raise subprocess.CalledProcessError(iExitCode, asArgs);
    608617
    609     return sOutput.decode(sEncoding);
     618    if hasattr(sOutput, 'decode'):
     619        sOutput = sOutput.decode(sEncoding, 'ignore' if fIgnoreEncoding else 'strict');
     620    return sOutput;
    610621
    611622g_fOldSudo = None;
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