Re: [Zope-dev] Relative Imports: PEP-328

2008-10-14 Thread Sidnei da Silva
FWIW, I've done that now.

On Wed, Oct 8, 2008 at 9:43 AM, Philipp von Weitershausen
<[EMAIL PROTECTED]> wrote:
>
> El 8 Oct 2008, a las 14:23 , Sidnei da Silva escribió:
>
>> On Wed, Oct 8, 2008 at 8:53 AM, Philipp von Weitershausen
>> <[EMAIL PROTECTED]> wrote:
>>>
>>> Sidnei da Silva wrote:

 I'm trying to fix some import errors, which seem to be related to
 PEP-328.

 I'm fixing those errors this way, though I don't know if that's the
 recommended way of fixing it. Thoughts?

 """
 try:
  from DT_Util import parse_params, name_param
 except ImportError:
  # See PEP-328
  from .DT_Util import parse_params, name_param
 """
>>>
>>> This will generate a SyntaxError in Python 2.4. So unless we *require*
>>> Python >= 2.5, this won't work.
>>
>> Yuck. I hadn't thought of that. Any other suggestions? Like, using
>> zope.documenttemplate? :)
>
> zope.documenttemplate is a crippled version of DocumentTemplate. It doesn't
> have all features (e.g. it lacks the C extension module) and hasn't been
> kept up-to-date with respect to bugfixes. So it seems like a good idea to
> put this clone out of its misery and retire it.
>
> I ultimately suggest going to absolute imports everywhere (at least as long
> as we have to maintain Python 2.4 compatibility). I realize that
> DocumentTemplate/DocumentTemplate.py creates a problem. So here's what I
> suggest:
>
>  1. Rename DocumentTemplate/DocumentTemplate.py to, say,
> DocumentTemplate/DocTemplate.py (feel free to come up with
> a better name)
>
>  2. Introduce absolute imports to DocumentTemplate.DocTemplate
> everywhere
>
>  3. Ensure backwards compatibility by adding the following lines
> to DocumentTemplate/__init__.py::
>
>import DocumentTemplate.DocTemplate
>import sys
>sys.modules['DocumentTemplate.DocumentTemplate'] =
> DocumentTemplate.DocTemplate
>
> I *think* this should work.
>
>



-- 
Sidnei da Silva
Enfold Systemshttp://enfoldsystems.com
Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Relative Imports: PEP-328

2008-10-08 Thread Philipp von Weitershausen

El 8 Oct 2008, a las 14:23 , Sidnei da Silva escribió:

> On Wed, Oct 8, 2008 at 8:53 AM, Philipp von Weitershausen
> <[EMAIL PROTECTED]> wrote:
>> Sidnei da Silva wrote:
>>>
>>> I'm trying to fix some import errors, which seem to be related to  
>>> PEP-328.
>>>
>>> I'm fixing those errors this way, though I don't know if that's the
>>> recommended way of fixing it. Thoughts?
>>>
>>> """
>>> try:
>>>   from DT_Util import parse_params, name_param
>>> except ImportError:
>>>   # See PEP-328
>>>   from .DT_Util import parse_params, name_param
>>> """
>>
>> This will generate a SyntaxError in Python 2.4. So unless we  
>> *require*
>> Python >= 2.5, this won't work.
>
> Yuck. I hadn't thought of that. Any other suggestions? Like, using
> zope.documenttemplate? :)

zope.documenttemplate is a crippled version of DocumentTemplate. It  
doesn't have all features (e.g. it lacks the C extension module) and  
hasn't been kept up-to-date with respect to bugfixes. So it seems like  
a good idea to put this clone out of its misery and retire it.

I ultimately suggest going to absolute imports everywhere (at least as  
long as we have to maintain Python 2.4 compatibility). I realize that  
DocumentTemplate/DocumentTemplate.py creates a problem. So here's what  
I suggest:

   1. Rename DocumentTemplate/DocumentTemplate.py to, say,
  DocumentTemplate/DocTemplate.py (feel free to come up with
  a better name)

   2. Introduce absolute imports to DocumentTemplate.DocTemplate
  everywhere

   3. Ensure backwards compatibility by adding the following lines
  to DocumentTemplate/__init__.py::

 import DocumentTemplate.DocTemplate
 import sys
 sys.modules['DocumentTemplate.DocumentTemplate'] =  
