1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#!/usr/bin/env python
# This file is part of python-bidi
#
# python-bidi is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Copyright (C) 2008-2010 Yaacov Zamir <kzamir_a_walla.co.il>,
# Copyright (C) 2010-2015 Meir kriheli <mkriheli@gmail.com>.
"""
Implementation of Unicode Bidirectional Algorithm
http://www.unicode.org/unicode/reports/tr9/
"""
VERSION = '0.4.2'
def main():
"""Will be used to create the console script"""
import optparse
import sys
import codecs
import locale
from .algorithm import get_display
parser = optparse.OptionParser()
parser.add_option('-e', '--encoding',
dest='encoding',
default='utf-8',
type='string',
help='Text encoding (default: utf-8)')
parser.add_option('-u', '--upper-is-rtl',
dest='upper_is_rtl',
default=False,
action='store_true',
help="Treat upper case chars as strong 'R' "
'for debugging (default: False).')
parser.add_option('-d', '--debug',
dest='debug',
default=False,
action='store_true',
help="Output to stderr steps taken with the algorithm")
parser.add_option('-b', '--base-dir',
dest='base_dir',
default=None,
type='string',
help="Override base direction [L|R]")
options, rest = parser.parse_args()
if options.base_dir and options.base_dir not in 'LR':
parser.error('option -b can be L or R')
if rest:
lines = rest
else:
lines = sys.stdin
for line in lines:
display = get_display(line, options.encoding, options.upper_is_rtl,
options.base_dir, options.debug)
# adjust the encoding as unicode, to match the output encoding
if not isinstance(display, str):
display = display.decode(options.encoding)
print(display, end='')
|