mirror of
https://github.com/samba-team/samba.git
synced 2025-01-08 21:18:16 +03:00
netcmd: models: move expression code to Field class
This is necessary to deal with edge cases for specific fields. Signed-off-by: Rob van der Linde <rob@catalyst.net.nz> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
d8251cc0ea
commit
e11aa29ef8
@ -27,7 +27,7 @@ from abc import ABCMeta, abstractmethod
|
||||
from datetime import datetime
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from ldb import Dn, MessageElement, string_to_time, timestring
|
||||
from ldb import Dn, MessageElement, binary_encode, string_to_time, timestring
|
||||
from samba.dcerpc import security
|
||||
from samba.dcerpc.misc import GUID
|
||||
from samba.ndr import ndr_pack, ndr_unpack
|
||||
@ -91,6 +91,10 @@ class Field(metaclass=ABCMeta):
|
||||
"""
|
||||
pass
|
||||
|
||||
def expression(self, value):
|
||||
"""Returns the ldb search expression for this field."""
|
||||
return f"({self.name}={binary_encode(value)})"
|
||||
|
||||
|
||||
class IntegerField(Field):
|
||||
"""A simple integer field, can be an int or list of int."""
|
||||
|
@ -25,7 +25,7 @@ from abc import ABCMeta, abstractmethod
|
||||
|
||||
from ldb import (ERR_NO_SUCH_OBJECT, FLAG_MOD_ADD, FLAG_MOD_REPLACE,
|
||||
LdbError, Message, MessageElement, SCOPE_BASE,
|
||||
SCOPE_SUBTREE, binary_encode)
|
||||
SCOPE_SUBTREE)
|
||||
from samba.sd_utils import SDUtils
|
||||
|
||||
from .exceptions import (DeleteError, DoesNotExist, FieldError,
|
||||
@ -221,7 +221,7 @@ class Model(metaclass=ModelMeta):
|
||||
field = cls.fields.get(field_name)
|
||||
if field is None:
|
||||
raise ValueError(f"Unknown field '{field_name}'")
|
||||
expression += f"({field.name}={binary_encode(value)})"
|
||||
expression += field.expression(value)
|
||||
|
||||
if num_fields > 1:
|
||||
expression += ")"
|
||||
|
Loading…
Reference in New Issue
Block a user