mirror of
https://github.com/erkin/ponysay.git
synced 2025-02-12 07:46:44 +01:00
UTF-8 for the love of celestia
This commit is contained in:
parent
6431e38e4d
commit
e7ed3be525
2 changed files with 21 additions and 13 deletions
34
ponysay
34
ponysay
|
@ -36,6 +36,14 @@ The version of ponysay
|
||||||
VERSION = 'dev' # this line should not be edited, it is fixed by the build system
|
VERSION = 'dev' # this line should not be edited, it is fixed by the build system
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
Hack to enforce UTF-8 in output (in the future, if you see anypony not using utf-8 in programs by default, report them to Princess Celestia so she can banish them to the moon)
|
||||||
|
'''
|
||||||
|
def print(text, end = '\n'):
|
||||||
|
sys.stdout.buffer.write((text + end).encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
This is the mane class of ponysay
|
This is the mane class of ponysay
|
||||||
'''
|
'''
|
||||||
|
@ -111,8 +119,8 @@ class Ponysay():
|
||||||
if os.path.isfile(ucsmap):
|
if os.path.isfile(ucsmap):
|
||||||
mapfile = None
|
mapfile = None
|
||||||
try:
|
try:
|
||||||
mapfile = open(ucsmap, 'r')
|
mapfile = open(ucsmap, 'rb')
|
||||||
maplines += [line.replace('\n', '') for line in mapfile.readlines()]
|
maplines += [line.replace('\n', '') for line in mapfile.read().decode('utf8', 'replace').split('\n')]
|
||||||
finally:
|
finally:
|
||||||
if mapfile is not None:
|
if mapfile is not None:
|
||||||
mapfile.close()
|
mapfile.close()
|
||||||
|
@ -154,8 +162,8 @@ class Ponysay():
|
||||||
if os.path.isfile(ucsmap):
|
if os.path.isfile(ucsmap):
|
||||||
mapfile = None
|
mapfile = None
|
||||||
try:
|
try:
|
||||||
mapfile = open(ucsmap, 'r')
|
mapfile = open(ucsmap, 'rb')
|
||||||
maplines += [line.replace('\n', '') for line in mapfile.readlines()]
|
maplines += [line.replace('\n', '') for line in mapfile.read().decode('utf8', 'replace').split('\n')]
|
||||||
finally:
|
finally:
|
||||||
if mapfile is not None:
|
if mapfile is not None:
|
||||||
mapfile.close()
|
mapfile.close()
|
||||||
|
@ -517,8 +525,8 @@ class Ponysay():
|
||||||
|
|
||||||
balloonstream = None
|
balloonstream = None
|
||||||
try:
|
try:
|
||||||
balloonstream = open(balloonfile, 'r')
|
balloonstream = open(balloonfile, 'rb')
|
||||||
data = [line.replace('\n', '') for line in balloonstream.readlines()]
|
data = [line.replace('\n', '') for line in balloonstream.read().decode('utf8', 'replace').split('\n')]
|
||||||
finally:
|
finally:
|
||||||
if balloonstream is not None:
|
if balloonstream is not None:
|
||||||
balloonstream.close()
|
balloonstream.close()
|
||||||
|
@ -627,7 +635,7 @@ class Ponysay():
|
||||||
for line in output.split('\n')[: lines]:
|
for line in output.split('\n')[: lines]:
|
||||||
print(line)
|
print(line)
|
||||||
else:
|
else:
|
||||||
print(output);
|
print(output)
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
@ -655,8 +663,8 @@ class Ponysay():
|
||||||
pair = pairs[random.randrange(0, len(pairs))]
|
pair = pairs[random.randrange(0, len(pairs))]
|
||||||
qfile = None
|
qfile = None
|
||||||
try:
|
try:
|
||||||
qfile = open(pair[1], 'r')
|
qfile = open(pair[1], 'rb')
|
||||||
args.message = '\n'.join(qfile.readlines()).strip()
|
args.message = qfile.read().decode('utf8', 'replace').strip()
|
||||||
finally:
|
finally:
|
||||||
if qfile is not None:
|
if qfile is not None:
|
||||||
qfile.close()
|
qfile.close()
|
||||||
|
@ -727,8 +735,8 @@ class Ponysay():
|
||||||
else:
|
else:
|
||||||
cachev = None
|
cachev = None
|
||||||
try:
|
try:
|
||||||
cachev = open(cachedir + '/.version', 'r')
|
cachev = open(cachedir + '/.version', 'rb')
|
||||||
if ''.join(cachev.readlines()) == KMS_VERSION:
|
if cachev.read().decode('utf8', 'replace').replace('\n', '') == KMS_VERSION:
|
||||||
newversion = True
|
newversion = True
|
||||||
finally:
|
finally:
|
||||||
if cachev is not None:
|
if cachev is not None:
|
||||||
|
@ -1149,8 +1157,8 @@ class Backend():
|
||||||
def __loadFile(self):
|
def __loadFile(self):
|
||||||
ponystream = None
|
ponystream = None
|
||||||
try:
|
try:
|
||||||
ponystream = open(self.ponyfile, 'r')
|
ponystream = open(self.ponyfile, 'rb')
|
||||||
self.pony = ''.join(ponystream.readlines())
|
self.pony = ponystream.read().decode('utf8', 'replace')
|
||||||
finally:
|
finally:
|
||||||
if ponystream is not None:
|
if ponystream is not None:
|
||||||
ponystream.close()
|
ponystream.close()
|
||||||
|
|
BIN
ponysay.pdf
BIN
ponysay.pdf
Binary file not shown.
Loading…
Reference in a new issue