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

Read/write text as string and plist as bytes, add tests #23

Merged
merged 2 commits into from Feb 6, 2016

Conversation

moyogo
Copy link
Collaborator

@moyogo moyogo commented Feb 6, 2016

This fixes #19 and adds some minor changes.

  • Read and write text files as utf-8 and Plist as bytes. subpathReadPlist() and subpathWritePlist() don't use subpathReadFile() and subpathWriteFile() anymore.
  • Use unicode_literals.
  • Rename _readPlistFromBytes() and _writePlistToBytes() as _loads() and _dumps().
  • Add unit tests for subpath and modTimes functions.

f = open(path, "rb")
text = f.read()
f.close()
with open(path, "r") as f:
Copy link
Member

Choose a reason for hiding this comment

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

you should specify the encoding="utf-8" here, otherwise io.open will default to the preferred locale encoding, which on windows is not utf-8.

@anthrotype
Copy link
Member

thank you Denis! This looks much better than my hotfix 👍

can you remind me why we can't read/write plist files as unicode strings and we need to use bytes?

def test_subpathWriteFile(self):
expected_text = 'foo bar™'
subpathWriteFile(expected_text, self.directory, self.filename)
with open(self.filepath, 'r') as f:
Copy link
Member

Choose a reason for hiding this comment

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

if instead of trademark symbol here you had used a character which can't be encoded in cp1252, I would expect this test to fail on Windows.

Why are we not testing Windows with appveyor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point! I’ll add encoding="utf-8" to open() in subpathReadFile() and subpathWriteFile() and in the tests.

Appveyor needs to be enabled for the project. We can open an issue about that to ask @typesupply to do that.

miguelsousa added a commit that referenced this pull request Feb 6, 2016
Read/write text as string and plist as bytes, add tests
@miguelsousa miguelsousa merged commit dca1380 into unified-font-object:master Feb 6, 2016
@anthrotype
Copy link
Member

💯

@anthrotype anthrotype mentioned this pull request Feb 6, 2016
@moyogo moyogo deleted the textutf8 branch June 21, 2016 08:43
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

Successfully merging this pull request may close these issues.

String encoding issue
3 participants