Jump to content
Korean Random
Sign in to follow this  
Chirimen

[1.0.1/8307] [Fixed] clock in hangar: error with Japanese Windows

Recommended Posts

py_macro/xvm.py puts error, and disabled hanger clock. I used Japanese Windows (CP932).

 

 

2017-04-19 23:24:14: [ERROR] Traceback (most recent call last):
  File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 157, in process_python_macro
    return (func(), deterministic)
  File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 150, in <lambda>
    return (lambda: func(*args), deterministic)
  File "res_mods/configs/xvm/py_macro\xvm.py", line 51, in xvm_formatDate
    t = time.strftime(formatDate).decode(loc)
LookupError: unknown encoding: cp932
arg='xvm.formatDate('%H:%M')'

Edited by Mixaill

Share this post


Link to post

Short link
Share on other sites

py_macro/xvm.py puts error, and disabled hanger clock. I used Japanese Windows (CP932).

 

 

2017-04-19 23:24:14: [ERROR] Traceback (most recent call last):

  File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 157, in process_python_macro

    return (func(), deterministic)

  File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 150, in <lambda>

    return (lambda: func(*args), deterministic)

  File "res_mods/configs/xvm/py_macro\xvm.py", line 51, in xvm_formatDate

    t = time.strftime(formatDate).decode(loc)

LookupError: unknown encoding: cp932

arg='xvm.formatDate('%H:%M')'

func time.strftime() certainly returns CP932 string, but python codecs module in wot does not know encoding CP932, why?

of course, normal python has encoding CP932.  CP932 is used as standard in Japanese Windows.

 

missing codecs are:

 

'big5', 'big5hkscs', 'cp932', 'cp949', 'cp950', 'euc_jp', 'euc_jis_2004', 'euc_jisx0213', 'euc_kr', 'gb2312', 'gbk', 'gb18030', 'hz', 'iso2022_jp', 'iso2022_jp_1', 'iso2022_jp_2', 'iso2022_jp_2004', 'iso2022_jp_3', 'iso2022_jp_ext', 'iso2022_kr', 'johab', 'shift_jis', 'shift_jis_2004', 'shift_jisx0213'

Edited by Chirimen

Share this post


Link to post

Short link
Share on other sites

hi ktulho, thanks patch, but doesn't work with same error.

 

2017-04-21 19:10:24: [ERROR] Traceback (most recent call last):
  File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 157, in process_python_macro
    return (func(), deterministic)
  File "./res_mods/mods/packages\xvm_main\python\python_macro.py", line 150, in <lambda>
    return (lambda: func(*args), deterministic)
  File "res_mods/configs/xvm/py_macro\xvm.py", line 44, in xvm_formatDate
    t = time.strftime(formatDate).decode(locale.getdefaultlocale()[1]).encode('utf8')
LookupError: unknown encoding: cp932
arg='xvm.formatDate('%H:%M')'

 

I think original xvm.py is valid code.

 

encoding cp932 is defined in res/scripts/common/Lib/encodings/cp932.py, and this code exists in WoT.
but cp932.py failed to import _codecs_jp and _multibytecodec, because they doesn't exist.
usually they are builtin python module and dll written in C.

so disabled multibyte encodings, such as cp932, big5 and so on.

Share this post


Link to post

Short link
Share on other sites

if codec is not found, fallback to locale C

# Date and time

import locale
import codecs
d = {}
loc = locale.getdefaultlocale()[1]
try:
    codecs.lookup(loc)
except LookupError:
    locale.setlocale(locale.LC_ALL, 'C')
    loc = 'ascii'

@xvm.export('xvm.formatDate', deterministic=False)
def xvm_formatDate(formatDate):
    def createDict(value, formatDate):
        global d
        s = time.strftime('%{}'.format(value[0])).decode(loc)
        d[value] = s.title() if value[1] == 'u' else s.lower()
        return formatDate.replace('%{}'.format(value), '{%s}' % value)

    global d
    d = {}
    if '%au' in formatDate:
        formatDate = createDict('au', formatDate)
    if '%al' in formatDate:
        formatDate = createDict('al', formatDate)
    if '%Au' in formatDate:
        formatDate = createDict('Au', formatDate)
    if '%Al' in formatDate:
        formatDate = createDict('Au', formatDate)
    if '%bu' in formatDate:
        formatDate = createDict('bu', formatDate)
    if '%bl' in formatDate:
        formatDate = createDict('bl', formatDate)
    if '%Bu' in formatDate:
        formatDate = createDict('Bu', formatDate)
    if '%Bl' in formatDate:
        formatDate = createDict('Bl', formatDate)
    t = time.strftime(formatDate).decode(loc)
    return t.format(**d)

