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 problem with escape sequences in CSV files
- Loading branch information
Alberto Pettarin
committed
Feb 16, 2016
1 parent
6589d13
commit d4d07dc
Showing
25 changed files
with
83 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2012-2015 Alberto Pettarin ([email protected]) | ||
Copyright (c) 2012-2016 Alberto Pettarin ([email protected]) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
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.1 | ||
3.1.2 |
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 |
---|---|---|
|
@@ -12,9 +12,9 @@ from __future__ import absolute_import | |
from penelope import main as package_main | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -30,9 +30,9 @@ | |
from penelope.utilities import print_info | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -29,9 +29,9 @@ | |
from penelope.utilities import print_info | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -6,9 +6,9 @@ | |
""" | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -6,9 +6,9 @@ | |
""" | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -13,9 +13,9 @@ | |
from penelope.utilities import print_error | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -24,9 +24,9 @@ | |
from penelope.utilities import print_error | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -16,9 +16,9 @@ | |
from penelope.utilities import delete_directory | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -21,9 +21,9 @@ | |
from penelope.utilities import delete_directory | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -12,24 +12,42 @@ | |
from penelope.utilities import print_error | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__email__ = "[email protected]" | ||
__status__ = "Production" | ||
|
||
ASCII_ESCAPES = [ | ||
("\\a", "\a"), | ||
("\\b", "\b"), | ||
("\\t", "\t"), | ||
("\\n", "\n"), | ||
("\\v", "\v"), | ||
("\\f", "\f"), | ||
("\\r", "\r") | ||
] | ||
|
||
def escape(string): | ||
ret = string | ||
for s, r in ASCII_ESCAPES: | ||
ret = ret.replace(s, r) | ||
return ret | ||
|
||
def read(dictionary, args, input_file_paths): | ||
csv_fs = escape(args.csv_fs) | ||
csv_ls = escape(args.csv_ls) | ||
for input_file_path in input_file_paths: | ||
print_debug("Reading from file '%s'..." % (input_file_path), args.debug) | ||
input_file_object = open(input_file_path, "rb") | ||
data_bytes = input_file_object.read() # bytes | ||
data_unicode = data_bytes.decode(args.input_file_encoding) # unicode | ||
input_file_object.close() | ||
lines = data_unicode.split(args.csv_ls) | ||
lines = data_unicode.split(csv_ls) | ||
if args.csv_ignore_first_line: | ||
lines = lines[1:] | ||
for line in lines: | ||
array = line.split(args.csv_fs) | ||
array = line.split(csv_fs) | ||
if len(array) >= 2: | ||
headword = array[0] | ||
definition = line[len(headword) + 1:] | ||
|
@@ -40,16 +58,18 @@ def read(dictionary, args, input_file_paths): | |
return dictionary | ||
|
||
def write(dictionary, args, output_file_path): | ||
csv_fs = escape(args.csv_fs) | ||
csv_ls = escape(args.csv_ls) | ||
try: | ||
print_debug("Writing to file '%s'..." % (output_file_path), args.debug) | ||
output_file_obj = open(output_file_path, "wb") | ||
for index in dictionary.entries_index_sorted: | ||
entry = dictionary.entries[index] | ||
string = u"%s%s%s%s" % ( | ||
entry.headword, | ||
args.csv_fs, | ||
csv_fs, | ||
entry.definition, | ||
args.csv_ls | ||
csv_ls | ||
) | ||
output_file_obj.write(string.encode("utf-8")) | ||
output_file_obj.close() | ||
|
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 |
---|---|---|
|
@@ -20,9 +20,9 @@ | |
from penelope.utilities import print_info | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -37,9 +37,9 @@ | |
from penelope.utilities import rename_file | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -21,9 +21,9 @@ | |
from penelope.utilities import delete_directory | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -22,9 +22,9 @@ | |
from penelope.utilities import print_info | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -13,9 +13,9 @@ | |
from penelope.utilities import print_error | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -9,9 +9,9 @@ | |
""" | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -7,9 +7,9 @@ | |
""" | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -6,9 +6,9 @@ | |
""" | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -6,9 +6,9 @@ | |
""" | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -16,9 +16,9 @@ | |
import uuid | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__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 |
---|---|---|
|
@@ -8,17 +8,17 @@ | |
from setuptools import setup, Extension | ||
|
||
__author__ = "Alberto Pettarin" | ||
__copyright__ = "Copyright 2012-2015, Alberto Pettarin (www.albertopettarin.it)" | ||
__copyright__ = "Copyright 2012-2016, Alberto Pettarin (www.albertopettarin.it)" | ||
__license__ = "MIT" | ||
__version__ = "3.1.1" | ||
__version__ = "3.1.2" | ||
__email__ = "[email protected]" | ||
__status__ = "Production" | ||
|
||
setup( | ||
name="penelope", | ||
packages=["penelope"], | ||
package_data={"penelope": ["res/*"]}, | ||
version="3.1.1.1", | ||
version="3.1.2.0", | ||
description="Penelope is a multi-tool for creating, editing and converting dictionaries, especially for eReader devices", | ||
author="Alberto Pettarin", | ||
author_email="[email protected]", | ||
|