banksalad / K-Format

🇰🇷 Python library for Korean style fixed length format definition(전문 통신)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UnicodeEncodeError

gpeddler opened this issue · comments

cases

  • 동아・한신아파트
>>> a = '동아・한신아파트'
>>> a.encode('euc-kr')
UnicodeEncodeError: 'euc_kr' codec can't encode character '\u30fb' in position 2: illegal multibyte sequence

에러 재현 확인
아래처럼 해결 가능

>>> a.encode('euc-kr', errors='ignore').decode('euc-kr')
'동아한신아파트'
>>> a.encode('euc-kr', errors='replace').decode('euc-kr')
'동아?한신아파트'

위 로직이 kproperty에 반영되어야함

ignore 시키는것과 default인 strict에서 발생하는 UnicodeError를 catch해 KFormatError를 발생시키는것 중에 어떤게 나을까요? 혹은 anything else? @sunghyunzz
이 에러를 과연 K-Format에서 핸들링해야하는가 에 대한 논의도 좋습니당

3가지 Enum 타입 제공. strict, ignore, replace. 기본은 ignore.
replace의 확장성까지는 일단 고려하지 않기로 메인테이너(@sunghyunzz )와 합의

생성자에 errors를 두는 방식으로 구현해보겠습니다..