You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.3 KiB

import sys
from splunk.clilib.bundle_paths import make_splunkhome_path
'''
py23_helper has some duplicated functions from similar helper in main ITSI application,
however we keep this duplication and eliminate any dependencies on other bundled ITSI apps and libraries
so that License checker module can be deployed separately in distributed setups
'''
string_type = None
'''
Legacy string type:
* in python2 it is a basestring,
* in python3 environment is set to string and bytes types (to be backwards compatible with python2)
'''
def decode(string):
'''
a helper function to decode string:
* in python2 leaves string unchanged since in python2 bytes and str are same
* in python3 decodes bytes into a str
returns str
'''
return string
############ i18n setup ################
def ugettext(message):
"""
Translate a string message
This method is also installed as "_" in builtins
"""
return message
def ungettext(msgid1, msgid2, n):
"""
Translate a string message with a number in it
"""
return msgid1 if n==1 else msgid2
# Check if i18n functions are available (or use stubs)
try:
from splunk.appserver.mrsparkle.lib import i18n
i18n.ugettext('test') # try it out to check if it's functional
ugettext = i18n.ugettext
ungettext = i18n.ungettext
except:
'''No working i18n available - will use stubs for ugettext and ungettext'''
_ = ugettext
############ end of i18n setup ################
if sys.version_info >= (3, 0):
####################################################
# Python 3: specific types, functions and settings #
####################################################
string_type = (str, bytes)
def py3decode(string):
if type(string) is bytes:
return string.decode()
return string
decode = py3decode
import builtins
# global i18n definitions
builtins.__dict__['_'] = ugettext
builtins.__dict__['ungettext'] = ungettext
else:
####################################################
# Python 2: specific types, functions and settings #
####################################################
import __builtin__
string_type = __builtin__.basestring
# global i18n definitions
__builtin__.__dict__['_'] = ugettext
__builtin__.__dict__['ungettext'] = ungettext