From 03229174429b030e7ca21d0f9deb6fe51bd42601 Mon Sep 17 00:00:00 2001 From: mhagger Date: Fri, 8 Apr 2011 19:52:58 +0000 Subject: [PATCH] Teach CVSTextDecoder how to fix EOLs. git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5339 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2svn_lib/common.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cvs2svn_lib/common.py b/cvs2svn_lib/common.py index 4d29951b..efbd857b 100644 --- a/cvs2svn_lib/common.py +++ b/cvs2svn_lib/common.py @@ -265,7 +265,7 @@ def format_date(date): class CVSTextDecoder: """Callable that decodes CVS strings into Unicode.""" - def __init__(self, encodings, fallback_encoding=None): + def __init__(self, encodings, fallback_encoding=None, eol_fix=None): """Create a CVSTextDecoder instance. ENCODINGS is a list containing the names of encodings that are @@ -275,6 +275,10 @@ class CVSTextDecoder: should be used as a source encoding in lossy 'replace' mode if all of ENCODINGS failed. + EOL_FIX is the string to which all EOL sequences should be + converted. If it is set to None, then EOL sequences are left + unchanged. + Raise LookupError if any of the specified encodings is unknown.""" self.decoders = [ @@ -287,6 +291,7 @@ class CVSTextDecoder: self.fallback_decoder = ( fallback_encoding, codecs.lookup(fallback_encoding)[1] ) + self.eol_fix = eol_fix def add_encoding(self, encoding): """Add an encoding to be tried in 'strict' mode. @@ -335,7 +340,10 @@ class CVSTextDecoder: raise UnicodeError() def __call__(self, s): - return self.decode(s) + s = self.decode(s) + if self.eol_fix is not None: + s = canonicalize_eol(s, self.eol_fix) + return s class Timestamper: -- 2.11.4.GIT