Skip to content

Commit 28f5251

Browse files
committed
Move import statements to top level
For import statements that can safely exist at the top level of the file, move them there. In Lib/slapdtest/_slapdtest.py, Adding imports local to functions unnecessarily resulted in duplicates. This style is also more in line with PEP8: https://www.python.org/dev/peps/pep-0008/#imports > Imports are always put at the top of the file, just after any module > comments and docstrings, and before module globals and constants.
1 parent c10cd5c commit 28f5251

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Lib/ldap/asyncsearch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from ldap import __version__
1010

11+
import ldif
12+
1113
SEARCH_RESULT_TYPES = {
1214
ldap.RES_SEARCH_ENTRY,
1315
ldap.RES_SEARCH_RESULT,
@@ -269,7 +271,6 @@ class LDIFWriter(FileWriter):
269271
"""
270272

271273
def __init__(self,l,writer_obj,headerStr='',footerStr=''):
272-
import ldif
273274
if isinstance(writer_obj,ldif.LDIFWriter):
274275
self._ldif_writer = writer_obj
275276
else:

Lib/ldap/schema/subentry.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
See https://www.python-ldap.org/ for details.
55
"""
66

7+
import copy
8+
79
import ldap.cidict,ldap.schema
810

11+
from ldap.compat import urlopen
912
from ldap.schema.models import *
1013

14+
import ldapurl
15+
import ldif
16+
17+
1118
SCHEMA_CLASS_MAPPING = ldap.cidict.cidict()
1219
SCHEMA_ATTR_MAPPING = {}
1320

@@ -256,7 +263,6 @@ def get_inheritedobj(self,se_class,nameoroid,inherited=None):
256263
Get a schema element by name or OID with all class attributes
257264
set including inherited class attributes
258265
"""
259-
import copy
260266
inherited = inherited or []
261267
se = copy.copy(self.sed[se_class].get(self.getoid(se_class,nameoroid)))
262268
if se and hasattr(se,'sup'):
@@ -452,7 +458,6 @@ def urlfetch(uri,trace_level=0):
452458
"""
453459
uri = uri.strip()
454460
if uri.startswith(('ldap:', 'ldaps:', 'ldapi:')):
455-
import ldapurl
456461
ldap_url = ldapurl.LDAPUrl(uri)
457462

458463
l=ldap.initialize(ldap_url.initializeUrl(),trace_level)
@@ -472,8 +477,6 @@ def urlfetch(uri,trace_level=0):
472477
l.unbind_s()
473478
del l
474479
else:
475-
import ldif
476-
from ldap.compat import urlopen
477480
ldif_file = urlopen(uri)
478481
ldif_parser = ldif.LDIFRecordList(ldif_file,max_entries=1)
479482
ldif_parser.parse()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy