Visitar URL original
refactor(ldap.controls): cast pyasn1 encoding to bytes instead of type-ignore by spaceone · Pull Request #684 · python-ldap/python-ldap · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Lib/ldap/controls/deref.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from __future__ import annotations

from typing import cast


__all__ = [
'DEREF_CONTROL_OID',
Expand Down Expand Up @@ -99,7 +101,7 @@ def _derefSpecs(self) -> DerefSpecs:
return deref_specs

def encodeControlValue(self) -> bytes:
return encoder.encode(self._derefSpecs()) # type: ignore
return cast(bytes, encoder.encode(self._derefSpecs()))

def decodeControlValue(self, encodedControlValue: bytes) -> None:
decodedValue, _ = decoder.decode(encodedControlValue, asn1Spec=DerefResultControlValue())
Expand Down
8 changes: 5 additions & 3 deletions Lib/ldap/controls/libldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from __future__ import annotations

from typing import cast

import ldap
from ldap import _ldap
from ldap.controls import KNOWN_RESPONSE_CONTROLS, LDAPControl, RequestControl
Expand Down Expand Up @@ -34,7 +36,7 @@ def __init__(self, criticality: bool = True, filterstr: str = '(objectClass=*)')
self.filterstr = filterstr

def encodeControlValue(self) -> bytes:
return _ldap.encode_assertion_control(self.filterstr) # type: ignore
return cast(bytes, _ldap.encode_assertion_control(self.filterstr))


class MatchedValuesControl(RequestControl):
Expand All @@ -57,7 +59,7 @@ def __init__(
self.filterstr = filterstr

def encodeControlValue(self) -> bytes:
return _ldap.encode_valuesreturnfilter_control(self.filterstr) # type: ignore
return cast(bytes, _ldap.encode_valuesreturnfilter_control(self.filterstr))


class SimplePagedResultsControl(LDAPControl):
Expand All @@ -77,7 +79,7 @@ def __init__(self, criticality: bool = False, size: int | None = None, cookie: s
self.size, self.cookie = size, cookie

def encodeControlValue(self) -> bytes:
return _ldap.encode_page_control(self.size, self.cookie) # type: ignore
return cast(bytes, _ldap.encode_page_control(self.size, self.cookie))

def decodeControlValue(self, encodedControlValue: bytes) -> None:
self.size, self.cookie = _ldap.decode_page_control(encodedControlValue)
Expand Down
4 changes: 3 additions & 1 deletion Lib/ldap/controls/pagedresults.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from __future__ import annotations

from typing import cast


__all__ = ['SimplePagedResultsControl']

Expand Down Expand Up @@ -48,7 +50,7 @@ def encodeControlValue(self) -> bytes:
pc = PagedResultsControlValue()
pc.setComponentByName('size', univ.Integer(self.size))
pc.setComponentByName('cookie', LDAPString(self.cookie))
return encoder.encode(pc) # type: ignore
return cast(bytes, encoder.encode(pc))

def decodeControlValue(self, encodedControlValue: bytes) -> None:
decodedValue, _ = decoder.decode(encodedControlValue, asn1Spec=PagedResultsControlValue())
Expand Down
4 changes: 3 additions & 1 deletion Lib/ldap/controls/readentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from __future__ import annotations

from typing import cast

from pyasn1.codec.ber import decoder, encoder
from pyasn1_modules.rfc2251 import AttributeDescriptionList, SearchResultEntry

Expand Down Expand Up @@ -39,7 +41,7 @@ def encodeControlValue(self) -> bytes:
attributeSelection = AttributeDescriptionList()
for i in range(len(self.attrList)):
attributeSelection.setComponentByPosition(i, self.attrList[i])
return encoder.encode(attributeSelection) # type: ignore
return cast(bytes, encoder.encode(attributeSelection))

def decodeControlValue(self, encodedControlValue: bytes) -> None:
decodedEntry, _ = decoder.decode(encodedControlValue, asn1Spec=SearchResultEntry())
Expand Down
4 changes: 3 additions & 1 deletion Lib/ldap/controls/sessiontrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
See https://www.python-ldap.org/ for project details.
"""

from typing import cast

from pyasn1.codec.ber import encoder
from pyasn1.type import namedtype, univ
from pyasn1_modules.rfc2251 import LDAPOID, LDAPString
Expand Down Expand Up @@ -68,4 +70,4 @@ def encodeControlValue(self) -> bytes:
s.setComponentByName('sessionSourceName', LDAPString(self.sessionSourceName))
s.setComponentByName('formatOID', LDAPOID(self.formatOID))
s.setComponentByName('sessionTrackingIdentifier', LDAPString(self.sessionTrackingIdentifier))
return encoder.encode(s) # type: ignore
return cast(bytes, encoder.encode(s))
3 changes: 2 additions & 1 deletion Lib/ldap/controls/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import annotations

import struct
from typing import cast

from pyasn1.codec.ber import decoder, encoder
from pyasn1.type import univ
Expand Down Expand Up @@ -87,7 +88,7 @@ def __init__(self, controlType: str | None = None, criticality: bool = False, bo
self.booleanValue = booleanValue

def encodeControlValue(self) -> bytes:
return encoder.encode(self.booleanValue, asn1Spec=univ.Boolean()) # type: ignore
return cast(bytes, encoder.encode(self.booleanValue, asn1Spec=univ.Boolean()))

def decodeControlValue(self, encodedControlValue: bytes) -> None:
decodedValue, _ = decoder.decode(encodedControlValue, asn1Spec=univ.Boolean())
Expand Down
4 changes: 3 additions & 1 deletion Lib/ldap/controls/sss.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from __future__ import annotations

from typing import cast


__all__ = [
'SSSRequestControl',
Expand Down Expand Up @@ -91,7 +93,7 @@ def asn1(self) -> SortKeyListType:
return p

def encodeControlValue(self) -> bytes:
return encoder.encode(self.asn1()) # type: ignore
return cast(bytes, encoder.encode(self.asn1()))


class SortResultType(univ.Sequence):
Expand Down
4 changes: 3 additions & 1 deletion Lib/ldap/controls/vlv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from __future__ import annotations

from typing import cast


__all__ = [
'VLVRequestControl',
Expand Down Expand Up @@ -91,7 +93,7 @@ def encodeControlValue(self) -> bytes:
p.setComponentByName('target', target)
if self.context_id is not None:
p.setComponentByName('contextID', self.context_id)
return encoder.encode(p) # type: ignore
return cast(bytes, encoder.encode(p))


class VirtualListViewResultType(univ.Enumerated):
Expand Down
4 changes: 2 additions & 2 deletions Lib/ldap/syncrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, cast
from uuid import UUID

from pyasn1.codec.ber import decoder, encoder
Expand Down Expand Up @@ -109,7 +109,7 @@ def encodeControlValue(self) -> bytes:
rcv.setComponentByName('cookie', SyncCookie(self.cookie))
if self.reloadHint:
rcv.setComponentByName('reloadHint', univ.Boolean(self.reloadHint))
return encoder.encode(rcv) # type: ignore
return cast(bytes, encoder.encode(rcv))


class SyncStateOp(univ.Enumerated):
Expand Down
Loading