[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/master] Replacing uiTools isUnicodeAvailable()
commit d48a9be3030090b1365c87a59a3b0399259fba8a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Jan 11 17:06:17 2014 -0800
Replacing uiTools isUnicodeAvailable()
Cleaning up our uiTools function for determining if curses supports unicode or
not. We don't need the caching of isUnicodeAvailable() nor did it help with
readability so dropping that. We still need the function for determining if
curses has wide character support though so just tweaking that to be PEP8
compliant.
---
arm/starter.py | 7 +++++-
arm/util/uiTools.py | 66 ++++++++++++++++-----------------------------------
2 files changed, 27 insertions(+), 46 deletions(-)
diff --git a/arm/starter.py b/arm/starter.py
index 48611f3..c974f2c 100644
--- a/arm/starter.py
+++ b/arm/starter.py
@@ -251,7 +251,12 @@ def _use_unicode():
initializing curses.
"""
- if arm.util.uiTools.isUnicodeAvailable():
+ if not CONFIG.get('features.printUnicode', True):
+ return
+
+ is_lang_unicode = "utf-" in os.getenv("LANG", "").lower()
+
+ if is_lang_unicode and arm.util.uiTools.is_wide_characters_supported():
locale.setlocale(locale.LC_ALL, '')
diff --git a/arm/util/uiTools.py b/arm/util/uiTools.py
index 1682e50..1eb413a 100644
--- a/arm/util/uiTools.py
+++ b/arm/util/uiTools.py
@@ -5,7 +5,6 @@ easy method of providing the following interface components:
- unit conversion for labels
"""
-import os
import sys
import curses
@@ -40,13 +39,8 @@ CONFIG = conf.config_dict("arm", {
"features.colorOverride": "none",
"features.colorInterface": True,
"features.acsSupport": True,
- "features.printUnicode": True,
}, conf_handler)
-# Flag indicating if unicode is supported by curses. If None then this has yet
-# to be determined.
-IS_UNICODE_SUPPORTED = None
-
def demoGlyphs():
"""
Displays all ACS options with their corresponding representation. These are
@@ -94,27 +88,6 @@ def _showGlyphs(stdscr):
stdscr.getch() # quit on keyboard input
-def isUnicodeAvailable():
- """
- True if curses has wide character support, false otherwise or if it can't be
- determined.
- """
-
- global IS_UNICODE_SUPPORTED
- if IS_UNICODE_SUPPORTED == None:
- if CONFIG["features.printUnicode"]:
- # Checks if our LANG variable is unicode. This is what will be respected
- # when printing multi-byte characters after calling...
- # locale.setlocale(locale.LC_ALL, '')
- #
- # so if the LANG isn't unicode then setting this would be pointless.
-
- isLangUnicode = "utf-" in os.getenv("LANG", "").lower()
- IS_UNICODE_SUPPORTED = isLangUnicode and _isWideCharactersAvailable()
- else: IS_UNICODE_SUPPORTED = False
-
- return IS_UNICODE_SUPPORTED
-
def getPrintable(line, keepNewlines = True):
"""
Provides the line back with non-printable characters stripped.
@@ -453,20 +426,18 @@ class Scroller:
return True
else: return False
-def _isWideCharactersAvailable():
+def is_wide_characters_supported():
"""
- True if curses has wide character support (which is required to print
- unicode). False otherwise.
+ Checks if our version of curses has wide character support. This is required
+ to print unicode.
+
+ :returns: **bool** that's **True** if curses supports wide characters, and
+ **False** if it either can't or this can't be determined
"""
try:
- # gets the dynamic library used by the interpretor for curses
-
- import _curses
- cursesLib = _curses.__file__
-
- # Uses 'ldd' (Linux) or 'otool -L' (Mac) to determine the curses
- # library dependencies.
+ # Gets the dynamic library used by the interpretor for curses. This uses
+ # 'ldd' on Linux or 'otool -L' on OSX.
#
# atagar@fenrir:~/Desktop$ ldd /usr/lib/python2.6/lib-dynload/_curses.so
# linux-gate.so.1 => (0x00a51000)
@@ -482,16 +453,21 @@ def _isWideCharactersAvailable():
# /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
# /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.6)
- libDependencyLines = None
+ import _curses
+
+ lib_dependency_lines = None
+
if system.is_available("ldd"):
- libDependencyLines = system.call("ldd %s" % cursesLib)
+ lib_dependency_lines = system.call("ldd %s" % _curses.__file__)
elif system.is_available("otool"):
- libDependencyLines = system.call("otool -L %s" % cursesLib)
-
- if libDependencyLines:
- for line in libDependencyLines:
- if "libncursesw" in line: return True
- except: pass
+ lib_dependency_lines = system.call("otool -L %s" % _curses.__file__)
+
+ if lib_dependency_lines:
+ for line in lib_dependency_lines:
+ if "libncursesw" in line:
+ return True
+ except:
+ pass
return False
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits