This repository has been archived by the owner on Aug 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug in collation_default. PEP 8. v3.1.3
- Loading branch information
Alberto Pettarin
committed
Sep 23, 2016
1 parent
7682dc1
commit fce6dcf
Showing
25 changed files
with
266 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.1.2 | ||
3.1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,21 +9,19 @@ This is the main Penelope script, intended to be run from command line. | |
|
||
from __future__ import absolute_import | ||
|
||
from penelope import main as package_main | ||
from penelope.__main__ import main as package_main | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.2" | ||
__version__ = "3.1.3" | ||
__email__ = "[email protected]" | ||
__status__ = "Production" | ||
|
||
|
||
def main(): | ||
package_main() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,34 +7,9 @@ | |
This is the main Penelope script, intended to be run from command line. | ||
""" | ||
|
||
from __future__ import absolute_import | ||
import argparse | ||
import sys | ||
|
||
from penelope.__main__ import main | ||
from penelope.command_line import COMMAND_LINE_PARAMETERS | ||
from penelope.command_line import DESCRIPTION | ||
from penelope.command_line import EPILOG | ||
from penelope.command_line import INPUT_FORMATS | ||
from penelope.command_line import OUTPUT_FORMATS | ||
from penelope.command_line import REQUIRED_PARAMETERS | ||
from penelope.command_line import USAGE | ||
from penelope.command_line import check_arguments | ||
from penelope.command_line import set_default_values | ||
from penelope.dictionary import read_dictionary | ||
from penelope.dictionary import write_dictionary | ||
from penelope.utilities import get_uuid | ||
from penelope.utilities import load_input_parser | ||
from penelope.utilities import print_debug | ||
from penelope.utilities import print_error | ||
from penelope.utilities import print_info | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.2" | ||
__version__ = "3.1.3" | ||
__email__ = "[email protected]" | ||
__status__ = "Production" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,10 +31,11 @@ | |
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.2" | ||
__version__ = "3.1.3" | ||
__email__ = "[email protected]" | ||
__status__ = "Production" | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
usage=USAGE, | ||
|
@@ -144,6 +145,3 @@ def main(): | |
|
||
if __name__ == "__main__": | ||
main() | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,18 @@ | |
This is the default collation function (IcuNoCase). | ||
""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from penelope.utilities import utf_lower | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.2" | ||
__version__ = "3.1.3" | ||
__email__ = "[email protected]" | ||
__status__ = "Production" | ||
|
||
|
||
def collate_function(string1, string2): | ||
""" | ||
Implement default IcuNoCase collation, | ||
|
@@ -24,13 +29,10 @@ def collate_function(string1, string2): | |
:type string2: unicode | ||
:rtype: int | ||
""" | ||
b1 = string1.encode("utf-8").lower() | ||
b2 = string2.encode("utf-8").lower() | ||
b1 = utf_lower(string1, encoding="utf-8", lower=True) | ||
b2 = utf_lower(string2, encoding="utf-8", lower=True) | ||
if b1 == b2: | ||
return 0 | ||
if b1 < b2: | ||
elif b1 < b2: | ||
return -1 | ||
return 1 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,19 +5,28 @@ | |
This is a collation function (IcuNoCase) for German. | ||
""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from penelope.utilities import PY2 | ||
from penelope.utilities import utf_lower | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.2" | ||
__version__ = "3.1.3" | ||
__email__ = "[email protected]" | ||
__status__ = "Production" | ||
|
||
|
||
REPLACEMENTS = [ | ||
[u"ä", u"a"], | ||
[u"ö", u"o"], | ||
[u"ü", u"u"], | ||
[u"ß", u"ss"] | ||
] | ||
if PY2: | ||
REPLACEMENTS = [(r.encode("utf-8"), s.encode("utf-8")) for (r, s) in REPLACEMENTS] | ||
|
||
|
||
def collate_function(string1, string2): | ||
""" | ||
|
@@ -32,20 +41,22 @@ def collate_function(string1, string2): | |
""" | ||
b1 = string1.lower() | ||
b2 = string2.lower() | ||
c1 = b1 | ||
c2 = b2 | ||
for repl in REPLACEMENTS: | ||
b1 = b1.replace(repl[0], repl[1]) | ||
b2 = b2.replace(repl[0], repl[1]) | ||
if b1.encode("utf-16") == b2.encode("utf-16"): | ||
if c1.encode("utf-16") == c2.encode("utf-16"): | ||
for (r, s) in REPLACEMENTS: | ||
b1 = b1.replace(r, s) | ||
b2 = b2.replace(r, s) | ||
b1 = utf_lower(b1, encoding="utf-8", lower=True) | ||
b2 = utf_lower(b2, encoding="utf-8", lower=True) | ||
c1 = utf_lower(string1, encoding="utf-8", lower=True) | ||
c2 = utf_lower(string2, encoding="utf-8", lower=True) | ||
d1 = utf_lower(b1, encoding="utf-16", lower=False) | ||
d2 = utf_lower(b2, encoding="utf-16", lower=False) | ||
if d1 == d2: | ||
e1 = utf_lower(c1, encoding="utf-16", lower=False) | ||
e2 = utf_lower(c2, encoding="utf-16", lower=False) | ||
if e1 == e2: | ||
return 0 | ||
if c1.encode("utf-16") < c2.encode("utf-16"): | ||
return -1 | ||
else: | ||
if b1.encode("utf-16") < b2.encode("utf-16"): | ||
if e1 < e2: | ||
return -1 | ||
if d1 < d2: | ||
return -1 | ||
return 1 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.2" | ||
__version__ = "3.1.3" | ||
__email__ = "[email protected]" | ||
__status__ = "Production" | ||
|
||
|
@@ -370,14 +370,14 @@ | |
] | ||
|
||
EXAMPLES = [ | ||
#{ | ||
# "options": "-h", | ||
# "description": "Print this message and exit" | ||
#}, | ||
#{ | ||
# "options": "-v", | ||
# "description": "Print the version and exit" | ||
#}, | ||
# { | ||
# "options": "-h", | ||
# "description": "Print this message and exit" | ||
# }, | ||
# { | ||
# "options": "-v", | ||
# "description": "Print the version and exit" | ||
# }, | ||
{ | ||
"options": "-i dict.csv -j csv -f en -t it -p stardict -o output.zip", | ||
"description": "Convert en->it dictionary dict.csv (in CSV format) into output.zip (in StarDict format)" | ||
|
@@ -450,6 +450,7 @@ | |
EPILOG += u" %s\n" % (example["description"]) | ||
EPILOG += u" \n" | ||
|
||
|
||
def check_arguments(args): | ||
""" | ||
Check that we have all the required command line arguments, | ||
|
@@ -468,6 +469,7 @@ def check_arguments(args): | |
print_error("Valid output formats: %s" % OUTPUT_FORMATS) | ||
sys.exit(4) | ||
|
||
|
||
def set_default_values(args): | ||
def set_default_value(key, value): | ||
if not args.__contains__(key): | ||
|
@@ -519,6 +521,3 @@ def set_default_value(key, value): | |
set_default_value("title", u"Dictionary %s to %s" % (args.language_from, args.language_to)) | ||
set_default_value("website", u"https://goo.gl/EB5XSR") | ||
set_default_value("year", str(datetime.datetime.now().year)) | ||
|
||
|
||
|
Oops, something went wrong.