Here are the examples of the python api sys.setdefaultencoding taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
44 Examples
3
View Complete Implementation : site.py
Copyright Apache License 2.0
Author : acaceres2176
Copyright Apache License 2.0
Author : acaceres2176
def setencoding():
"""Set the string encoding used by the Unicode implementation. The
default is 'ascii', but if you're willing to experiment, you can
change this."""
encoding = "ascii" # Default value set by _PyUnicode_Init()
if 0:
# Enable to support locale aware default string encodings.
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]
if 0:
# Enable to switch off string to Unicode coercion and implicit
# Unicode to string conversion.
encoding = "undefined"
if encoding != "ascii":
# On Non-Unicode builds this will raise an AttributeError...
sys.setdefaultencoding(encoding) # Needs Python Unicode build !
3
View Complete Implementation : test_log.py
Copyright MIT License
Author : adde88
Copyright MIT License
Author : adde88
def tearDown(self):
for chunk in self.out:
self.failUnless(isinstance(chunk, str), "%r was not a string" % (chunk,))
# sick you very much.
sys.setdefaultencoding(self._origEncoding)
del sys.setdefaultencoding
3
View Complete Implementation : clear_running.py
Copyright GNU Lesser General Public License v3.0
Author : awolfly9
Copyright GNU Lesser General Public License v3.0
Author : awolfly9
def handle(self, *args, **options):
reload(sys)
sys.setdefaultencoding('utf-8')
spargs = utils.arglist_to_dict(options['spargs'])
key = spargs.get('key', 'running')
os.chdir(sys.path[0])
red = redis.StrictRedis(host = config.redis_host, port = config.redis_part, db = config.redis_db,
pastword = config.redis_past)
res = red.get(key)
if res != None:
info = json.loads(res)
info['name'] = 'clear_running'
info['error_msg'] = 'interrupt error'
red.lpush('retry_list', info)
red.delete(key)
3
View Complete Implementation : __main__.py
Copyright GNU General Public License v3.0
Author : BlendedSiteGenerator
Copyright GNU General Public License v3.0
Author : BlendedSiteGenerator
@cli.command('build', short_help='Build the Blended files into a website')
@click.option('--outdir', default="build", help='Choose which folder to build to. Default is `build`.')
def build(outdir):
"""Blends the generated files and outputs a HTML website"""
print("Building your Blended files into a website!")
reload(sys)
sys.setdefaultencoding('utf8')
build_files(outdir)
print("The files are built! You can find them in the " + outdir +
"/ directory. Run the view command to see what you have created in a web browser.")
3
View Complete Implementation : __main__.py
Copyright GNU General Public License v3.0
Author : BlendedSiteGenerator
Copyright GNU General Public License v3.0
Author : BlendedSiteGenerator
@cli.command('interactive', short_help='Build the Blended files into a website on each file change')
@click.option('--outdir', default="build", help='Choose which folder to build to. Default is `build`.')
def interactive(outdir):
"""Blends the generated files and outputs a HTML website on file change"""
print("Building your Blended files into a website!")
global outdir_type
outdir_type = outdir
reload(sys)
sys.setdefaultencoding('utf8')
build_files(outdir)
print("Watching the content and templates directories for changes, press CTRL+C to stop...\n")
w = Watcher()
w.run()
3
View Complete Implementation : XlsFileUtil.py
Copyright MIT License
Author : CatchZeng
Copyright MIT License
Author : CatchZeng
def __init__(self, filePath):
self.filePath = filePath
# get all sheets
reload(sys)
sys.setdefaultencoding('utf-8')
self.data = xlrd.open_workbook(filePath)
3
View Complete Implementation : alipayapi.py
Copyright Apache License 2.0
Author : edisonlz
Copyright Apache License 2.0
Author : edisonlz
def get_sign(self, para_str, sign_type="RSA2"):
#对参数排序
import OpenSSL
###############################################
# 这里需要支付宝支付私钥文件 #
###############################################
root = os.path.realpath(os.path.dirname(__file__))
ali_private_path = os.path.join(root, "ali_private2048.txt")
private_key = OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, open(ali_private_path).read())
import sys
reload(sys)
sys.setdefaultencoding('utf-8') #这三句:解决签名方法编码报错
sign = base64.encodestring(OpenSSL.crypto.sign(private_key, para_str, 'sha256'))
return sign
3
View Complete Implementation : dispatcher.py
Copyright Apache License 2.0
Author : ibm-research
Copyright Apache License 2.0
Author : ibm-research
def run(self, *args, **kwargs):
reload(sys)
sys.setdefaultencoding('utf8')
if len(sys.argv) == 2 and str(sys.argv[1]) == "1":
self.logger.debug('Polling the requests queue')
print 'Polling the requests queue'
self.process_next_request()
return
else:
while True:
if len(sys.argv) >= 2:
print 'Polling the requests queue'
self.logger.debug('Polling the requests queue')
self.process_next_request()
if self.found_empty_queue:
sleep(5) # TODO: make polling frequency more adaptive
3
View Complete Implementation : io.py
Copyright GNU General Public License v3.0
Author : JacksonWuxs
Copyright GNU General Public License v3.0
Author : JacksonWuxs
def encode(code='cp936'):
'''change the python environment encode
'''
import sys
if sys.version_info.major == 2:
stdi, stdo, stde = sys.stdin, sys.stdout, sys.stderr
reload(sys)
sys.stdin, sys.stdout, sys.stderr = stdi, stdo, stde
from sys import setdefaultencoding
setdefaultencoding(code)
3
View Complete Implementation : new_tests.py
Copyright MIT License
Author : JBKahn
Copyright MIT License
Author : JBKahn
def tearDown(self):
import sys
if PY2:
reload(sys)
sys.setdefaultencoding(self.old_encoding)
super(TestRedNoseEncoding, self).tearDown()