Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix issue with unicode arguments to __main__
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Apr 25, 2015
1 parent 8cb66c2 commit a73ed63
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion nikola/__main__.py
Expand Up @@ -74,7 +74,7 @@ def main(args=None):
conf_filename = 'conf.py'
conf_filename_changed = False
for index, arg in enumerate(args):
if arg[:7] == '--conf=':
if arg[:7] == b'--conf=':
del args[index]
conf_filename = arg[7:]
conf_filename_changed = True
Expand Down

9 comments on commit a73ed63

@felixfontein
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a problem with Python 3: 'a' == b'a' under Python 2, while 'a' != b'a' under Python 3. Now under Python 3, repr(arg[:7]) is '--conf=' for me, whence the two strings are never equal and I get ERROR: Nikola: Unknown command --conf=xxx.

@felixfontein
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Replacing b'--conf=' with '--conf=' helps, or replacing arg[:7] by arg[:7].encode('utf-8').)

@Kwpolska
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind figuring a solution that works with both Pythons and making a PR?

@felixfontein
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the motivation to change '--conf=' to b'--conf=' in the first place? I think before this change it was working fine.

@Kwpolska
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wasn’t, we were getting “cannot coerce to Unicode” errors if there were Unicode arguments (which can happen with nikola new_post -t, for instance)

@felixfontein
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then adding .encode('utf-8') to arg is probably the best fix. From what I understand, this works fine under Python 2 and Python 3, and shouldn't exhibit the "cannot coerce to Unicode" errors. What do you think?

This also affects some more settings parsing in main.py, I think.

@Kwpolska
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t have time to look into this further, I’ll try to come up with a solution tomorrow. And yes, we would need to fix every argument check in the file.

@felixfontein
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you had a chance to look at it?

@Kwpolska
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn’t have time; see #1738

Please sign in to comment.