VirtualBox

Ignore:
Timestamp:
May 17, 2018 12:15:44 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
122684
Message:

valkit/utils.py: Fixed hasNonAsciiCharacters (busted on 3.x) and added a couple of more tests to it.

File:
1 edited

Legend:

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

    r71963 r72238  
    14001400        return '%ss' % (cSeconds,);
    14011401    if cSeconds < 3600:
    1402         cMins = cSeconds / 60;
     1402        cMins = cSeconds // 60;
    14031403        cSecs = cSeconds % 60;
    14041404        if cSecs == 0:
     
    14071407
    14081408    # Generic and a bit slower.
    1409     cDays     = cSeconds / 86400;
     1409    cDays     = cSeconds // 86400;
    14101410    cSeconds %= 86400;
    1411     cHours    = cSeconds / 3600;
     1411    cHours    = cSeconds // 3600;
    14121412    cSeconds %= 3600;
    1413     cMins     = cSeconds / 60;
     1413    cMins     = cSeconds // 60;
    14141414    cSecs     = cSeconds % 60;
    14151415    sRet = '';
     
    18221822    Returns True is specified string has non-ASCII characters, False if ASCII only.
    18231823    """
    1824     sTmp = unicode(sText, errors='ignore') if isinstance(sText, str) else sText;
    1825     return not all(ord(ch) < 128 for ch in sTmp);
     1824    if isString(sText):
     1825        for ch in sText:
     1826            if ord(ch) >= 128:
     1827                return True;
     1828    else:
     1829        # Probably byte array or some such thing.
     1830        for ch in sText:
     1831            if ch >= 128 or ch < 0:
     1832                return True;
     1833    return False;
    18261834
    18271835
     
    20752083        self.assertEqual(hasNonAsciiCharacters(''), False);
    20762084        self.assertEqual(hasNonAsciiCharacters('asdfgebASDFKJ@#$)(!@#UNASDFKHB*&$%&)@#(!)@(#!(#$&*#$&%*Y@#$IQWN---00;'), False);
     2085        self.assertEqual(hasNonAsciiCharacters('\x80 '), True);
     2086        self.assertEqual(hasNonAsciiCharacters('\x79 '), False);
    20772087        self.assertEqual(hasNonAsciiCharacters(u'12039889y!@#$%^&*()0-0asjdkfhoiuyweasdfASDFnvV'), False);
    20782088        self.assertEqual(hasNonAsciiCharacters(u'\u0079'), False);
    20792089        self.assertEqual(hasNonAsciiCharacters(u'\u0080'), True);
    20802090        self.assertEqual(hasNonAsciiCharacters(u'\u0081 \u0100'), True);
     2091        self.assertEqual(hasNonAsciiCharacters(b'\x20\x20\x20'), False);
     2092        self.assertEqual(hasNonAsciiCharacters(b'\x20\x81\x20'), True);
    20812093
    20822094if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.

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