Last active
May 28, 2023 04:25
-
-
Save hMatoba/efdfd5c0d13a4ee1ca2d1d4094c53a31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
バイナリ ⇔ 文字列 の相互変換をするだけなので楽 | |
http://www.cipa.jp/std/documents/j/DC-008-2012_J.pdf | |
ページ49 / 195のUserComment参照 | |
UserCommentフィールドの値を バイナリ⇔文字列型 の変換する関数の実装 | |
piexif/_helper.pyに実装 | |
引数、返り値などは下記のような具合に | |
def load(data): | |
""" | |
Convert "UserComment" value in exif format to str. | |
:param bytes data: "UserComment" value from exif | |
:return: u"foobar" | |
:rtype: str(Unicode) | |
""" | |
def dump(data, encoding="ascii"): | |
""" | |
Convert str to appropriate format for "UserComment". | |
:param data: Like u"foobar" | |
:param str encoding: "ascii", "jis", or "unicode" | |
:return: b"ASCII\x00\x00\x00foobar" | |
:rtype: bytes | |
""" | |
テスト -> "python setup.py test" -> VisualStudioがあれば、ソリューションを読み込むだけでテストエクスプローラから簡単にできる | |
tests/s_test.py | |
test_load_user_comment | |
test_dump_user_comment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UNDEFINEDに関しては、UNDEFINEDとされている時点でエンコードもデコードもできない。
・入力をそのまま返す→ASCIIやJISの場合と返す値が一致しなくなるので嫌
・latinでエンコード、デコード→違ってない?違ってる
・Noneを返す→名案がないときの落としどころ
・Exceptionを上げる→ValueErrorあたりで「UNDEFINEDだからどうにもできないよ」的なメッセージを出す