Share this post


Link to post

Short link
Share on other sites

hi Mixaill

in cp932, strftime use only a few multibyte chars, so could translate to utf-8 with short code.

for example,

map_cp932_utf8 = {
    '\x93\xfa': '\xe6\x97\xa5',    # U+65E5, Unicode Han Character 'sun; day; daytime'
    '\x8c\x8e': '\xe6\x9c\x88',    # U+6708, Unicode Han Character 'moon; month; KangXi radical 74'
    '\x89\xce': '\xe7\x81\xab',    # U+706B, Unicode Han Character 'fire, flame; burn; anger, rage'
    '\x90\x85': '\xe6\xb0\xb4',    # U+6C34, Unicode Han Character 'water, liquid, lotion, juice'
    '\x96\xd8': '\xe6\x9c\xa8',    # U+6728, Unicode Han Character 'tree; wood, lumber; wooden'
    '\x8b\xe0': '\xe9\x87\x91',    # U+91D1, Unicode Han Character 'gold; metals in general; money'
    '\x93\x79': '\xe5\x9c\x9f',    # U+571F, Unicode Han Character 'soil, earth; items made of earth'
    '\x97\x6a': '\xe6\x9b\x9c',    # U+66DC, Unicode Han Character 'glorious, as sun; daylight, sunlight; one of the seven planets of pre-modern astronomy (the sun, the moon, Mercury, Venus, Mars, Jupiter, and Saturn)'
    '\x94\x4e': '\xe6\x9b\x9c',    # U+5E74, Unicode Han Character 'year; new-years; person's age'
    '\x8e\x9e': '\xe6\x9b\x9c',    # U+6642, Unicode Han Character 'time, season; era, age, period'
    '\x95\xaa': '\xe6\x9b\x9c',    # U+5206, Unicode Han Character 'divide; small unit of time etc.'
    '\x95\x62': '\xe6\x9b\x9c',    # U+79D2, Unicode Han Character 'beard of grain or corn; a second'
}

def _translate_from_subset_cp932_to_utf8(src):
    dst = ''
    s = ''
    for c in src:
        if s:
            s = s + c
            dst = dst + map_cp932_utf8[s]
            s = ''
        else:
            if ord(c) >= 0x80:
                s = c
                continue
            dst = dst + c
    return dst

sample xvm.py attached, but I don't know other multibyte locale, ie, chinese and  korean. so the sample is only for japanese.

 

more preferable method, all strftime directive is convert to dict.

for py:xvm.formatDate()'s arg allow multibyte chars

 

xvm.zip

post-40275-0-75068100-1492844256.png

Edited by Chirimen

Share this post


Link to post

Short link
Share on other sites

Please try latest nightly build (7414-default). I've build _multibytecodec for WoT, should be fixed.

  • Upvote 1

Share this post


Link to post

Short link
Share on other sites

good. encode/decode is working. thanks to Mixaill.

 

I have one more request.

xvm_formatDate()'s arg formatDate is utf8 string, so formatDate should be translated to loc before send to strftime(), following.

def xvm_formatDate(formatDate):
    def createDict(value, formatDate):
        global d
        s = time.strftime('%{}'.format(value[0])).decode(loc)
        d[value] = s.title() if value[1] == 'u' else s.lower()
        return formatDate.replace('%{}'.format(value), '{%s}' % value)

    global d
    d = {}
    formatDate = formatDate.decode('utf8').encode(loc)
    if '%au' in formatDate:
        formatDate = createDict('au', formatDate)
Edited by Chirimen

Share this post


Link to post

Short link
Share on other sites

in current version, XVM-7.5.6,

clock in hangar is disabled on japanese locale (maybe on other multibyte chars locales).

 

Цитата

 

2018-04-14 12:47:24: [ERROR] Traceback (most recent call last):
  File "res_mods/mods/xfw_packages\xvm_main\python\python_macro.py", line 157, in process_python_macro
    return (func(), deterministic)
  File "res_mods/mods/xfw_packages\xvm_main\python\python_macro.py", line 150, in <lambda>
    return (lambda: func(*args), deterministic)
  File "res_mods/configs/xvm/py_macro\xvm.py", line 61, in xvm_formatDate
    formatDate = formatDate.decode('utf8').encode(_defaultlocale)
LookupError: unknown encoding: cp932
arg='xvm.formatDate('%Y-%m-%d')'


 

 

Share this post


Link to post

Short link
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...