Skip to content

Commit

Permalink
Move import statements to top level
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jon Dufresne committed Apr 3, 2018
1 parent c10cd5c commit 28f5251
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Lib/ldap/asyncsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from ldap import __version__

import ldif

SEARCH_RESULT_TYPES = {
ldap.RES_SEARCH_ENTRY,
ldap.RES_SEARCH_RESULT,
Expand Down Expand Up @@ -269,7 +271,6 @@ class LDIFWriter(FileWriter):
"""

def __init__(self,l,writer_obj,headerStr='',footerStr=''):
import ldif
if isinstance(writer_obj,ldif.LDIFWriter):
self._ldif_writer = writer_obj
else:
Expand Down
11 changes: 7 additions & 4 deletions Lib/ldap/schema/subentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
See https://www.python-ldap.org/ for details.
"""

import copy

import ldap.cidict,ldap.schema

from ldap.compat import urlopen
from ldap.schema.models import *

import ldapurl
import ldif


SCHEMA_CLASS_MAPPING = ldap.cidict.cidict()
SCHEMA_ATTR_MAPPING = {}

Expand Down Expand Up @@ -256,7 +263,6 @@ def get_inheritedobj(self,se_class,nameoroid,inherited=None):
Get a schema element by name or OID with all class attributes
set including inherited class attributes
"""
import copy
inherited = inherited or []
se = copy.copy(self.sed[se_class].get(self.getoid(se_class,nameoroid)))
if se and hasattr(se,'sup'):
Expand Down Expand Up @@ -452,7 +458,6 @@ def urlfetch(uri,trace_level=0):
"""
uri = uri.strip()
if uri.startswith(('ldap:', 'ldaps:', 'ldapi:')):
import ldapurl
ldap_url = ldapurl.LDAPUrl(uri)

l=ldap.initialize(ldap_url.initializeUrl(),trace_level)
Expand All @@ -472,8 +477,6 @@ def urlfetch(uri,trace_level=0):
l.unbind_s()
del l
else:
import ldif
from ldap.compat import urlopen
ldif_file = urlopen(uri)
ldif_parser = ldif.LDIFRecordList(ldif_file,max_entries=1)
ldif_parser.parse()
Expand Down

0 comments on commit 28f5251

Please sign in to comment.