Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4) - Mailing list pgadmin-hackers

From Murtuza Zabuawala
Subject Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
Date
Msg-id CAKKotZT2YcvNF-cr3XV_EGiWhc-mPvGZCe5r62YFYbx6Zxvhyw@mail.gmail.com
Whole thread Raw
In response to Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)  (Dave Page <dpage@pgadmin.org>)
List pgadmin-hackers
Hi Dave,

1) Unicode conversion was working properly for function node, It was failing due to wrong sql templates.
- I've fixed them.
2) Type is also working fine with encoding for me(PFA screenshots), Can you please provide error you got?


This patch also makes Provider optional in security label control & templates.

-------
Regarding enforcing to utf-8, In my opinion we can enforce everything to utf-8 if we use any of one python version but to make it compatible with both python2 and python3 version by forcing utf-8 encoding it will be difficult to handle its side effects.

For example, 

Python2,

>>> txt_sample = 'Hello'
>>> isinstance(txt_sample, str)
True
>>> isinstance(txt_sample, bytes)
True
>>> isinstance(txt_sample, unicode)
False
>>> txt_sample.encode('utf-8')
'Hello'
>>> txt_sample.decode('utf-8')
u'Hello'

Forcing to unicode in Python2,

>>> txt_sample = u'Hello'
>>> isinstance(txt_sample, str)
False
>>> isinstance(txt_sample, bytes)
False
>>> isinstance(txt_sample, unicode)
True

Python3,

>>> txt_sample = 'Hello'
>>> isinstance(txt_sample, str)
True
>>> isinstance(txt_sample, bytes)
False
>>> txt_sample.encode('utf-8')
b'Hello'
>>> txt_sample.decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'decode'


And also psycopg2 driver returns text as string in Python2 even if that text contains unicode characters, In python3 that just works fine because string is Unicode by default.


Regards,
Murtuza

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachment

pgadmin-hackers by date:

Previous
From: Dave Page
Date:
Subject: Re: PATCH: Encoding issue with qtLiteral function (pgAdmin4)
Next
From: Navnath Gadakh
Date:
Subject: Re: pgAdmin IV : Unittest modular patch