All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] oepydevshell-internal.py: decode only when readdata is valid
@ 2018-11-13  9:04 changqing.li
  2018-11-13 10:03 ` Richard Purdie
  0 siblings, 1 reply; 5+ messages in thread
From: changqing.li @ 2018-11-13  9:04 UTC (permalink / raw)
  To: openembedded-core

From: Changqing Li <changqing.li@windriver.com>

fix below problem:
pydevshell raises exception when maximize the python shell window.
when click maximize, rlist of select return ready object, but the
pty.read is None, so throw exception of 'NoneType' object has no
attribute 'decode', change to only decode when readdata is valid.

[YOCTO #11875]

Signed-off-by: Changqing Li <changqing.li@windriver.com>
---
 scripts/oepydevshell-internal.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/oepydevshell-internal.py b/scripts/oepydevshell-internal.py
index 04621ae..2d1bc77 100755
--- a/scripts/oepydevshell-internal.py
+++ b/scripts/oepydevshell-internal.py
@@ -63,7 +63,10 @@ try:
             (ready, _, _) = select.select([pty, sys.stdin], writers , [], 0)
             try:
                 if pty in ready:
-                    i = i + pty.read().decode('utf-8')
+                    readdata=pty.read()
+                    if readdata == None:
+                        continue
+                    i = i + readdata.decode('utf-8')
                 if i:
                     # Write a page at a time to avoid overflowing output 
                     # d.keys() is a good way to do that
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] oepydevshell-internal.py: decode only when readdata is valid
  2018-11-13  9:04 [PATCH] oepydevshell-internal.py: decode only when readdata is valid changqing.li
@ 2018-11-13 10:03 ` Richard Purdie
  2018-11-13 11:10   ` Burton, Ross
  2018-11-14  9:37   ` Changqing Li
  0 siblings, 2 replies; 5+ messages in thread
From: Richard Purdie @ 2018-11-13 10:03 UTC (permalink / raw)
  To: changqing.li, openembedded-core

On Tue, 2018-11-13 at 17:04 +0800, changqing.li@windriver.com wrote:
> From: Changqing Li <changqing.li@windriver.com>
> 
> fix below problem:
> pydevshell raises exception when maximize the python shell window.
> when click maximize, rlist of select return ready object, but the
> pty.read is None, so throw exception of 'NoneType' object has no
> attribute 'decode', change to only decode when readdata is valid.
> 
> [YOCTO #11875]
> 
> Signed-off-by: Changqing Li <changqing.li@windriver.com>
> ---
>  scripts/oepydevshell-internal.py | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/oepydevshell-internal.py b/scripts/oepydevshell-
> internal.py
> index 04621ae..2d1bc77 100755
> --- a/scripts/oepydevshell-internal.py
> +++ b/scripts/oepydevshell-internal.py
> @@ -63,7 +63,10 @@ try:
>              (ready, _, _) = select.select([pty, sys.stdin], writers
> , [], 0)
>              try:
>                  if pty in ready:
> -                    i = i + pty.read().decode('utf-8')
> +                    readdata=pty.read()
> +                    if readdata == None:
> +                        continue
> +                    i = i + readdata.decode('utf-8')

Usually you'd write this as:

if readdata:
    i = i + readdata.decode('utf-8')

Is there a reason not to do that here?

If you really want to test for None, you usually write:

if readdata is None:

which is a little more pythonic.

Cheers,

Richard



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] oepydevshell-internal.py: decode only when readdata is valid
  2018-11-13 10:03 ` Richard Purdie
@ 2018-11-13 11:10   ` Burton, Ross
  2018-11-14  9:44     ` Changqing Li
  2018-11-14  9:37   ` Changqing Li
  1 sibling, 1 reply; 5+ messages in thread
From: Burton, Ross @ 2018-11-13 11:10 UTC (permalink / raw)
  To: Purdie, Richard; +Cc: OE-core

On Tue, 13 Nov 2018 at 10:03, Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:

