Re: [Hack] Import binary extensions from zipfiles, windows only

2005-01-03 Thread PJDM
I'm trying to make ZopeX3 start faster by zipping up the "zope"
directory. (Because this will be stored on a CD, having less data to
read will make it quicker to start.)

The standard python zipimporter won't work with the ZopeX3 .pyd files,
so zipextimporter came along at just the right time. However, it
doesn't seem to work for me (Python 2.3.4 (#53, May 25 2004, 21:17:02)
[MSC v.1200 32 bit (Intel)] on win32, Windows XP SP2).

Sample script:

import zipextimporter
zipextimporter.install()

import sys
print 'Hooks:\n', sys.path_hooks

sys.path.append(r'C:\tmp\zope.zip')
print 'Path:\n', sys.path

# Try an innocuous import first to make sure we have the path correct.
import zope.server
print 'Server file:\n', zope.server.__file__

# Now try a .pyd import.
import zope.thread._zope_thread
print 'Thread file:\n', zope.thread._zope_thread.__file__


Output:

Hooks:
[, ]
Path:
['C:\\tmp', 'C:\\WINDOWS\\system32\\python23.zip', 'C:\\tmp',
'C:\\opt\\Python23\\DLLs', 'C:\\opt\\Python23\\lib',
'C:\\opt\\Python23\\lib\\plat-win', 'C:\\opt\\Python23\\lib\\lib-tk',
'C:\\opt\\Python23', 'C:\\opt\\Python23\\lib\\site-packages',
'C:\\tmp\\zope.zip']
Server file:
C:\tmp\zope.zip\zope\server\__init__.py
Traceback (most recent call last):
File "zei.py", line 15, in ?
import zope.thread._zope_thread
ImportError: No module named _zope_thread


The zope.zip file contains zope.thread:

$ unzip -l zope.zip |grep zope/thread
0  11-08-04 11:00   zope/thread/
0  07-03-04 04:34   zope/thread/DEPENDENCIES.cfg
65  07-28-04 22:52   zope/thread/SETUP.cfg
994  07-03-04 04:34   zope/thread/tests.py
748  11-08-04 11:00   zope/thread/tests.pyc
748  11-08-04 11:00   zope/thread/tests.pyo
20480  11-07-04 00:54   zope/thread/_zope_thread.pyd
7838  08-17-04 17:20   zope/thread/__init__.py
7808  11-08-04 11:00   zope/thread/__init__.pyc
7808  11-08-04 11:00   zope/thread/__init__.pyo


What am I missing?

Thanks.

PJDM

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Import binary extensions from zipfiles, windows only

2005-01-05 Thread PJDM
Thomas Heller wrote:

> zipextimporter, as published, doesn't handle extensions in packages.
> The patch I attached at the end, may fix this - I tested it with PIL.

Thanks, that works fine.

However, ZopeX3 itself still won't run. As part of the startup, it
attempts to load some files relative to imported classes. Since the
path dives into a zip file, opening a file such as
file:/C|/tmp/zope.zip/zope/app/server/schema.xml doesn't work.
Patching things up to avoid this just leads deeper into the mire, so it
looks like this avenue is closed.

Things would probably be easier if Python had something like Java's
Class.getResourceAsStream(), where a resource is found by the class
loader. This means that is doesn't matter if the class came from a
directory, a JAR file, or a network: if the class loader could load the
class, it could also load the resource from the same place. The
__loader__ attribute from PEP 302 seems to be the equivalent, but the
standard importer doesn't provide it.

[EMAIL PROTECTED]:~> python
Python 2.3.4 (#1, Jul 31 2004, 11:22:19)
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.__loader__
Traceback (most recent call last):
File "", line 1, in ?
AttributeError: 'module' object has no attribute '__loader__'
>>>

Oh well.

PJDM

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Octal notation: severe deprecation

2005-01-12 Thread PJDM
John Machin wrote:
>
> 1. Octal notation is of use to systems programmers on computers where
> the number of bits in a word is a multiple of 3. Are there any still
in
> production use? AFAIK word sizes were 12, 24, 36, 48, and 60 bits --
> all multiples of 4, so hexadecimal could be used.

The PDP-11 was 16 bit, but used octal. With eight registers and eight
addressing modes in instructions, octal was a convenient base. (On the
11/70, the front switches were marked in alternate pink and purple
groups of three. <http://www.psych.usyd.edu.au/pdp-11/11_70.html>)

> I don't see any mention of octal in GvR's "Python Regrets" or AMK's
> "PEP 3000". Why not? Is it not regretted?

I suspect that, as in other places, Python just defers to the
underlying implementation. Since the C libraries treat "0n" as octal,
so does Python. (So does JavaScript.) More "it sucks, but it's too late
to change" than regrets.

Maybe P3K will have an integer literal like "n_b" for "the integer n in
base b".

PJDM

-- 
http://mail.python.org/mailman/listinfo/python-list