Comment 6 for bug 256550

Revision history for this message
John A Meinel (jameinel) wrote :

Provided Robert is talking about "punycode": https://designarchitecture.com:19638/docs/en_US/user/oh_user_overview_of_internationalized_domain_names_idn.htm#Translation_of_IDNs

Then no, we are not. I set my host name to:
samus憟

And python socket.gethostname() returned:
'samus\xb5\xe5\x83'

Which can be ".decode('cp1252')" to give the right string. If I try .decode('iso-8859-1') it doesn't convert the ƒ character correctly (it exists in the cp1252 codepage, but *not* in iso-8859-1.

Now, Alexander has actually done the work in win32utils.py to write the function "get_host_name()" which is able to use a Unicode-aware api in windows (!win98) GetComputerNameW. Which returns a proper unicode string:
>>> bzrlib.win32utils.get_host_name()
u'SAMUS\xb5\xc5\u0192'

Note, however, that 'socket.gethostname()' returns the lowercase form at GetComputerNameW() returns the upper-case form. I'm guessing GetComputerNameW is returning the NETBIOS name, which is always in upper case.

Now, according to MSDN, there is another function:
http://msdn.microsoft.com/en-us/library/ms724301(VS.85).aspx

GetComputerNameEx (I assume this will become GetComputerNameExW when appropriate).

If I manually hack together something with cytpes, and I do:

>>> ctypes.windll.kernel32.GetComputerNameExW(3, buf, n)
>>> buf.value
u'samus\xb5\xe5\u0192'

Now, I'm guessing on the COMPUTER_NAME_FORMAT parameter, because it is an enum, and they don't actually mention the mapping. But I'm thinking we might actually want '3' =ComputerNameDnsFullyQualified
http://msdn.microsoft.com/en-us/library/ms724224(VS.85).aspx

So it might just make sense to write an 'osutils.gethostname()' which returns a unicode string, and calls over into GetComputeNameExW on windows when available.