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

OFX Spec Compliance Fixes #332

Merged
merged 5 commits into from
Jan 16, 2025
Merged

Conversation

Holzhaus
Copy link
Contributor

@Holzhaus Holzhaus commented Jan 11, 2025

This makes it possible to import the output of ofxstatement with Denaro. See #327 (comment) for detailed explanations.

Fixes #327.

encoded = str(encoded, "utf-8")
encoding = "cp1252"
encoded = etree.tostring(et.getroot(), encoding)
encoded = str(encoded, encoding)
Copy link
Owner

Choose a reason for hiding this comment

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

I assume this breaks any outputs with characters outside of cp1252 encoding (IOW, this will probably break ofxstatement for a lot of users, including me). This doesn't seem right.

Regarding the encoding, you seem to refer to some ancient OFX spec from 1999 in #327 (comment). We shouldn't be stuck with such an old version in 2025.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose it depends on the support by other tools. If OFX 1.0.2 is more widely supported, it makes sense to stick with that unless there is a reason to upgrade.

The 1.0.2 spec talks about ENCODING:UNICODE, and the OFX 2.2 spec implies that this referred to UTF-8. Most tools (e.g. GnuCash) support UNICODE, we can just use that. OfxSharp which is used by Denaro does not support it, but I think this should be fixed upstream, not worked around here.

FYI, we are not the only ones struggling with OFX encoding: https://github.com/wesabe/fixofx/blob/1792d94697af682ca1d4a75cfefe98465d95a288/lib/ofx/document.py#L27-L42 😅

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I agree, just having it as UNICODE would be fine. From what I remember I didn't specifically chose OFX 1.0.2 for compatibility, but it was just what was in some sample file I used in initial implementation. So we can be flexible here, as long as consuming tools are ok with that.

For this case, I'm fine if the encoding would be UNICODE instead of UTF-8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I noticed that the encoding is already configurable, so I made the OFX writer respect that. If "utf-8" is used, it will use ENCODING:UNICODE and CHARSET:NONE, if cp1252 is used it will use ENCODING:USASCII and CHARSET:1252.

For other charsets, it will try to handle this gracefully by using a nonstandard charset. Alternatively, we could raise an error.

@Holzhaus Holzhaus force-pushed the ofx-spec-compliance branch from afba71f to e21fde6 Compare January 12, 2025 12:53
Copy link
Owner

@kedder kedder left a comment

Choose a reason for hiding this comment

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

This looks good, just please fix the tests.

@Holzhaus Holzhaus force-pushed the ofx-spec-compliance branch 2 times, most recently from edcb14c to ebfe884 Compare January 12, 2025 22:29
@Holzhaus Holzhaus force-pushed the ofx-spec-compliance branch from ebfe884 to febd0c3 Compare January 12, 2025 22:30
@kedder
Copy link
Owner

kedder commented Jan 15, 2025

I checked on my files and it seems good. So, just run make to blacken the files and I think this should be good to go.

@Holzhaus
Copy link
Contributor Author

Holzhaus commented Jan 16, 2025

Will do tomorrow (if you don't want to wait you should also be able to do it yourself and push to this branch).

By the way, have you considered using https://pre-commit.com/ instead of make? It's huge DX improvement IMHO and also keeps the git history clean because you avoid "Fix formatting" commits.

@kedder
Copy link
Owner

kedder commented Jan 16, 2025

pre-commit is a good idea. I'll add it.

@coveralls
Copy link

Coverage Status

coverage: 95.791% (-0.5%) from 96.25%
when pulling 64ed6cb on Holzhaus:ofx-spec-compliance
into dfcbf12 on kedder:master.

@kedder
Copy link
Owner

kedder commented Jan 16, 2025

Okay, tests look good. I'm merging it. Thanks a lot!

Do you want a new release?

@kedder kedder merged commit 198142b into kedder:master Jan 16, 2025
9 of 10 checks passed
@Holzhaus Holzhaus deleted the ofx-spec-compliance branch January 16, 2025 20:58
@Holzhaus
Copy link
Contributor Author

Do you want a new release?

Not urgent to me, I'm using ofxstatement in a venv anyway. 🙂

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.

OFX cannot be imported by Denaro
3 participants