Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c1592e8

Browse files
committed
Code refactoring (moving import ctypes to be used only when needed)
1 parent 3e0f747 commit c1592e8

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

lib/core/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import contextlib
1010
import cookielib
1111
import copy
12-
import ctypes
1312
import httplib
1413
import inspect
1514
import logging
@@ -2209,6 +2208,8 @@ def runningAsAdmin():
22092208

22102209
isAdmin = isinstance(_, (int, float, long)) and _ == 0
22112210
elif IS_WIN:
2211+
import ctypes
2212+
22122213
_ = ctypes.windll.shell32.IsUserAnAdmin()
22132214

22142215
isAdmin = isinstance(_, (int, float, long)) and _ == 1

thirdparty/ansistrm/ansistrm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#
22
# Copyright (C) 2010-2012 Vinay Sajip. All rights reserved. Licensed under the new BSD license.
33
#
4-
import ctypes
54
import logging
65
import os
76
import re
@@ -84,6 +83,8 @@ def output_colorized(self, message):
8483
}
8584

8685
def output_colorized(self, message):
86+
import ctypes
87+
8788
parts = self.ansi_esc.split(message)
8889
write = self.stream.write
8990
h = None

thirdparty/magic/magic.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616

1717
import sys
1818
import os.path
19-
import ctypes
20-
import ctypes.util
21-
22-
from ctypes import c_char_p, c_int, c_size_t, c_void_p
2319

2420
class MagicException(Exception):
2521
pass
@@ -104,6 +100,12 @@ def from_buffer(buffer, mime=False):
104100

105101
try:
106102
libmagic = None
103+
104+
import ctypes
105+
import ctypes.util
106+
107+
from ctypes import c_char_p, c_int, c_size_t, c_void_p
108+
107109
# Let's try to find magic or magic1
108110
dll = ctypes.util.find_library('magic') or ctypes.util.find_library('magic1')
109111

0 commit comments

Comments
 (0)