Re: Bug in svnmerge.py, rev 30107 (not fully compatible with Python 2.2.x)

View: New views
3 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: Bug in svnmerge.py, rev 30107 (not fully compatible with Python 2.2.x)

by Raman Gupta :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Justin Akehurst wrote:

> The problem: sys.stdout (file object) under Python 2.2.2 does not have the
> 'encoding' attribute.
>
> My workaround:
> @@ -217,7 +217,7 @@
>      return prefix + lines[:-1].replace("\n", "\n"+prefix) + "\n"
>  
>  def recode_stdout_to_file(s):
> -    if locale.getdefaultlocale()[1] is None or sys.stdout.encoding is None:
> +    if locale.getdefaultlocale()[1] is None or not
> sys.stdout.has_attr('encoding') or sys.stdout.encoding is None:
>        return s
>      u = s.decode(sys.stdout.encoding)
>      return u.encode(locale.getdefaultlocale()[1])

Ok, but unfortunately the work-around doesn't seem to work on more
recent versions:

$ python -V
Python 2.5.1

$ python
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.stdout.has_attr('encoding')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'file' object has no attribute 'has_attr'

An other ideas?

Cheers,
Raman
_______________________________________________
Svnmerge mailing list
Svnmerge@...
http://www.orcaware.com/mailman/listinfo/svnmerge

Re: Bug in svnmerge.py, rev 30107 (not fully compatible with Python 2.2.x)

by Dustin J. Mitchell-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Apr 2, 2008 at 12:21 AM, Raman Gupta <rocketraman@...> wrote:
>  AttributeError: 'file' object has no attribute 'has_attr'
>
>  An other ideas?

use
  if .. hasattr(sys.stdout, "encoding") ..

Given this change, and assuming tests pass, I'm happy with this as a
permanent solution, rather than a workaround.

Dustin

--
Storage Software Engineer
http://www.zmanda.com
_______________________________________________
Svnmerge mailing list
Svnmerge@...
http://www.orcaware.com/mailman/listinfo/svnmerge

Re: Bug in svnmerge.py, rev 30107 (not fully compatible with Python 2.2.x)

by Raman Gupta :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dustin J. Mitchell wrote:

> On Wed, Apr 2, 2008 at 12:21 AM, Raman Gupta <rocketraman@...> wrote:
>>  AttributeError: 'file' object has no attribute 'has_attr'
>>
>>  An other ideas?
>
> use
>   if .. hasattr(sys.stdout, "encoding") ..
>
> Given this change, and assuming tests pass, I'm happy with this as a
> permanent solution, rather than a workaround.
>
> Dustin

Thanks Dustin, applied in 30181.

Cheers,
Raman

_______________________________________________
Svnmerge mailing list
Svnmerge@...
http://www.orcaware.com/mailman/listinfo/svnmerge
LightInTheBox - Buy quality products at wholesale price!