Permalink
Browse files

OPy's stdlib dependencies can now be compiled with OPy as well.

- Remove unicode character from Python's heapq.py.  The OPy compiler
  doesn't read the '-*- coding: latin-1 -*- line.
- print() conversion in locale and textwrap
  • Loading branch information...
Andy Chu
Andy Chu committed Feb 25, 2018
1 parent 34c7ebc commit 165a5c65e3bfcc18ae540f7b04cdc046ced8317a
Showing with 47 additions and 39 deletions.
  1. +1 −3 Python-2.7.13/Lib/heapq.py
  2. +36 −35 Python-2.7.13/Lib/locale.py
  3. +2 −1 Python-2.7.13/Lib/textwrap.py
  4. +8 −0 scripts/run.sh
@@ -1,6 +1,4 @@
from __future__ import print_function # for OPy compiler
# -*- coding: latin-1 -*-
"""Heap queue algorithm (a.k.a. priority queue).
Heaps are arrays for which a[k] <= a[2*k+1] and a[k] <= a[2*k+2] for
@@ -35,7 +33,7 @@
__about__ = """Heap queues
[explanation by François Pinard]
[explanation by Francois Pinard]
Heaps are arrays for which a[k] <= a[2*k+1] and a[k] <= a[2*k+2] for
all k, counting elements from 0. For the sake of comparison,
@@ -1,3 +1,4 @@
from __future__ import print_function # for OPy compiler
"""Locale support module.
The module provides low-level access to the C lib's locale APIs and adds high
@@ -325,10 +326,10 @@ def _test():
setlocale(LC_ALL, "")
#do grouping
s1 = format("%d", 123456789,1)
print s1, "is", atoi(s1)
print(s1, "is", atoi(s1))
#standard formatting
s1 = str(3.14)
print s1, "is", atof(s1)
print(s1, "is", atof(s1))
### Locale name aliasing engine
@@ -2001,49 +2002,49 @@ def _init_categories(categories=categories):
_init_categories()
del categories['LC_ALL']
print 'Locale defaults as determined by getdefaultlocale():'
print '-'*72
print('Locale defaults as determined by getdefaultlocale():')
print('-'*72)
lang, enc = getdefaultlocale()
print 'Language: ', lang or '(undefined)'
print 'Encoding: ', enc or '(undefined)'
print
print('Language: ', lang or '(undefined)')
print('Encoding: ', enc or '(undefined)')
print()
print 'Locale settings on startup:'
print '-'*72
print('Locale settings on startup:')
print('-'*72)
for name,category in categories.items():
print name, '...'
print(name, '...')
lang, enc = getlocale(category)
print ' Language: ', lang or '(undefined)'
print ' Encoding: ', enc or '(undefined)'
print
print(' Language: ', lang or '(undefined)')
print(' Encoding: ', enc or '(undefined)')
print()
print
print 'Locale settings after calling resetlocale():'
print '-'*72
print()
print('Locale settings after calling resetlocale():')
print('-'*72)
resetlocale()
for name,category in categories.items():
print name, '...'
print(name, '...')
lang, enc = getlocale(category)
print ' Language: ', lang or '(undefined)'
print ' Encoding: ', enc or '(undefined)'
print
print(' Language: ', lang or '(undefined)')
print(' Encoding: ', enc or '(undefined)')
print()
try:
setlocale(LC_ALL, "")
except:
print 'NOTE:'
print 'setlocale(LC_ALL, "") does not support the default locale'
print 'given in the OS environment variables.'
print('NOTE:')
print('setlocale(LC_ALL, "") does not support the default locale')
print('given in the OS environment variables.')
else:
print
print 'Locale settings after calling setlocale(LC_ALL, ""):'
print '-'*72
print()
print('Locale settings after calling setlocale(LC_ALL, ""):')
print('-'*72)
for name,category in categories.items():
print name, '...'
print(name, '...')
lang, enc = getlocale(category)
print ' Language: ', lang or '(undefined)'
print ' Encoding: ', enc or '(undefined)'
print
print(' Language: ', lang or '(undefined)')
print(' Encoding: ', enc or '(undefined)')
print()
###
@@ -2055,10 +2056,10 @@ def _init_categories(categories=categories):
__all__.append("LC_MESSAGES")
if __name__=='__main__':
print 'Locale aliasing:'
print
print('Locale aliasing:')
print()
_print_locale()
print
print 'Number formatting:'
print
print()
print('Number formatting:')
print()
_test()
@@ -1,3 +1,4 @@
from __future__ import print_function # for OPy compiler
"""Text wrapping and filling.
"""
@@ -426,4 +427,4 @@ def dedent(text):
if __name__ == "__main__":
#print dedent("\tfoo\n\tbar")
#print dedent(" \thello there\n \t how are you?")
print dedent("Hello there.\n This is indented.")
print(dedent("Hello there.\n This is indented."))
View
@@ -32,4 +32,12 @@ make-bin-links() {
done
}
# Hm all of the solutions involve grep --perl or perl itself?
# https://stackoverflow.com/questions/3001177/how-do-i-grep-for-all-non-ascii-characters-in-unix
# Found a latin-1 character in Python-2.7.13/Lib/heapq.py. Had to add LC_ALL=C.
grep-unicode() {
LC_ALL=C grep --color='auto' --perl -n '[^\x00-\x7F]' "$@"
}
"$@"

0 comments on commit 165a5c6

Please sign in to comment.