-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of relying on the default encoding (LANG, LC_*), force encoding of read and written files to UTF-8. Also add some test cases for UTF-8 text. Bump patch version.
- Loading branch information
Showing
4 changed files
with
25 additions
and
26 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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
will split `mycal.ics` into outcal1.ics outcal2.ics outcal3.cs... | ||
""" | ||
|
||
__version__ = '1.0.0' | ||
__version__ = '1.0.1' | ||
__author__ = 'Bjorn Stabell <[email protected]>' | ||
__all__ = [] | ||
|
||
|
@@ -26,11 +26,11 @@ | |
logger = logging.getLogger(__name__) | ||
log = logger.info | ||
|
||
|
||
BEGIN_CALENDAR = 'BEGIN:VCALENDAR' | ||
END_CALENDAR = 'END:VCALENDAR' | ||
BEGIN_EVENT = 'BEGIN:VEVENT' | ||
END_EVENT = 'END:VEVENT' | ||
enc = {'encoding': 'utf8'} # don't rely on LANG, force encoding to UTF-8 | ||
|
||
def icssplit(src, maxsize): | ||
"""\ | ||
|
@@ -93,11 +93,12 @@ def cli(): | |
outfile_base = args['OUTFILE'] or infile | ||
maxsize = int(args['--maxsize'] or 0) or 1024*1024*0.9 | ||
|
||
|
||
log(f"parsing {infile} and splitting into files of maxsize={maxsize}") | ||
for (indx, outf) in enumerate(icssplit(open(infile, 'r'), maxsize)): | ||
for (indx, outf) in enumerate(icssplit(open(infile, 'r', **enc), maxsize)): | ||
outfile = f"{outfile_base}-{indx}.ics" | ||
log(f"writing {outfile}") | ||
with open(outfile, 'w') as fh: | ||
with open(outfile, 'w', **enc) as fh: | ||
fh.write(outf) | ||
|
||
if __name__ == '__main__': cli() |
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