~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Patch Queue Manager
  • Date: 2011-12-05 12:23:58 UTC
  • mfrom: (6336.3.3 get_message_encoding)
  • Revision ID: pqm@pqm.ubuntu.com-20111205122358-4vml1qhofl1ll84q
(gz) Add get_message_encoding() for reading encoding name from LC_MESSAGE
 setting (Martin Packman)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2007
2007
    return get_terminal_encoding()
2008
2008
 
2009
2009
 
 
2010
_message_encoding = None
 
2011
 
 
2012
 
 
2013
def get_message_encoding():
 
2014
    """Return the encoding used for messages
 
2015
 
 
2016
    While the message encoding is a general setting it should usually only be
 
2017
    needed for decoding system error strings such as from OSError instances.
 
2018
    """
 
2019
    global _message_encoding
 
2020
    if _message_encoding is None:
 
2021
        if os.name == "posix":
 
2022
            import locale
 
2023
            # This is a process-global setting that can change, but should in
 
2024
            # general just get set once at process startup then be constant.
 
2025
            _message_encoding = locale.getlocale(locale.LC_MESSAGES)[1]
 
2026
        else:
 
2027
            # On windows want the result of GetACP() which this boils down to.
 
2028
            _message_encoding = get_user_encoding()
 
2029
    return _message_encoding or "ascii"
 
2030
        
 
2031
 
2010
2032
def get_host_name():
2011
2033
    """Return the current unicode host name.
2012
2034