Package rhn :: Module i18n
[hide private]
[frames] | no frames]

Source Code for Module rhn.i18n

 1  # 
 2  # This module contains all the RPC-related functions the RHN code uses 
 3  # 
 4  # Copyright (c) 2016 Red Hat, Inc. 
 5  # 
 6  # This software is licensed to you under the GNU General Public License, 
 7  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 8  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 9  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
10  # along with this software; if not, see 
11  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
12  # 
13  # Red Hat trademarks are not licensed under GPLv2. No permission is 
14  # granted to use or replicate Red Hat trademarks that are incorporated 
15  # in this software or its documentation. 
16  # 
17   
18  from sys import version_info 
19   
20  try: 
21      PY3 = version_info.major >= 3 
22  except AttributeError: 
23      PY3 = False 
24   
25   
26 -def ustr(obj):
27 # converts object to unicode like object 28 if PY3: # python3 29 if isinstance(obj, str): 30 return obj 31 else: 32 return str(obj, 'utf8', errors='ignore') 33 else: # python2 34 if isinstance(obj, unicode): 35 return obj 36 return unicode(obj, 'utf8', 'ignore')
37
38 -def bstr(obj):
39 # converts object to bytes like object 40 if PY3: # python3 41 if isinstance(obj, bytes): 42 return obj 43 else: 44 return bytes(obj, 'utf8', errors='ignore') 45 else: # python2 46 if isinstance(obj, str): 47 return obj 48 return str(obj.encode('utf8', 'ignore'))
49
50 -def sstr(obj):
51 # converts object to string 52 if PY3: # python3 53 if isinstance(obj, str): 54 return obj 55 else: 56 return str(obj, 'utf8', errors='ignore') 57 else: # python2 58 if isinstance(obj, str): 59 return obj 60 return str(obj.encode('utf8', 'ignore'))
61