commit:     728b5d1c32773422f0b3e658d16116f6883ee9d2
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed May  7 01:21:28 2014 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed May  7 01:21:28 2014 +0000
URL:        
http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=728b5d1c

roverlay/util/fileio, write_text_file: accept str

---
 roverlay/util/fileio.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/roverlay/util/fileio.py b/roverlay/util/fileio.py
index 804aa9f..d4019d7 100644
--- a/roverlay/util/fileio.py
+++ b/roverlay/util/fileio.py
@@ -128,6 +128,7 @@ def write_text_file (
    newline='\n'
 ):
    compress_open = get_compress_open ( compression ) if compression else None
+   lines_iter    = ( lines, ) if isinstance ( lines, str ) else lines
 
    if create_dir:
       roverlay.util.common.dodir_for_file ( filepath )
@@ -135,7 +136,7 @@ def write_text_file (
    if compress_open:
       NL = newline.encode()
       with compress_open ( filepath, mode.rstrip ( 'tu' ) ) as CH:
-         for line in lines:
+         for line in lines_iter:
             CH.write ( str ( line ).encode() )
             if append_newlines:
                CH.write ( NL )
@@ -144,7 +145,7 @@ def write_text_file (
             CH.write ( NL )
    else:
       with open ( filepath, mode ) as FH:
-         for line in lines:
+         for line in lines_iter:
             FH.write ( str ( line ) )
             if append_newlines:
                FH.write ( newline )

Reply via email to