How to derive from datetime.timezone class?

2011-11-10 Thread Baptiste Lepilleur
Hi, I want to sub-class the datetime.timezone class, but when I derive from datetime.timezone I get an error message "TypeError: type 'datetime.timezone' is not an acceptable base type". Why do I get this error? Is there something specific to do to avoid it? Below is an example of code: Python 3

Re: How to port bytes formatting to Python 3.x ?

2011-01-01 Thread Baptiste Lepilleur
2011/1/1 Stefan Behnel > Baptiste Lepilleur, 01.01.2011 10:01: > > Hi, >> I'm trying to port a small library to Python 3.x, and I'm wondering what >> is >> the best way to port statements such as the one belows that are >> frequently >> found in

Re: How to define a bytes literal in Python 2.x for porting to Python 3.x using 2to3?

2011-01-01 Thread Baptiste Lepilleur
2011/1/1 Stefan Behnel > Terry Reedy, 01.01.2011 11:08: > > On 1/1/2011 4:08 AM, Baptiste Lepilleur wrote: >> >> Is there a way to mark string literals so that 2to3 automatically >>> prefixes them with 'b'? Is there a simpler trick? >>> >

How to define a bytes literal in Python 2.x for porting to Python 3.x using 2to3?

2011-01-01 Thread Baptiste Lepilleur
Hi, I'm trying to port some network protocol library to Python 3.x, and it defines many bytes literals as plain string. How do you define bytes literals so that the library can be ported to Python 3.x using only 2to3? For example: In python 2.x, I need: self.buffer = '\n' In python 3.x,

How to port bytes formatting to Python 3.x ?

2011-01-01 Thread Baptiste Lepilleur
Hi, I'm trying to port a small library to Python 3.x, and I'm wondering what is the best way to port statements such as the one belows that are frequently found in network protocol implementation: headerparts = ("%s:%s\n" % (key, value) for key, value in headers.iteritems()) frame

Change in scope of handled exception variable in Python 3?

2010-12-30 Thread Baptiste Lepilleur
Hi, I stumbled on a small bug with httplib2 that I reduced to the example below. It seems that with Python 3, when an exception is handled it "unbound" the previously declared local variable. This did not occurs with Python 2.5. It is a Python 3 feature? I did not find anything in the what's news

Re: Why tarfile.TarFile.gzopen is not in the online documentation?

2010-02-26 Thread Baptiste Lepilleur
2010/2/24 Lars Gustäbel > On Wed, Feb 24, 2010 at 09:37:19AM +0100, Baptiste Lepilleur wrote: > > I stumbled uppon this and find it somewhat odd: some class methods of > > TarFile and TarInfo do not appears in either the online documentation or > > search while t

Why tarfile.TarFile.gzopen is not in the online documentation?

2010-02-24 Thread Baptiste Lepilleur
I stumbled uppon this and find it somewhat odd: some class methods of TarFile and TarInfo do not appears in either the online documentation or search while they have a doc string: http://docs.python.org/search.html?q=gzopen http://docs.python.org/library/tarfile.html?highlight=tarfile#tarfile.TarF

Semantic of operations on a closed file object

2009-12-26 Thread Baptiste Lepilleur
Reading python io.IOBase class documentation, I'm kind of confused at the expected behavior of operation on a closed file object. The io.IOBase class doc says: """Note that calling any method (even inquiries) on a closed stream is undefined. Implementations may raise IOErrorin this case.""" But t

What is the equivalent of chr(x) for bytes in python 3?

2009-12-26 Thread Baptiste Lepilleur
Hi, I'm looking for the equivalent of the built-in chr(x) function that would return a bytes type taking an integer as parameter. The easiest way I found to do this is the function below, but there must be some simpler way to do that and I must be overlooking something fairly obvious... def byte(

Re: Why the expression "(1)" is not an one-arity tuple, but int ?

2009-12-04 Thread Baptiste Lepilleur
By adding a before the closing brace of the tucomma after 1. Python allow this to disambiguate between braced expression and tuple >>> type( (1,) ) 2009/12/4 Петров Александр > > How could I tell Python that "(1)" is not an integer, but an one-arity > tuple ? > > Thank you, > Alexander Petrov

Re: Why the expression "(1)" is not an one-arity tuple, but int ?

2009-12-04 Thread Baptiste Lepilleur
By adding a before the closing brace of the tuple. Python allow this to disambiguate between braced expression and tuple >>> type( (1,) ) 2009/12/4 Петров Александр > > How could I tell Python that "(1)" is not an integer, but an one-arity > tuple ? > > Thank you, > Alexander Petrov > -- > ht

Re: Writing an emulator in python - implementation questions (for performance)

2009-11-15 Thread Baptiste Lepilleur
I think you can use python itself for "pre-processing". Here is an (shortened) example from PyPy RPython paper: # operators: the docstrings contain the # symbol associated with each operator class Op_Add(BinaryExpr): ’+’ class Op_Sub(BinaryExpr): ’-’ # INIT-TIME only: build the table of #

Re: What is the correct way to port codecs.open to python 3.1?

2009-11-07 Thread Baptiste Lepilleur
2009/11/7 MRAB > Baptiste Lepilleur wrote: > [..] >> Do I need to replace all codecs.open with the built-in open function? If >> so, why does codecs.open still exist? >> >> The documentation says of codecs.open() that "Files are always opened in > b

What is the correct way to port codecs.open to python 3.1?

2009-11-07 Thread Baptiste Lepilleur
After applying 2to3.py to port a 2.6 script to 3.1, I get the following error when running my script: File "purekeyworddbtest.py", line 143, in __init__ f = codecs.open(EXCLUDED_KEYWORDS_FILE, 'rt', 'utf-8') File "c:\Python31\lib\codecs.py", line 870, in open file = builtins.open(filena

Looking for a tool to checkfor python script backward compatibility

2009-07-12 Thread Baptiste Lepilleur
I'm looking for a tool that could be used in a pre-commit step to check that only features available in a "old" python version are used, say python 2.3 for example. Does any one know of one ? -- http://mail.python.org/mailman/listinfo/python-list

How to suppress UnicodeError exception when enabling httplib debug?

2006-08-06 Thread Baptiste Lepilleur
I activated httplib debug, and when trace are printed, a UnicodeError exception is thrown. I have already set sys.stdout to use utf-8 encoding (this removed the exception when *I* was printing unicode), but from the stacktrace below, the encoding seems to magically have switched to 'ascii' when