DocumentTemplate.DocTemplate

I *think* this should work.

___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Relative Imports: PEP-328

2008-10-08 Thread Sidnei da Silva
On Wed, Oct 8, 2008 at 8:53 AM, Philipp von Weitershausen
<[EMAIL PROTECTED]> wrote:
> Sidnei da Silva wrote:
>>
>> I'm trying to fix some import errors, which seem to be related to PEP-328.
>>
>> I'm fixing those errors this way, though I don't know if that's the
>> recommended way of fixing it. Thoughts?
>>
>> """
>> try:
>>from DT_Util import parse_params, name_param
>> except ImportError:
>># See PEP-328
>>from .DT_Util import parse_params, name_param
>> """
>
> This will generate a SyntaxError in Python 2.4. So unless we *require*
> Python >= 2.5, this won't work.

Yuck. I hadn't thought of that. Any other suggestions? Like, using
zope.documenttemplate? :)

-- 
Sidnei da Silva
Enfold Systemshttp://enfoldsystems.com
Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Relative Imports: PEP-328

2008-10-08 Thread Philipp von Weitershausen
Sidnei da Silva wrote:
> I'm trying to fix some import errors, which seem to be related to PEP-328.
> 
> I'm fixing those errors this way, though I don't know if that's the
> recommended way of fixing it. Thoughts?
> 
> """
> try:
> from DT_Util import parse_params, name_param
> except ImportError:
> # See PEP-328
> from .DT_Util import parse_params, name_param
> """

This will generate a SyntaxError in Python 2.4. So unless we *require* 
Python >= 2.5, this won't work.
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Relative Imports: PEP-328

2008-10-07 Thread Sidnei da Silva
On Wed, Oct 8, 2008 at 2:40 AM, Marius Gedminas <[EMAIL PROTECTED]> wrote:
> I'd suggest converting it to an absolute import
>
>  from zope.documenttemplate.dt_util import parse_params, name_param

So I thought at first. Except there is a problem:

Inside 'DocumentTemplate' there's another 'DocumentTemplate' module. So doing:

 'from DocumentTemplate.DT_Util import parse_params'

... tries to import DT_Util from the relative module. Then the fix is to do:

 'from __future__ import absolute_import'

... except that doesn't work on Python 2.4.

So the try: except seems to be the only way around here, unfortunately.

> or whatever the equivalent for Zope 2 is (I'm assuming it's Zope 2,
> since DT_Util is capitalized).

Another option might be to switch this to use zope.documenttemplate. :)

-- 
Sidnei da Silva
Enfold Systemshttp://enfoldsystems.com
Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Relative Imports: PEP-328

2008-10-07 Thread Marius Gedminas
On Wed, Oct 08, 2008 at 12:14:29AM -0300, Sidnei da Silva wrote:
> I'm trying to fix some import errors, which seem to be related to PEP-328.
> 
> I'm fixing those errors this way, though I don't know if that's the
> recommended way of fixing it. Thoughts?
> 
> """
> try:
> from DT_Util import parse_params, name_param
> except ImportError:
> # See PEP-328
> from .DT_Util import parse_params, name_param
> """

I'd suggest converting it to an absolute import

  from zope.documenttemplate.dt_util import parse_params, name_param

or whatever the equivalent for Zope 2 is (I'm assuming it's Zope 2,
since DT_Util is capitalized).

Marius Gedminas
-- 
My mail reader can beat up your mail reader.


signature.asc
Description: Digital signature
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Relative Imports: PEP-328

2008-10-07 Thread Sidnei da Silva
I'm trying to fix some import errors, which seem to be related to PEP-328.

I'm fixing those errors this way, though I don't know if that's the
recommended way of fixing it. Thoughts?

"""
try:
from DT_Util import parse_params, name_param
except ImportError:
# See PEP-328
from .DT_Util import parse_params, name_param
"""

-- 
Sidnei da Silva
Enfold Systemshttp://enfoldsystems.com
Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )