summaryrefslogtreecommitdiff
path: root/appdirs.py
diff options
context:
space:
mode:
authorcpburnz <cpburnz@gmail.com>2014-05-07 21:37:22 -0400
committercpburnz <cpburnz@gmail.com>2014-05-07 21:37:22 -0400
commitd75081d4bc71bb4ed1192ba980b417423b18871f (patch)
tree405312b4d49482e6b8f73e9d97c6be7229efefee /appdirs.py
parentf664dec44ce21cc1bd660ecc3fd381c83342ac7d (diff)
downloadappdirs-d75081d4bc71bb4ed1192ba980b417423b18871f.tar.gz
Calculate buffer size once
Diffstat (limited to 'appdirs.py')
-rw-r--r--appdirs.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/appdirs.py b/appdirs.py
index 62a5f88..4a782f7 100644
--- a/appdirs.py
+++ b/appdirs.py
@@ -483,12 +483,13 @@ def _get_win_folder_with_jna(csidl_name):
import array
from com.sun import jna
from com.sun.jna.platform import win32
-
- buf = array.zeros('c', win32.WinDef.MAX_PATH * 2)
+
+ buf_size = win32.WinDef.MAX_PATH * 2
+ buf = array.zeros('c', buf_size)
shell = win32.Shell32.INSTANCE
shell.SHGetFolderPath(None, getattr(win32.ShlObj, csidl_name), None, win32.ShlObj.SHGFP_TYPE_CURRENT, buf)
dir = jna.Native.toString(buf.tostring()).rstrip(u"\0")
-
+
# Downgrade to short path name if have highbit chars. See
# <http://bugs.activestate.com/show_bug.cgi?id=85099>.
has_high_char = False
@@ -497,13 +498,13 @@ def _get_win_folder_with_jna(csidl_name):
has_high_char = True
break
if has_high_char:
- buf = array.zeros('c', win32.WinDef.MAX_PATH * 2)
+ buf = array.zeros('c', buf_size)
kernel = win32.Kernel32.INSTANCE
- if kernal.GetShortPathName(dir, buf, win32.WinDef.MAX_PATH * 2):
+ if kernal.GetShortPathName(dir, buf, buf_size):
dir = jna.Native.toString(buf.tostring()).rstrip(u"\0")
-
+
return dir
-
+
if system == "win32":
try:
import win32com.shell