From c1592e8508dc84c5d9f28a9930db5475555813f3 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 4 Jun 2013 22:23:44 +0200 Subject: [PATCH] Code refactoring (moving import ctypes to be used only when needed) --- lib/core/common.py | 3 ++- thirdparty/ansistrm/ansistrm.py | 3 ++- thirdparty/magic/magic.py | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index 25d174d27..676c1df79 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -9,7 +9,6 @@ import codecs import contextlib import cookielib import copy -import ctypes import httplib import inspect import logging @@ -2209,6 +2208,8 @@ def runningAsAdmin(): isAdmin = isinstance(_, (int, float, long)) and _ == 0 elif IS_WIN: + import ctypes + _ = ctypes.windll.shell32.IsUserAnAdmin() isAdmin = isinstance(_, (int, float, long)) and _ == 1 diff --git a/thirdparty/ansistrm/ansistrm.py b/thirdparty/ansistrm/ansistrm.py index c4db309af..eb30b9c6d 100644 --- a/thirdparty/ansistrm/ansistrm.py +++ b/thirdparty/ansistrm/ansistrm.py @@ -1,7 +1,6 @@ # # Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license. # -import ctypes import logging import os import re @@ -84,6 +83,8 @@ class ColorizingStreamHandler(logging.StreamHandler): } def output_colorized(self, message): + import ctypes + parts = self.ansi_esc.split(message) write = self.stream.write h = None diff --git a/thirdparty/magic/magic.py b/thirdparty/magic/magic.py index 3460b4b2e..036983ae0 100644 --- a/thirdparty/magic/magic.py +++ b/thirdparty/magic/magic.py @@ -16,10 +16,6 @@ Usage: import sys import os.path -import ctypes -import ctypes.util - -from ctypes import c_char_p, c_int, c_size_t, c_void_p class MagicException(Exception): pass @@ -104,6 +100,12 @@ def from_buffer(buffer, mime=False): try: libmagic = None + + import ctypes + import ctypes.util + + from ctypes import c_char_p, c_int, c_size_t, c_void_p + # Let's try to find magic or magic1 dll = ctypes.util.find_library('magic') or ctypes.util.find_library('magic1')