~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Packman
  • Date: 2011-12-02 13:36:43 UTC
  • mto: This revision was merged to the branch mainline in revision 6344.
  • Revision ID: martin.packman@canonical.com-20111202133643-0j1f9botvq8d61ar
Add get_message_encoding() for use in decoding system messages

Show diffs side-by-side

added added

removed removed

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