> Usually you'd write this as:
>
> if readdata:
>     i = i + readdata.decode('utf-8')
>
> Is there a reason not to do that here?

Whilst this code is being changed, is there a chance of getting a
partial read that has half of a utf-8 byte sequence?

Ross


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] oepydevshell-internal.py: decode only when readdata is valid
  2018-11-13 10:03 ` Richard Purdie
  2018-11-13 11:10   ` Burton, Ross
@ 2018-11-14  9:37   ` Changqing Li
  1 sibling, 0 replies; 5+ messages in thread
From: Changqing Li @ 2018-11-14  9:37 UTC (permalink / raw)
  To: Richard Purdie, openembedded-core


On 11/13/18 6:03 PM, Richard Purdie wrote:
> On Tue, 2018-11-13 at 17:04 +0800, changqing.li@windriver.com wrote:
>> From: Changqing Li <changqing.li@windriver.com>
>>
>> fix below problem:
>> pydevshell raises exception when maximize the python shell window.
>> when click maximize, rlist of select return ready object, but the
>> pty.read is None, so throw exception of 'NoneType' object has no
>> attribute 'decode', change to only decode when readdata is valid.
>>
>> [YOCTO #11875]
>>
>> Signed-off-by: Changqing Li <changqing.li@windriver.com>
>> ---
>>   scripts/oepydevshell-internal.py | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/scripts/oepydevshell-internal.py b/scripts/oepydevshell-
>> internal.py
>> index 04621ae..2d1bc77 100755
>> --- a/scripts/oepydevshell-internal.py
>> +++ b/scripts/oepydevshell-internal.py
>> @@ -63,7 +63,10 @@ try:
>>               (ready, _, _) = select.select([pty, sys.stdin], writers
>> , [], 0)
>>               try:
>>                   if pty in ready:
>> -                    i = i + pty.read().decode('utf-8')
>> +                    readdata=pty.read()
>> +                    if readdata == None:
>> +                        continue
>> +                    i = i + readdata.decode('utf-8')
> Usually you'd write this as:
>
> if readdata:
>      i = i + readdata.decode('utf-8')
>
> Is there a reason not to do that here?
>
> If you really want to test for None, you usually write:
>
> if readdata is None:
>
> which is a little more pythonic.
>
> Cheers,
>
> Richard
>
Thanks. I will correct the patch as suggested.

//Changqing

-- 
BRs

Sandy(Li Changqing)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] oepydevshell-internal.py: decode only when readdata is valid
  2018-11-13 11:10   ` Burton, Ross
@ 2018-11-14  9:44     ` Changqing Li
  0 siblings, 0 replies; 5+ messages in thread
From: Changqing Li @ 2018-11-14  9:44 UTC (permalink / raw)
  To: Burton, Ross, Purdie, Richard; +Cc: OE-core


On 11/13/18 7:10 PM, Burton, Ross wrote:
> On Tue, 13 Nov 2018 at 10:03, Richard Purdie
> <richard.purdie@linuxfoundation.org> wrote:
>
>> Usually you'd write this as:
>>
>> if readdata:
>>      i = i + readdata.decode('utf-8')
>>
>> Is there a reason not to do that here?
> Whilst this code is being changed, is there a chance of getting a
> partial read that has half of a utf-8 byte sequence?
>
> Ross

Seems "continue"  will delay  the deal of  "i"  to next loop, but will 
not lost data.

but I still change to let it continue to deal with "i" , in case there 
is still "i" not

outputed in last loop. it should be better.


changqing

-- 
BRs

Sandy(Li Changqing)



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-11-14  9:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-13  9:04 [PATCH] oepydevshell-internal.py: decode only when readdata is valid changqing.li
2018-11-13 10:03 ` Richard Purdie
2018-11-13 11:10   ` Burton, Ross
2018-11-14  9:44     ` Changqing Li
2018-11-14  9:37   ` Changqing Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.