1# -*- coding: utf-8 -*- 2 3############################################################################# 4## 5## Copyright (C) 2020 The Qt Company Ltd. 6## Contact: https://www.qt.io/licensing/ 7## 8## This file is part of the test suite of Qt for Python. 9## 10## $QT_BEGIN_LICENSE:GPL-EXCEPT$ 11## Commercial License Usage 12## Licensees holding valid commercial Qt licenses may use this file in 13## accordance with the commercial license agreement provided with the 14## Software or, alternatively, in accordance with the terms contained in 15## a written agreement between you and The Qt Company. For licensing terms 16## and conditions see https://www.qt.io/terms-conditions. For further 17## information use the contact form at https://www.qt.io/contact-us. 18## 19## GNU General Public License Usage 20## Alternatively, this file may be used under the terms of the GNU 21## General Public License version 3 as published by the Free Software 22## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 23## included in the packaging of this file. Please review the following 24## information to ensure the GNU General Public License requirements will 25## be met: https://www.gnu.org/licenses/gpl-3.0.html. 26## 27## $QT_END_LICENSE$ 28## 29############################################################################# 30 31# Copy of ../../pyside2/tests/util/py3kcompat.py 32 33import sys 34 35IS_PY3K = sys.version_info[0] == 3 36 37if IS_PY3K: 38 def b(s): 39 if type(s) == bytes: 40 return s 41 return bytes(s, "UTF8") 42 43 def buffer_(s): 44 if s == None: 45 return None 46 elif type(s) == str: 47 return bytes(s, "UTF8") 48 elif type(s) == bytes: 49 return s 50 else: 51 memoryview(s) 52 53 def l(n): 54 return n 55 56 def unicode_(s): 57 return s 58 59 unicode = str 60 unichr = chr 61 long = int 62 unichr = chr 63 buffer = buffer_ 64else: 65 def b(s): 66 return s 67 68 def l(n): 69 return long(n) 70 71 def unicode_(s): 72 if type(s) == str: 73 import codecs 74 c = codecs.lookup('utf-8') 75 s2 = c.decode(s, 'ignore') 76 return s2[0] 77 return u'%s' % s 78 79 unicode = unicode 80 unichr = unichr 81 long = long 82 buffer = buffer 83