Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write error when file contents not utf8 encoded #10

Closed
goodboy opened this issue Jan 10, 2016 · 4 comments
Closed

Write error when file contents not utf8 encoded #10

goodboy opened this issue Jan 10, 2016 · 4 comments
Assignees

Comments

@goodboy
Copy link

goodboy commented Jan 10, 2016

I get the following error if my input file corpus is not utf8 encoded:

Traceback (most recent call last):                                      
  File "replace.py", line 50, in <module>                               
    dry_run=False,                                                      
  File "/home/tyler/repos/massedit/massedit.py", line 440, in edit_files
    diffs = list(editor.edit_file(path))                                
  File "/home/tyler/repos/massedit/massedit.py", line 202, in edit_file 
    new_file.writelines(to_lines)                                       
TypeError: must be unicode, not str                                     

A change to https://github.com/elmotec/massedit/blob/master/massedit.py#L202
resolves this:

new_file.writelines(line.decode('utf8') for line in to_lines)

I can provide a PR if necessary.

@elmotec
Copy link
Owner

elmotec commented Jan 18, 2016

Ok. I am not sure I understand the fix though.

I suppose utf-8 should not be hard-coded anyway. I'd rather add an option that specifies the encoding with utf-8 as default.

@elmotec elmotec self-assigned this Jan 18, 2016
@elmotec
Copy link
Owner

elmotec commented Jan 19, 2016

Hey @tgoodlet, Could you attach a small example file that reproduces the problem, please? Just to make sure it's fixed for you at least.

@goodboy
Copy link
Author

goodboy commented Jan 25, 2016

I can't seem to reproduce after reverting the change. I'll close this for now until I hit it again (if I ever do).

@goodboy goodboy closed this as completed Jan 25, 2016
@elmotec
Copy link
Owner

elmotec commented Jan 27, 2016

No problem. I think it's not right to assume utf-8 for all input files. I've made changes to allow the user to specify the encoding. I'll polish and commit this week end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants