LDB python3 strings

Noel Power nopower at suse.com
Wed May 9 07:20:06 UTC 2018


On 08/05/18 23:33, Douglas Bagnall wrote:
> On 09/05/18 06:25, Noel Power via samba-technical wrote:
[...]
> What I thought Andrew meant is a C implementation of exactly this:
>
> class LdbBytes(bytes):
>      def __str__(self):
>          return self.decode('utf8')
>
> which would be bytes in all but stringification, as follows:
>
> x = LdbBytes(b'abc')
> str(x)               # 'abc'
>
> b = b'abc'
> str(b)               # "b'abc'"
>
> x == b               # True
> isinstance(x, bytes) # True
>
> repr(x)              # "b'abc'"
ok, this type of wrapper is what I originally thought was meant (but I
missed detail of the expected subclass of bytes)
On reading the responses I got even more confused and figured what I
just proposed was what was being suggested :-)
>
>
> It makes things very easy now, at the risk of causing other parties to
> swear loudly in the future. Progress as usual in software.
Unfortunately this doesn't help with the instance where just plain
res[0]["samAccountName"][0] is being passed around (which seem to be the
ones that I have had to change lots of). PerhapsĀ 
str(res[0]["samAccountName"][0]) is used more than I realise but I just
haven't experienced that yet (at least in terms of root causes of
runtime errors when porting tests)
I'll look into the c - code modification to provide the stringification
functionality
>
> It would be nice to be able to piggyback the Python 3 API break as an
> excuse to breakingly improve our Python APIs, but we can't easily do
> that while still supporting Py2.
yep
>
> Douglas

Thanks for the hints
Noel



More information about the samba-technical mailing list