ANN: mock 0.8 final released

2012-02-16 Thread Fuzzyman
After more than six months development work mock 0.8 has been
released. 0.8 is a big release with many new features, general
improvements and bugfixes.

You can download mock 0.8.0 final from the PyPI page or install it
with:

pip install -U mock

mock is a library for testing in Python. It allows you to replace
parts of your system under test with mock objects.

http://pypi.python.org/pypi/mock
http://www.voidspace.org.uk/python/mock/
http://www.voidspace.org.uk/python/mock/changelog.html#version-0-8-0

The only changes in mock 0.8.0 final since 0.8rc2 are:

* Improved repr of `sentinel` objects
* `ANY` can be used for comparisons against call objects
* The return value of  `MagicMock.__iter__` can be set to any iterable
and isn't required to be an iterator

A longer version of this announcement, including the full changelog
since mock 0.7 and a couple of short examples of the most important
changes, can be found on my blog:

http://www.voidspace.org.uk/python/weblog/arch_d7_2012_02_11.shtml#e1234

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


Re: __set__ method is not called for class attribute access

2011-08-10 Thread Fuzzyman
On Aug 5, 12:29 pm, Ryan  wrote:
> In the context of descriptors, the __set__ method is not called for
> class attribute access. __set__ is only
> called to set the attribute on an instance instance of the owner class
> to a new value, value. WHY?

It's an unfortunate asymmetry in the descriptor protocol. You can
write "class descriptors" with behaviour on get, but not on set.

As others point out, metaclasses are an ugly way round this
(particularly given that *basically* a class can only have one
metaclass - so if you're inheriting from a class that already has a
custom metaclass you can't use this technique).

Michael Foord
--
http://voidspace.org.uk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __set__ method is not called for class attribute access

2011-08-10 Thread Fuzzyman
On Aug 5, 1:16 pm, Duncan Booth  wrote:
> Ryan  wrote:
> > In the context of descriptors, the __set__ method is not called for
> > class attribute access. __set__ is only
> > called to set the attribute on an instance instance of the owner class
> > to a new value, value. WHY? Is there some other mechanism for
> > accomplishing this outcome. This subtle difference from __get__cost me
> > some time to track down. Might think about pointing that out the
> > documentation.
>
> > class RevealAccess(object):
> >     """A data descriptor that sets and returns values
> >        normally and prints a message logging their access.
> >     """
>
> >     def __init__(self, initval=None, name='var'):
> >         self.val = initval
> >         self.name = name
>
> >     def __get__(self, obj, objtype):
> >         print 'Retrieving', self.name
> >         return self.val
>
> >     def __set__(self, obj, val):
> >         print 'Updating' , self.name
> >         self.val = val
>
> > class MyClass(object):
> >     x = RevealAccess(10, 'var "x"')
> >     y = 5
>
> > print MyClass.x
> > MyClass.x = 20
> > print MyClass.x
> > MyClass.x = 30
> > print MyClass.x
>
> > Retrieving var "x"
> > 10
> > 20
> > 30
>
> > I am at a lost on how to intercept class attribute sets. Can anyone
> > help :-/
>
> The descriptor protocol only works when a value is being accessed or set
> on an instance and there is no instance attribute of that name so the
> value is fetched from the underlying class.
>

That's not true. Properties, for example, can be got or set even when
they shadow an instance attribute. You're (probably) thinking of
__getattr__ which isn't invoked when an instance attribute exists.

Also, the descriptor protocol *is* invoked for getting an attribute
from a class - but not when setting a class attribute. An unfortunate
asymmetry. It just wasn't considered as a use case when the descriptor
protocol was implemented.

Michael
--
http://voidspace.org.uk/

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


Re: how to dynamically generate __name__ for an object?

2011-08-10 Thread Fuzzyman
On Aug 7, 4:06 am, Eric Snow  wrote:
> Thought I knew how to provide a dynamic __name__ on instances of a
> class.  My first try was to use a non-data descriptor:
>
> # module base.py
>
> class _NameProxy(object):
>     def __init__(self, oldname):
>         self.oldname = oldname
>     def __get__(self, obj, cls):
>         if obj is None:
>             return self.oldname
>         if "__name__" not in obj.__dict__:
>             return str(obj.__context__)
>         return obj.__name__
>
> class _BaseMeta(type):
>     def __init__(cls, name, bases, namespace):
>         cls.__name__ = _NameProxy(name)
>
> class Base(object):
>     __metaclass__ = _BaseMeta
>
> $ python _base.py
> Traceback (most recent call last):
>   ...
>   File "/usr/local/lib/python2.4/site-packages/base.py", line xx, in __init__
>     cls.__name__ = _NameProxy(name)
> TypeError: Error when calling the metaclass bases
>     can only assign string to Base.__name__, not '_NameProxy'
>
> Needless to say I was surprised.  After looking in typeobject.c, I
> believe that __name__ must be a string where classes are concerned[1].
>  So if I want all my instances to have a __name__ attribute, and for
> it to be dynamically provided if it isn't set on the instance, what
> are my options?  Or maybe I did something wrong and it should work as
> I expected?
>

__name__ can be a descriptor, so you just need to write a descriptor
that can be fetched from classes as well as instances.

Here's an example with a property (instance only):

>>> class Foo(object):
...   @property
...   def __name__(self):
... return 'bar'
...
>>> Foo().__name__
'bar'

Michael
--
http://voidspace.org.uk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to dynamically generate __name__ for an object?

2011-08-10 Thread Fuzzyman
On Aug 10, 4:25 pm, Ian Kelly  wrote:
> On Wed, Aug 10, 2011 at 8:48 AM, Fuzzyman  wrote:
> > __name__ can be a descriptor, so you just need to write a descriptor
> > that can be fetched from classes as well as instances.
>
> > Here's an example with a property (instance only):
>
> >>>> class Foo(object):
> > ...   @property
> > ...   def __name__(self):
> > ...     return 'bar'
> > ...
> >>>> Foo().__name__
> > 'bar'
>
> But:
>
> >>> Foo.__name__
> 'Foo'

That's why I said "you just need to _write_ a descriptor that can be
fetched from classes as well as instances". The example with property
was to show that it *could* be a descriptor. You can write descriptors
with custom behaviour when fetched from a class.

However it turns out that you're right and I'm wrong; __name__ is
special:

>>> class descriptor(object):
...  def __get__(*args):
...   return 'bar'
...
>>> class Foo(object):
...  __name__ = descriptor()
...
>>> Foo.__name__
'Foo'
>>> Foo().__name__
'bar'
>>> class Foo(object):
...  name = descriptor()
...
>>> Foo.name
'bar'

As Eric points out in his original slot, types have their __name__
slot filled in with a string in typeobject.c

All the best,

Michael
--
http://voidspace.org.uk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __set__ method is not called for class attribute access

2011-08-10 Thread Fuzzyman
On Aug 10, 5:27 pm, Eric Snow  wrote:
> On Wed, Aug 10, 2011 at 8:33 AM, Fuzzyman  wrote:
> > On Aug 5, 12:29 pm, Ryan  wrote:
> >> In the context of descriptors, the __set__ method is not called for
> >> class attribute access. __set__ is only
> >> called to set the attribute on an instance instance of the owner class
> >> to a new value, value. WHY?
>
> > It's an unfortunate asymmetry in the descriptor protocol. You can
> > write "class descriptors" with behaviour on get, but not on set.
>
> > As others point out, metaclasses are an ugly way round this
> > (particularly given that *basically* a class can only have one
> > metaclass - so if you're inheriting from a class that already has a
> > custom metaclass you can't use this technique).
>
> Keep in mind that you can still do something like this:
>
> class XMeta(Base.__class__):
>     "Customize here"
>
> class X(Base, metaclass=XMeta):
>     "Do your stuff."
>
> They you would put your descriptor hacking in XMeta and still take
> advantage of the original metaclass.

Yeah, the way round the "more than one metaclass problem" is to have
your new metaclass inherit from the first one. That's not a general
purpose solution though.

Michael
--
http://voidspace.org.uk/
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Voidspace Updates - Jalopy, logintools, textmacros, downman (etc)

2005-09-23 Thread Fuzzyman
Hello All,

There have been various updates to the Voidspace modules :

Jalopy 0.6.0
http://www.voidspace.org.uk/python/cgi.shtml#jalopy

A collaborative website designer (CGI). It uses Kupu
(http://kupu.oscom.org ) the WYSIWYG HTML editor.

This update moves to Kupu 1.3 and the pythonutils 0.2.2 set of modules.


logintools 0.6.0
http://www.voidspace.org.uk/python/cgi.shtml#logintools

A CGI framework for user authentication and account management. Add
user login to your CGI applications with two lines of code !

This update moves to the pythonutils 0.2.2 set of modules. logintools
is now being used on another project and seeing some development work.


textmacros
http://www.voidspace.org.uk/python/modules.shtml#macros

A textmacro system for adding features to docutils
(http://docutils.sourceforge.net ).

This update makes it *much* easier to use (it now behaves like the
``buildhtml.py`` script). Easily add Python source coloring, smilies,
and accronyms (and much more) to reStructured Text.


downman 0.4.1
http://www.voidspace.org.uk/python/cgi.shtml#downman

A CGI download manager. Present files for download and statistics
(basic) about download rates.

This update has a security fix and uses the pythonutils 0.2.2 set of
modules. Also other minor updates. It also needs the updated version of
cgiutils.


cgiutils 0.3.3
http://www.voidspace.org.uk/python/recipebook.shtml#utils

A helpful set of constants and functions when working with CGI scripts.

This update has two bugfixes.


copy2cgi 1.1.1
http://www.voidspace.org.uk/python/recipebook.shtml#copy2cgi

A small convenience script to copy files and directories to a target
location. Useful for copying files to a server directory for testing.


pycrypto 2.0.1
http://www.voidspace.org.uk/python/modules.shtml#pycrypto

I've (finally) updated the prebuild windows binary of PyCrypto (Python
2.4) to the 2.0.1 version.

All the best,


Fuzzyman
http://www.voidspace.org.uk/python/weblog/index.shtml


All the Voidspace modules and applications are available under the OSI
Approved Open Source BSD License -
http://www.voidspace.org.uk/python/license.shtml

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


Re: File Upload Script

2005-09-30 Thread Fuzzyman
On 29 Sep 2005 21:41:21 -0700, "Chuck" <[EMAIL PROTECTED]>
wrote:

>Hi, can anyone provide or point me in the direction of a simple python
>file upload script?  I've got the HTML form part going but simply
>putting the file in a directory on the server is what I'm looking for.
>Any help would be greatly appreciated.
>

An http CGI upload ?

http://www.voidspace.org.uk/python/cgi.shtml

All the best,

Fuzzyman
http://www.voidspace.rog.uk/python

>Thanks,
>Chuck
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: RELEASED Python 2.4.2 (final)

2005-09-30 Thread Fuzzyman
On Thu, 29 Sep 2005 17:53:47 -0700, Bugs <[EMAIL PROTECTED]> wrote:

>I downloaded the 2.4.2 Windows Binary Installer from python.org but when 
>I try to run python.exe I get the following in the console:
>
>ActivePython 2.4.1 Build 247 (ActiveState Corp.) based on
>Python 2.4.1 (#65, Jun 20 2005, 17:01:55) [MSC v.1310 32 bit (Intel)] on 
>win32
>Type "help", "copyright", "credits" or "license" for more information.
> >>>
>
>It says ActivePython 2.4.1 but I downloaded the 2.4.2 binary installer 
>from python.org and the python.exe executable I'm running is timestamped 
>9/28/2005 12:41PM...  Any ideas what I'm doing wrong?
>

I had problems updating from activestate 2.4 to activestate 2.4.1

I think it was caused by not uninstalling the original. This does mean
that even a *minor* version upgrade is a PITA. To do it cleanly all
extension modules have to be uninstalled and re-installed.

*sigh*

Fuzzyman
http://www.voidspace.org.uk/python

>Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: ConfigObj 4.0.0 Final and Pythonutils 0.2.3

2005-10-18 Thread Fuzzyman
ConfigObj 4.0.0 final and Pythonutils 0.2.3 have just hit the streets.

http://www.voidspace.org.uk/python/configobj.html
http://www.voidspace.org.uk/python/pythonutils.html

They are both pure Python modules - the source distributions include
full documentation, which is also online.

What's New ?


ConfigObj 4.0.0 final has two bugfixes.
Using ``setdefault`` to create a new section would return a reference
to the dictionary you passed in - not the new section.
Also fixed a trivial bug in ``write`` (wouldn't have affected anyone).

Pythonutils 0.2.3 is updated to include the ConfigObj 4.0.0 final and
cgiutils 0.3.3

ConfigObj is now marked stable. (But caveat emptor :-)

What is ConfigObj ?
===

ConfigObj is a simple but powerful config file reader and writer: an
*ini file round tripper*. Its main feature is that it is very easy to
use, with a straightforward programmer's interface and a simple syntax
for config files. It has lots of other features though :

* Nested sections (subsections), to any level
* List values
* Multiple line values
* String interpolation (substitution)
* Integrated with a powerful validation system

- including automatic type checking/conversion
- repeated sections
- and allowing default values

* All comments in the file are preserved
* The order of keys/sections is preserved
* No external dependencies

What is Pythonutils ?
=

The Voidspace Pythonutils package is a simple way of installing the
Voidspace collection of modules. Several of the Voidspace Projects
depend on these modules. They are also useful in their own right of
course. They are primarily general utility modules that simplify common
programming tasks in Python.

These are currently :

* ConfigObj - simple config file handling
* validate - validation and type conversion system
* listquote - string to list conversion
* StandOut - simple logging and output control object
* pathutils - for working with paths and files
* cgiutils - cgi helpers (and functions for sending emails etc)
* urlpath - functions for handling URLs
* odict - Ordered Dictionary Class

All the best,

Fuzzyman
http://www.voidspace.org.uk/python

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


Re: Python as a HTTP Client

2005-11-10 Thread Fuzzyman
``urllib2`` is the standard library module you need.

I've written a guide to using it (although it's very easy - but some
attributes of the errors it can raise aren't documented) :

http://www.voidspace.org.uk/python/articles/urllib2.shtml

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: modify dictionary while iterating

2005-11-11 Thread Fuzzyman
Iterate over the keys ( for entry in adict.keys(): )

All the best,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


ANN: rest2web 0.4.0alpha

2005-11-14 Thread Fuzzyman
rest2web 0.4.0 alpha is now available.

http://www.voidspace.org.uk/python/rest2web/

What's New ?
==

See
http://www.voidspace.org.uk/python/rest2web/reference/changelog.html#version-0-4-0-alpha-2005-11-11

Lots of bugfixes and new features since the 0.3.0 release.

Includes a new gallery plugin (which will also function as a standalone
HTML gallery generator).
http://www.voidspace.org.uk/python/rest2web/reference/gallery.html

There is also an experimental windows executable version.

The documentation has been greatly improved, including a tutorial which
should get anyone up to scratch on the basics very quickly.
http://www.voidspace.org.uk/python/rest2web/tutorial.html

What is rest2web
=

**rest2web** is a tool for autogenerating wesites, or parts of
websites. It's main features are :

* Integrated with docutils.
* Automatically builds index pages and navigation links (sidebars and
{acro;breadcrumbs;Weird name for navigation links ?}).
* Embedded code in templates for unlimited expressiveness.
* Flexible macro system.
* Uses relative links, so sites can be viewed from the filesystem.
* Unicode internally - so you don't have to be. {sm;:-p}
* Includes features for multiple translations of sites.
* Built-in gallery creator plugin.
* The basic system is very easy to use.
* Lots of powerful (optional) features.

The content can be stored as HTML, or in reST format; in which case the
HTML will be generated using docutils. **rest2web** inserts each page
into a template, and automatically creates index pages for sections,
and navigation links.

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


Re: how to bypass firewall

2005-11-16 Thread Fuzzyman

Parth wrote:
> Hello everyone,
> I need some help regrading byassing firewalls.My college has internet
> aces but it prevents us from dowloading music(*.mp3,*.mid,etc.)from the
> net.I use a win xp sp2 and browse using ie 6. Is there any way how i
> can dowload music on my computer using this connection. (We have a
> proxy server throught which all the connections pass)
>

You need to use a solution *outside* the firewall.

Shell access on a virtual server is cheap - check if port 22 is
blocked. SSH dynamic port forwarding will get you unlimtied access via
a socks 4 proxy.

Alternatively you need an external proxy that renames files. If you're
prepared to do some *work* - you could start with approx -
http://www.voidspace.org.uk/python/cgi.shtml#approx

As it's a CGI it can be used with quite a cheap hosting account

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> Thanks,
> Parth Shah

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


Re: Reinvent no more forever

2005-11-16 Thread Fuzzyman
Ben Finney wrote:
> Howdy all,
>

Hello,

> On dirtSimple.org[0], PJE wrote:
>
> "Why is Python "blessed" with so much reinvention? Because it's
> often cheaper to rewrite than to reuse. Python code is easy to
> write, but hard to depend on. You pretty much have to:
>
> 1. limit yourself to platforms with a suitable packaging
> system,
> 2. bundle all your dependencies into your distribution, or


For pure python modules I don't find this to be a big problem.

> 3. make your users do all the work themselves
>
> Ouch. No wonder rewriting looks easier."
> [snip..]
> I now have a setuptools package of my Enum implementation. Should I
> submit it to PyPI?
>
> Advantages:
>
>   - I can declare a dependency on that package for all my other
> packages that need such functionality, instead of bundling it
> every time.
>
>   - Others can benefit from my code, instead of yet again including an
> Enum implementation (home-grown, or picked from a cookbook) by a
> simple dependency declaration.
>
>   - The code hopefully gets improved and generalised and all the other
> benefits that accrue to software with many users.
>

These are all very compelling reasons.

> Disadvantages:
>
>   - Proliferation. What's the protocol when[1] someone else puts an
> (incompatible, differently-specified) Enum implementation into
> PyPI?
>

That shouldn't be any more of a problem than the current situation. In
fact as the setuptools system becomes more established then it should
be easier for people to discover that an existing package does what
they want - rather than creating their own.

>   - Naming. How many ways can a package providing an Enum be named?
> I'd prefer mine to be named "Enum" or "enum", but why should mine
> be the one that claims that name?
>

I think "first come - first served" is the only possible way this can
work.

>   - It's just a pretty simple type, with unit tests. Does this really
> justify a PyPI package?
>

If it solves a common problem in an elegant way, then it's better
shared. :-)

> This is common to any repository of code. But the "automatic
> dependency" problem means that all those packages, and many more
> outside that repository, need to know how those problems are resolved.
>
> Operating system distributors have policies (to greater or lesser
> degrees of strictness) to ensure this kind of quality control. My
> understanding of PyPI is that there's no such policy.
>
> I'd love to follow the mantra PJE espouses, but if it's good for one
> person it's probably good for countless others. How do we deal with
> that? What actions can we take in advance to prevent problems in
> future?
>

Isn't setuptools *the system* that addresses these issues ? It provides
a way to track and auto-install dependencies  - so long as you have the
right kind of netowrk connection [1] and the packager of the
dependencies provides them in a way compatible with setuptools.

All the best,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

[1] setuptools uses python code to access the internet and install
dependencies. Python code can't fetch https URLs through a proxy and
can't use a SOCKS proxy at all. That means with some kinds of internet
conenctions (e.g. behind company firewalls) it doesn't work. Building
optional support for pycurl into setuptools could possibly resolve
this.

>
> [0] http://dirtsimple.org/2005/07/reinvent-no-more-forever.html>
>
> [1] Of course, someone already has. I prefer mine to theirs, hence the
> question.
>
> --
>  \ "I planted some bird seed. A bird came up. Now I don't know |
>   `\   what to feed it."  -- Steven Wright |
> _o__)  |
> Ben Finney

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


Re: Why are there no ordered dictionaries?

2005-11-21 Thread Fuzzyman

Fredrik Lundh wrote:
> Ben Sizer wrote:
>
> > > No, that's not the same logic.  The dict() in my example doesn't convert 
> > > be-
> > > tween data types; it provides a new way to view an existing data 
> > > structure.
> >
> > This is interesting; I would have thought that the tuple is read and a
> > dictionary created by inserting each pair sequentially. Is this not the
> > case?
>
[snip..]
> (as an example, on my machine, using Foord's OrderedDict class
> on Zwerschke's example, creating the dictionary in the first place
> takes 5 times longer than the index approach, and accessing an
> item takes 3 times longer.  you can in fact recreate the index 6
> times before OrderedDict is faster; if you keep the index around,
> the OrderedDict approach never wins...)
>

So, so long as you want to use the dictionary less than six times -
it's faster to store/access it as a list of tuples. ;-)

Everytime you want to access (or assign to) the data structure as a
dictionary, you have to re-create the index.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> 

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


Re: Web-based client code execution

2005-11-21 Thread Fuzzyman

Paul Watson wrote:
> John J. Lee wrote:
[snip..]
> I appreciate your long list of references.  For this task, I think the
> first answer may have to be the one with which to go.  A standard
> application that talks through port 80 and perhaps can use proxies.
>
> My desire to have the code distributed through a web page is just to
> ensure that the user is running the correct version and has not hacked
> it in any way.  I suppose I can checksum the local client application
> and compare it with what is on the server.  Then, make a way to
> update... ARGH!
>

If you can run it as a client application (i.e. not through the browser
but still across the internet) - then this all seems quite easy to
achieve. It also allows you to access the local filesystem without
dropping out of Python or using ActiveX objects.

If you know the version of Python the machines are using (or create a
loader program using py2exe) then you only need dsitribute the 'pyc'
bytecode files. (Making it *much* harder to hack for the average user).

I don't know if anyone has released an 'auto-update' framework for
applications, but it would be a nice project. I guess each time it's
needed the requirements will be slightly different though - but there
are a lot of general principles.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-11-22 Thread Fuzzyman
Christoph Zwerschke wrote:
> Fredrik Lundh wrote:
[snip..]
> You're right; I found creating a Larosa/Foord OrderedDict in this
> example to be even 8 times slower than an ordinary dict. However, two
> things need to be said here: 1) The dictionary in my exmaple was pretty
> small (only 3 items), so you are not really measuring the performance of
> the ordered dict, but mainly the overhead of using a user derived class
> in comparison with the built-in dict type. And 2) the implementation by
> Larosa/Foord is very slow and can be easily improved, for instance like
> that:
>
> def __init__(self, init_val = ()):
>  dict.__init__(self, init_val)
>  self.sequence = [x[0] for x in init_val]
>

But that doesn't allow you to create an ordered dict from another
ordered dict.

It also allows duplicates in the sequence attribute. It's a useful idea
though.

Thanks

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> With this change, creating the ordered dictionary is considerably faster
> and for an average size dictionary, the factor of 8 pretty quickly
> converges against 1.
>
> But of course, it will always be slower since it is constructed on top
> of the built-in dict. In end effect, you always have to maintain a
> sequence *plus* a dictionary, which will be always slower than a sheer
> dictionary. The ordered dictionary class just hides this uglyness of
> having to maintain a dictionary plus a sequence, so it's rather an issue
> of convenience in writing and reading programs than a performance issue.
>
> It may be different if the ordered dict would be implemented directly as
> an ordered hash table in C.
> 
> -- Christoph

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


Re: Why are there no ordered dictionaries?

2005-11-22 Thread Fuzzyman

Kay Schluehr wrote:
> Christoph Zwerschke wrote:
>
> > That would be also biased (in favour of Python) by the fact that
> > probably very little people would look for and use the package in the
> > cheese shop if they were looking for ordered dicts.
>
> Does anyone actually use this site? While the Vaults offered a nice
> place and a nice interface the Cheese Shop has the appeal of a code
> slum.
>

Hmmm.. it's *the* repository for Python code. I expect quite a few
people use it...

:-)

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> Kay

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


Re: Why are there no ordered dictionaries?

2005-11-22 Thread Fuzzyman
Of course ours is ordered *and* orderable ! You can explicitly alter
the sequence attribute to change the ordering.

I think we're looking at improving performance based on some of the
suggestions here - as well as possibly widening it to include some of
the alternative use cases. (Or at least Nicola Larosa will do it and
I'll criticise it).

All for another day though...

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-11-23 Thread Fuzzyman

Christoph Zwerschke wrote:
> >>I still believe that the concept of an "ordered dictionary" ("behave
> >>like dict, only keep the order of the keys") is intuitive and doesn't
> >>give you so much scope for ambiguity. But probably I need to work on an
> >>implementation to become more clear about possible hidden subtleties.
>
> Bengt Richter schrieb:
>
> > Does that mean that the Larosa/Foord odict.py implementation in PyPI
> > does not do what you want?
>
> Basically, it is what I had in mind. But I'm now seeing some things that
> could be improved/supplemented, e.g.
> - performance improvements

Implementation changes to follow, based on suggestions in this thread.
For *optimal* performance it needs to be implemented in C of course.
:-)

As F points out, a list of tuples may give you a data structure that
can be accessed quicker (although some operations will be slower). An
ordered dictionary will be a lot easier to use and make your code more
readable though.

> - the internal keys list should be hidden

I disagree. It is exposed so that you can manually change the order
(e.g. to create a "sorted" dict, rather than one ordered by key
insertion).

What do you *gain* by hiding it ?

> - list methods should be mixed in instead
>

Hmm... I did consider this. Which list methods would you consider
appropriate ?

The difficulty is that integers are valid keys for a dictionary.
Perhaps a subclass that uses integers as indexes instead...

You can always perform list operations on the ``sequence`` attribute of
course.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> -- Christoph

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


Re: Why are there no ordered dictionaries?

2005-11-23 Thread Fuzzyman

Bengt Richter wrote:
> On 22 Nov 2005 02:16:22 -0800, "Fuzzyman" <[EMAIL PROTECTED]> wrote:
>
> >
> >Kay Schluehr wrote:
> >> Christoph Zwerschke wrote:
> >>
> >> > That would be also biased (in favour of Python) by the fact that
> >> > probably very little people would look for and use the package in the
> >> > cheese shop if they were looking for ordered dicts.
> >>
> >> Does anyone actually use this site? While the Vaults offered a nice
> >> place and a nice interface the Cheese Shop has the appeal of a code
> >> slum.
> >>
> >
> >Hmmm.. it's *the* repository for Python code. I expect quite a few
> >people use it...
> >
> >:-)
> >
> I hadn't realized how much stuff was there. I generally google for stuff,
> but I will be looking directly now.
>
> BTW, I made a mod[1] to your odict that I think/hope is going to be generally 
> faster.
> It requires 2.4 though. It passes the same doctest, so its probably close to 
> the same.
> It stores the ordering info differently, but is also a dict subclass.
>

odict maintains compatibility with Python 2.2 - so it's not a change
we'd put back into the module I don't think.

Changes that keep compatibility are very welcoemd though.

> Do you happen to have a timing test that exercises various aspects, so I can 
> try it
> before I embarrass myself? Otherwise I guess I'll write something.
>

The only tests we have are the ones in the module.

If you create some timing tests we'd be interested in having access to
them though. They would be a useful addition.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> Would the would-be users chime in with some idea of what kinds of operations 
> are
> most important timing-wise? Which would get the most use? How dynamic would 
> ordering typically be?
>
> [1] fairly pervasive little mods actually
> [ 9:15] C:\pywk\clp>diffodict.py odictb.py |wc
> 146458   4948
>
> [ 9:15] C:\pywk\clp>wc odict*.py
> 467   1228  12483   odict.py
> 511   1500  14728   odictb.py
> 978   2728  27211   Totals
> 
> Regards,
> Bengt Richter

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


Re: Why are there no ordered dictionaries?

2005-11-23 Thread Fuzzyman

Christoph Zwerschke wrote:
> One implementation detail that I think needs further consideration is in
> which way to expose the keys and to mix in list methods for ordered
> dictionaries.
>
> In http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
> the keys are exposed via the keys() method which is bad. It should be a
> copy only, like for ordinary dicts (one comment also mentions that).
>
> In Foord/Larosa's odict, the keys are exposed as a public member which
> also seems to be a bad idea ("If you alter the sequence list so that it
> no longer reflects the contents of the dictionary, you have broken your
> OrderedDict").
>

So don't do it. ;-)

> I think it would be probably the best to hide the keys list from the
> public, but to provide list methods for reordering them (sorting,
> slicing etc.).
>
> For instance:
>
> d1 = OrderedDict( (1, 11), (2, 12), 3, 13) )
>
> d1[1:] ==> OrderedDict( (2, 12), 3, 13) )
>

So what do you want returned when you ask for d1[1] ? The member keyed
by 1, or the item in position 1 ?

You can access the members using list operations on the sequence
attribute.

E.g. d1[d1.sequence[index]]

This could probably be made more convenient.

> d1[0] + d1[2] ==> OrderedDict( (1, 11), (3, 13) )
>
> d1.reverse() ==> OrderedDict( (3, 13), (2, 12), 1, 11) )
>

Interesting idea.

> d1.insert(1, (4, 14))
>  ==> OrderedDict( (1, 11), (4, 14), (2, 12), 3, 13) )
>

Also an interesting idea.

> etc.
>
> But no other way to directly manipulate the keys should be provided.
>

Why - don't trust yourself with it ?

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> -- Christoph

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


Re: Why are there no ordered dictionaries?

2005-11-23 Thread Fuzzyman
There is already an update method of course. :-)

Slicing an ordered dictionary is interesting - but how many people are
actually going to use it ? (What's your use case)

You can already slice the sequence atribute and iterate over that.

All the best,


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-11-23 Thread Fuzzyman
While we're on the subject, it would be useful to be able to paste in a
changelog as well as a description.

Currently when updating versions you have to include the changelog in
the description - or not at all...

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: How can I package a python script and modules into a single script?

2005-11-23 Thread Fuzzyman
You could use my includer script.

http://www.voidspace.org.uk/python/recipebook.shtml#includer

It effectively adds an include direct to python scripts.

##include module.py
from module import *

You then run ``includer.py infilename outfilename``

This replaces the ``##include ..`` with the source of the included
module and *removes* the import statement.
This makes it possible to maintain modules separately, but distribute
as a single script.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-11-23 Thread Fuzzyman

Rick Wotnaz wrote:
> "Fuzzyman" <[EMAIL PROTECTED]> wrote in
> news:[EMAIL PROTECTED]:
>
> >
> > Christoph Zwerschke wrote:
> >> - the internal keys list should be hidden
> >
> > I disagree. It is exposed so that you can manually change the
> > order (e.g. to create a "sorted" dict, rather than one ordered
> > by key insertion).
> >
> > What do you *gain* by hiding it ?
>
> The internal list should be 'hidden' in the sense that it itself
> would not be modifiable, though it should be routine to obtain a
> copy of it at any time. That copy could then be arranged as needed.
> Any rearrangement of the original list's order destroys the reason
> for having an entry- or change-ordered dict in the first place.
>

That's not the only use case. Other use cases are to have a specific
order, not based on entry time.

Simple example :

d1 = OrderedDict(some_dict.items())
d1.sequence.sort()

d1 is now an ordered dict with the keys in alphabetic order.

If you don't want to modify sequence, don't. If you want a copy do :

seq = d1.sequence[:]

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> -- 
> rzed

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


Re: Why are there no ordered dictionaries?

2005-11-24 Thread Fuzzyman

Alex Martelli wrote:
> Fuzzyman <[EMAIL PROTECTED]> wrote:
>...
> > > - the internal keys list should be hidden
> >
> > I disagree. It is exposed so that you can manually change the order
> > (e.g. to create a "sorted" dict, rather than one ordered by key
> > insertion).
> >
> > What do you *gain* by hiding it ?
>
> Freedom of implementation, of course.  E.g., I can perhaps get better
> performance by keeping a red-black tree of (insertiontime,key) pairs, so
> for example deleting a key is O(log(N)) rather than O(N) as it would
> have to be if the sequence had to be kept as a Python list.
>
> What ELSE do you ever gain by enforcing abstraction and information
> hiding?  Conceptual integrity and implementation freedom...
>

The poster I was replying to inferred that we should hide it to protect
him from breaking it. :-)

Your reason is much more valid than the one I inferred. (And probably
worth chanign the code for).

>
> > > - list methods should be mixed in instead
> >
> > Hmm... I did consider this. Which list methods would you consider
> > appropriate ?
> >
> > The difficulty is that integers are valid keys for a dictionary.
> > Perhaps a subclass that uses integers as indexes instead...
>
> What about allowing slicing, taking advantage of the fact that slices
> are NOT valid dictionary keys?

Hmm... ok, simple enough to implement. What would anyone *use* it for
though ?

> Presumably sort and reverse methods are also desired.
>

Yeah - good idea. Insert is also good - I can't remember if we provide
this or not.

Thanks


Fuzzyman
http://www.voidspac.org.uk/python/index.shtml

> > You can always perform list operations on the ``sequence`` attribute of
> > course.
>
> But NOT having to expose .sequence as a real mutable list whose changes
> affect ordering has many advantages, as above noticed.
> 
> 
> Alex

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


Re: Why are there no ordered dictionaries?

2005-11-24 Thread Fuzzyman
Ok.

That answers a question in the post I've just made. This thread is hard
to follow.

Thanks

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-11-24 Thread Fuzzyman

Christoph Zwerschke wrote:
> Fuzzyman wrote:
>
> > So what do you want returned when you ask for d1[1] ? The member keyed
> > by 1, or the item in position 1 ?
>
> In case of conflict, the ordered dictionary should behave like a
> dictionary, not like a list. So d1[1] should be the member keyed by 1,
> not the item in position 1. Only in case there is no member keyed by 1,
> the item in position 1 could be returned, but I think that would be too
> adventurous a hattrick and can lead to big confusion. Better to raise a
> KeyError in that case.
>

I agree - hard to trace bugs lie this way

[snip..]
>
> Instead of writing d.sequence = new_sequence, I would write
> d.setkeys(new_sequence). But I'm not sure what to do if new_sequence is
> not a permutation of the old one. Raise a KeyError? Or even swallow
> this? For instance
>

This is an interesting question - I don't know which is the best
behaviour here.

It's probably better to raise a KeyError - that way the error will
occur when it happens.

The simplest way of doing this is to check that the new key list
(sorted) is the same as the original one (sorted). This is potentially
quite an expensive operation.

It might be faster to compare sets with Python 2.4 - but we intend to
retain compatibility with Python 2.2.

> d = OrderedDict((1,11), (2,12))
>
> d.setkeys((2, 1)) ==> d = OrderedDict((2, 11), (1, 12))
>
> d.setkeys((3, 4)) ==> d = OrderedDict((3, 11), (4, 12)) (or KeyError?)
>
> d.setvalues((12, 11)) ==> d = OrderedDict((1, 12), (2, 11))
>
> d.setvalues((13, 14)) ==> d = OrderedDict((1, 13), (2, 14)) (always ok)
>
> (Or maybe better set_keys in analogy to has_key?)
>
> I hesitate making keys and values managed properties, because this would
> conflict with them being methods in ordinary dicts. Ordered dicts should
> resemble ordinary dicts as closely as possible. And giving it a
> different name like "sequence" I find confusing and unintuitive.
>

You really want to be able to set values as a sequence ? I suppose it's
even easier to implement than changing keys, but I'd never considered
it.

> A resort could be the following: If keys() is given a sequence as
> argument, then use this as the new sequence of keys, and similar with
> values(). This way, no new methods need to be introduced.
>

That's not a bad idea. I'll chat with Nicola Larosa and see what he
thinks.

It does break backawards compatibility of course...

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> -- Christoph

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


Re: Why are there no ordered dictionaries?

2005-11-24 Thread Fuzzyman

Carsten Haese wrote:
> On Wed, 23 Nov 2005 23:39:22 +0100, Christoph Zwerschke wrote
> > Carsten Haese schrieb:
> >
> > > Thus quoth the Zen of Python:
> > > "Explicit is better than implicit."
> > > "In the face of ambiguity, refuse the temptation to guess."
> > >
> > > With those in mind, since an odict behaves mostly like a dictionary, []
> > > should always refer to keys. An odict implementation that wants to allow
> > > access by numeric index should provide explicitly named methods for that
> > > purpose.
> >
> > Exactly. But I don't think in this case such methods would be
> > needed. You easily get the i-th value in the ordered dict as
> > d.values()[i].
> >
> > -- Chris
>
> True enough, but unless the odict has its list of values on hand, you're
> asking the odict to build a list of all its values just so that you can get
> the i'th element. Having a method that does the equivalent of d[d.sequence[i]]
> would be cleaner and more efficient.
>

I'm going to add some of the sequence methods. I'm *not* going to allow
indexing, but I will allow slicing.

You can also do d[d.keys()[i]]

This provides two ways of fetching values by index, so I don't want to
add another.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
> -Carsten

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


Re: Opening for Python Programmers at Japan

2005-11-24 Thread Fuzzyman
I'll do the job from the UK for you. ;-)

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-11-24 Thread Fuzzyman
By the way, Nicola and I will be working on an improving odict in line
with several of the suggestions in this thread.

See :
http://www.voidspace.org.uk/python/weblog/arch_d7_2005_11_19.shtml#e140

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-11-24 Thread Fuzzyman

Tom Anderson wrote:
> On Tue, 22 Nov 2005, Christoph Zwerschke wrote:
>
> > One implementation detail that I think needs further consideration is in
> > which way to expose the keys and to mix in list methods for ordered
> > dictionaries.
> >
> > In Foord/Larosa's odict, the keys are exposed as a public member which
> > also seems to be a bad idea ("If you alter the sequence list so that it
> > no longer reflects the contents of the dictionary, you have broken your
> > OrderedDict").
> >
> > I think it would be probably the best to hide the keys list from the public,
> > but to provide list methods for reordering them (sorting, slicing etc.).
>
> I'm not too keen on this - there is conceptually a list here, even if it's
> one with unusual constraints, so there should be a list i can manipulate
> in code, and which should of course be bound by those constraints.
>

I think I am now in favour of hiding hte sequence attribute.

You will be able to mutate the the keys list through :

d1 = OrderedDict(some_sequence_of_items)
keys = d1.keys()
keys.sort() # or other mutation
d1.keys(keys)

Admittedly this is a lot slower than :

d1 = OrderedDict(some_sequence_of_items)
d1.sequence.sort()

*but* it frees the squence attribute from any implementation details.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> I think the way to do it is to have a sequence property (which could be a
> managed attribute to prevent outright clobberation) which walks like a
> list, quacks like a list, but is in fact a mission-specific list subtype
> whose mutator methods zealously enforce the invariants guaranteeing the
> odict's integrity.
>
> I haven't actually tried to write such a beast, so i don't know if this is
> either of possible and straightforward.
>
> tom
>
> --
> When I see a man on a bicycle I have hope for the human race. --
> H. G. Wells

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


Re: Why are there no ordered dictionaries?

2005-11-24 Thread Fuzzyman
d.keys() will still return a copy of the list, so d.keys()[i] will
still be slower than d.sequence[i]

Slicing shouldn't be too much slower though.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Help me to catch this exception :-)

2005-11-24 Thread Fuzzyman
I don't know the answer, but I like the problem. :-)

What happens with the standard CGIHttpServer ?

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Understanding Python Documentation

2005-11-24 Thread Fuzzyman
pydoc - sorry to be terse... I'm sure others will expand. :-)

There was also a project, recently, that generated the sort of api
documentation for the whole standard library.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-11-24 Thread Fuzzyman
Bengt Richter wrote:
> On Wed, 23 Nov 2005 23:00:29 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> 
> wrote:
>
[snip..]
> I think also that d1==d2 should effectively be implemented as d1[:] == d2[:] 
> -- i.e, compare
> the item lists to implement comparisons.
>

IIUC then the odict effectively already does this.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> Detailed requirements are most of the work ;-)
> I'm thinking now to try subclassing list in a constrained way instead of 
> dict, but well see.
> 
> Regards,
> Bengt Richter

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


Re: Why are there no ordered dictionaries?

2005-11-25 Thread Fuzzyman

Christoph Zwerschke wrote:
> Fuzzyman schrieb:
> > d.keys() will still return a copy of the list, so d.keys()[i] will
> > still be slower than d.sequence[i]
>
> Right, I forgot that.  Bengt suggested to implement __call__ as well as
> __getitem__ and __setitem__ for keys, values and items.
>
> In this case, you could very effectively access it as d.values[i].
>

That means making keys, values, and items custom objects.
Creating a new instance would have the overhead of creating 4 new
objects instead of just 1. Is the added convenience worth it ? (Plus
the extra layers of method calls for each access).

I'm not sure. It's a nice idea in terms of using it (we could just
leave the sequence attribute as an alias for the new keys attribute -
for backwards compatibility).

All the best,



Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> -- Christoph

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


Re: Why are there no ordered dictionaries?

2005-11-25 Thread Fuzzyman
Sure - that was just an example of mutating the keys list without
having direct access to it.

If keys was implemented as an object (with a ``__call__`` method) then
we could also implement sequence methods on it - making it easier to
mutate the keys/values/items directly.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-11-25 Thread Fuzzyman

Alex Martelli wrote:
> Fuzzyman <[EMAIL PROTECTED]> wrote:
>
> > There is already an update method of course. :-)
> >
> > Slicing an ordered dictionary is interesting - but how many people are
> > actually going to use it ? (What's your use case)
>
> I detest and abhor almost-sequences which can't be sliced (I consider
> that a defect of collections.deque).  If the ordered dictionary records
> by its sequencing the time order of key insertion, being able to ask for
> "the last 5 keys entered" or "the first 3 keys entered" seem to me to be
> perfectly natural use cases, and most naturally accomplished by slicing
> of course, d[-5:] and d[:3] respectively.
>

If you slice an ordered dictionary, I assume you would expect to get an
ordered dictionary back ?

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> 
> Alex

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


Re: Why are there no ordered dictionaries?

2005-11-25 Thread Fuzzyman
Sure - that was just an example of mutating the keys list without
having direct access to it.

If keys was implemented as an object (with a ``__call__`` method) then
we could also implement sequence methods on it - making it easier to
mutate the keys/values/items directly.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-11-27 Thread Fuzzyman
Note that I've done two things with the Foord/Larosa dict. ;-)

I've implemented slicing, including slice assignment and deletion. I've
also 'hidden' ``sequence``, but you can pass arguments to keys, values
and items.

I've done a second (experimental) implementation of a custom keys
object. This is effectively the managed list - which you can call as a
method or mutate in place. You can't delete members from 'keys' but you
can do slice assignment so long as the sequence you're replacing is the
same length (and is a re -ordering of the set being replaced).

I'll post it on Monday, and if people like it I'll complete it.

All the best,


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


New Ordered Dictionery to Criticise

2005-11-28 Thread Fuzzyman
Sorry for this hurried message - I've done a new implementation of out
ordered dict. This comes out of the discussion on this newsgroup (see
blog entry for link to archive of discussion).

See the latest blog entry to get at it :
http://www.voidspace.org.uk/python/weblog/index.shtml

Criticism solicited (honestly) :-)

We (Nicola Larosa and I) haven't yet made any optimisations - but there
are two implementations to play with.

One allows you to access the keys attribute as if it was a sequence (as
well as a method).

All the best,

Fuzzyman
 http://www.voidspace.org.uk/python/index.shtml

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


Re: New Ordered Dictionery to Criticise

2005-11-29 Thread Fuzzyman

Martin v. Löwis wrote:
> Fuzzyman wrote:
> > Criticism solicited (honestly) :-)
>
> A couple of minor points:
> - I would drop 2.2 compatibility

There are a lot of cheap hosting accounts where Python 2.2 is all that
is available. I would only drop support if there is some *compelling*
reason to do so.

> - self=self isn't needed in the functions, because of
>nested scopes

Cool, I'll test this out.

> - popitem(self) can be rewritten as
>
>def popitem(self):
>try:
>key = self._sequence.pop()
>except IndexError:
># always try to give the same exception string as
># dict
>raise KeyError("popitem(): dictionary is empty")
>return key, self.pop(key)
>

Yup, that's nicer - thanks.

> - One problem with the FancyDict is that it allows
>d.keys.append(100)

Are you sure ?

No file given.
Alias   System Command
--
cls cls
copycopy
ddirdir /ad /on
dir dir /on
echoecho
ldirdir /ad /on
ls  dir /on
mkdir   mkdir
ren ren
rmdir   rmdir
--
Total number of aliases: 10
Movable Python
IPython Interactive Shell. See the manual for a list of features and
tips.
Ctrl-D to exit.

>>> from odict import FancyODict
>>> d = FancyODict()
>>> d
  Out[3]:{}

>>> d.keys
--> d.keys()
   Out[4]:[]

>>> d.keys.append('anything')
---
exceptions.TypeError Traceback (most
recent call
 last)

\configobj4\pythonutils\odict.py in append(self, item)
713 def __iadd__(self, other): raise TypeError('Can\'t add in
place to keys')
714 def __imul__(self, n): raise TypeError('Can\'t multiply
keys in place')
--> 715 def append(self, item): raise TypeError('Can\'t append
items to keys')
716 def insert(self, i, item): raise TypeError('Can\'t insert
items into keys')
717 def pop(self, i=-1): raise TypeError('Can\'t pop items from
keys')

TypeError: Can't append items to keys

>>>

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> 
> Regards,
> Martin

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


Re: New Ordered Dictionery to Criticise

2005-11-29 Thread Fuzzyman

Christoph Zwerschke wrote:
> Fuzzyman wrote:
> > Sorry for this hurried message - I've done a new implementation of out
> > ordered dict. This comes out of the discussion on this newsgroup (see
> > blog entry for link to archive of discussion).
>
> Thanks. I'll try to check it out and put my oar in over the next
> weekend.

Cool, thanks.

Someone has commented on my blog that passing lists to ``keys``,
``values``, and ``items`` to assign to them "smells funny".

They've suggested new methods ``setkeys``, ``setitems``, ``setvalues``
instead. Any opinions ?

> One thing I already noticed: str() and repr() both output the
> OrderedDict as if it was an ordinary dictionary. For str() this may be
> acceptable, but repr() should output "a valid Python expression that
> could be used to recreate an object with the same value".
>

Yup. If you look in the code, there is already a commented out version
of ``__repr__`` that does this.

*Unfortunately*, it means changing *all* the doctests - so it will have
to wait until one of us can be bothered. :-)

It  will happen in the course of time I guess.

All the best,


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> -- Christoph

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


Re: HTML parsing/scraping & python

2005-12-01 Thread Fuzzyman
The standard library module for fetching HTML is urllib2.

The best module for scraping the HTML is BeautifulSoup.

There is a project called mechanize, built by John Lee on top of
urllib2 and other standard modules.

It will emulate a browsers behaviour - including history, cookies,
basic authentication, etc.

There are several modules for automated form filling - FormEncode being
one.

All the best,


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Python CGI

2005-12-01 Thread Fuzzyman
That doesn't sound too difficult to do in a single script.

As Tim has mentioned, you can always separate the code in two modules
and just import the one needed for the action being performed.

Your script just needs to output different HTML depending on the result
- with a different form depending on what information is required.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-12-01 Thread Fuzzyman

Christoph Zwerschke wrote:
>

Hello Christoph,

> I think re-ordering will be a very rare use case anyway and slicing even
> more. As a use case, I think of something like mixing different
> configuration files and default configuration parameters, while trying
> to keep a certain order of parameters and parameters blocks.
>

In actual fact - being able to *reorder* the dictionary is the main way
I use this dictionary.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> -- Christoph

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


Re: New Ordered Dictionery to Criticise

2005-12-01 Thread Fuzzyman

Fuzzyman wrote:
> Sorry for this hurried message - I've done a new implementation of out
> ordered dict. This comes out of the discussion on this newsgroup (see
> blog entry for link to archive of discussion).
>
> See the latest blog entry to get at it :
> http://www.voidspace.org.uk/python/weblog/index.shtml
>

Hello all,

I've just done a new "beta 2" version. It has a full version of
FancyODict with the custome "callable sequence objects" for keys,
values and items. They are almost completely covered by tests.

You can download the new(er) version from :
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=odictbeta2.py

Full discussion of the remaining issues below, or at :
http://www.voidspace.org.uk/python/weblog/arch_d7_2005_11_26.shtml#e147

Progress on the updated implementation of dict continues. (I hestitate
to say *new* version, as it's just a heavy makeover for the old code -
which was basically sound).

``FancyODict`` is now a full implementation of an Ordered Dictionary,
with custom *callable sequence objects* for ``keys``, ``values``, and
``items``. These can be called like normal methods, but can also be
accessed directly as sequence objects. This includes assigning to,
indexing, and slicing - as well as all the other relevant sequence
methods. {sm;:-)}

I've also added an optional index to ``OrderedDict.popitem``.

I'm sure there are lots of ways this can be optimised for efficiency -
but the new objects have got pretty full test coverage.

You can download the new version (for testing) from `odict Beta 2
<http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=odictbeta2.py>`_

The following issues still remain :

* ``FancyOdict`` is a separate class from ``OrderedDict``.

Because this version is *undoubtably* less efficient than
OrderedDict, my current thinking is that I should leave them separate
(and have both available). Being able to operate on the
keys/values/items as sequences is for convenience only.

Anyone got a suggestion for a better name than ``FancyODict`` ?

* You can no longer access the key order directly. The old ``sequence``
attribute is depracated and will eventually go away.

You can currently alter the order (of keys, values *and* items) by
passing an iterable into those methods.

Someone has suggested that this "smells bad" - and it ought to be
done through separate `setkeys``, ``setvalues``, and ``setitems``
methods.

I'm *inclined* to agree, but I don't feel strongly about it. Anyone
else got any opinions ?

* ``repr`` ought to return a value that ``eval`` could use to turn back
into an OrderedDict.

I have actually done an implementation of this, but it would mean
that *all* the doctests need to be changed. I *will* do this at some
point.

* Slice assignment.

The semantics for slice assignment are fiddly.

For example, what do you do if in a slice assignment a key collides
with an existing key ?

My current implementation does what an ordinary dictionary does,
the new value overwrites the previous one. This means that the
dictionary can reduce in size as the assignment progresses. {sm;:?}

I think this is preferable to raising an error and preventing
assignment. It does prevent an optimisation whereby I calculate the
indexes of all the new items in advance.

It also means you can't rely on the index of a key from a slice
assignment, unless you know that there will be no key collisions.

 In general I'm *against* preventing programmers from doing things,
so long as the documentation carries an appropriate warning.

An example will probably help illustrate this :

.. raw:: html

{+coloring}

d = OrderedDict()
d[1] = 1
d[2] = 2
d[3] = 3
d[4] = 4
d.keys()
[1, 2, 3]

# fetching every other key
# using an extended slice
# this actually returns an OrderedDict
d[::2]
{1: 1, 3: 3}

# we can assign to every other key
# using an ordered dict
d[::2] = OrderedDict([(2, 9), (4, 8)])
len(d) == 4
False

d
{2: 9, 4: 8}

"""
Because of the key collisions the length of
d has changed - it now only has two keys instead
of four.
"""

   {-coloring}


> Criticism solicited (honestly) :-)
>
> We (Nicola Larosa and I) haven't yet made any optimisations - but there
> are two implementations to play with.
>
> One allows you to access the keys attribute as if it was a sequence (as
> well as a method).
>
> All the best,
> 
> Fuzzyman
>  http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-12-01 Thread Fuzzyman
Hmmm... it would be interesting to see if these tests can be used with
odict.

The odict implementation now has full functionality by the way.

Optimisations to follow and maybe a few *minor* changes.

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Why are there no ordered dictionaries?

2005-12-01 Thread Fuzzyman
> The semantics of assigning slices
> to d.keys[i:j] and d.values[i:j] are kind of tricky when the size changes
> and/or key names match or don't match in various ways, or the incoming
> data represents collapsing redundant keys that are legal sequential assignment
> overrides but change the size, etc.
>

I have come against the same problem with slice assignment, when doing
odict. :-)
Allowing the size to change prevents a useful optimisation - but I
dislike *preventing* programmers from doing things.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> 
> Regards,
> Bengt Richter

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


Re: Death to tuples!

2005-12-01 Thread Fuzzyman

Mike Meyer wrote:
> Antoon Pardon <[EMAIL PROTECTED]> writes:
> > I know what happens, I would like to know, why they made this choice.
> > One could argue that the expression for the default argument belongs
> > to the code for the function and thus should be executed at call time.
> > Not at definion time. Just as other expressions in the function are
> > not evaluated at definition time.
>
> The idiom to get a default argument evaluated at call time with the
> current behavior is:
>
> def f(arg = None):
> if arg is None:
>arg = BuildArg()
>
> What's the idiom to get a default argument evaluated at definition
> time if it were as you suggested?
>

Having default arguments evaluated at definition time certainly bites a
lot of newbies. It allows useful tricks with nested scopes though.

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

>   --
> Mike Meyer <[EMAIL PROTECTED]>
> http://www.mired.org/home/mwm/
> Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

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


Re: New Ordered Dictionery to Criticise

2005-12-02 Thread Fuzzyman
Hello Bengt,

Bengt Richter wrote:
> On 1 Dec 2005 03:38:37 -0800, "Fuzzyman" <[EMAIL PROTECTED]> wrote:
>
> >
> >Fuzzyman wrote:
> >> Sorry for this hurried message - I've done a new implementation of out
> >> ordered dict. This comes out of the discussion on this newsgroup (see
> >> blog entry for link to archive of discussion).
> >>
> >> See the latest blog entry to get at it :
> >> http://www.voidspace.org.uk/python/weblog/index.shtml
> >>
> >
> >Hello all,
> >
> >I've just done a new "beta 2" version. It has a full version of
> >FancyODict with the custome "callable sequence objects" for keys,
> >values and items. They are almost completely covered by tests.
> >
> >You can download the new(er) version from :
> >http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=odictbeta2.py
> >
> Ran my tests on it: this one may be of interest:
>  __ entrypoint: test_popitem 
> ___
>
>  def test_popitem():
>  d = CandidateDict([(k,i*100) for i,k in enumerate('abcde')])
>  >   assert d.popitem() == ('e', 400)
>
>  [C:\pywk\ut\test\test_odicts.py:228]
>  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ _
>  ...
>  ...
>  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ _
>
>  def __getattr__(self, name):
>  """
>  Implemented so that access to ``sequence`` raises a warning.
>
>  >>> d = OrderedDict()
>  >>> d.sequence
>  []
>  """
>  if name == 'sequence':
>  warn('use of sequence attribute is deprecated. Use keys method '
>  'instead.', DeprecationWarning)
>  # NOTE: Still (currently) returns a direct reference. Need to
>  #   because code that uses sequence will expect to be able to
>  #   mutate it in place.
>  return self._sequence
>  else:
>  # NOTE: strictly unnecessary, but it raises the appropriate error
>  >   getattr(self, name)
>
>  [c:\pywk\clp\odictbeta2.py:309]
>  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ _
>  Recursion detected (same locals & position)
>  
> !!!
>  = tests finished: 19 passed, 9 failed in 1.57 seconds 
> =
>

Yep the line :

getattr(self, name)

is a bug.

I've replaced it now (not yet "published") with
object.__getattr__(self, name)
It could equally just be replaced with a raise AttributeError

You've picked up on another typo in the code, whichis odd because
``popitem`` is tested.

Oh well - works now.

[snip..]
> >You can currently alter the order (of keys, values *and* items) by
> >passing an iterable into those methods.
> I'm playing this game, but I wonder how much of it really makes sense ;-)
>

Can you explain what you mean ?


> >
> >Someone has suggested that this "smells bad" - and it ought to be
> >done through separate `setkeys``, ``setvalues``, and ``setitems``
> >methods.
> >
> >I'm *inclined* to agree, but I don't feel strongly about it. Anyone
> >else got any opinions ?
> I don't see a big difference. What's important, if you ask me, is
> whether you get an idea of what will happen when you pass the iterable as
> an argument. OTTOMH that suggests that keys/values/items[slice] = iterable
> have more expectation-generating precedent, and in fact perhaps should define
> what is to happen if no other constraints are violated.

Don't completely follow.

Are you saying that

d = OrderedDict(some_iterable)
d.keys[slice] = iterable

is more *understandable*  ("expectation-generating precedent" WTF) ?

The alternative being : d.keys(iterable)

In which case I'm inclined to agree. *However* - having custom objects
for items/keys/values is undoubtably less efficient.

Therefore I'm supplying two classes OrderedDict and FancyODict (name
not yet fixed).

OrderedDict needs a way of changing the keys - so it needs either

d.keys(iterable)

*or*

d.setkeys(iterable)

Which is preferable, is my question.

I think you're saying you don't care :-)
In which case I will leave it as it presently is.

> >
> >* ``repr`` ought to return a value that ``eval`` could use to turn back
> >into an OrderedDict.
> >
> >I have actually done 

akismet 0.1.2, cgiutils 0.3.5, pathutils 0.2.3

2005-12-05 Thread Fuzzyman
Hello All,

A new release and two updates.

New akismet.py 0.1.2


Python Interface to the Akismet API
Version 0.1.2 4th December 2005
http://www.voidspace.org.uk/python/modules.shtml#akismet

`Akismet `_ is a web service for recognising
spam comments. It promises to be almost 100% effective at catching
comment spam. They say that currently 81% of all comments submitted to
them are spam.

It's designed to work with the `Wordpress Blog Tool
`_, but it's not restricted to that - so this is
a Python interface to the `Akismet API
`_.

You'll need a `Wordpress Key `_ to use it. This
script will allow you to plug akismet into any CGI script or web
application, and there are full docs in the code. It's extremely easy
to use, because the folks at akismet have implemented a nice and
straightforward {acro;REST;REpresentational State Transfer} API.

It also comes with an `example CGI
`_.

(Although the akismet feature of an "example positive" doesn't seem to
be working currently - there fault not mine :-)

You can read the full (Python) docs at :

* `akismet.py Docs
`_

Download it here :

*
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=akismet-0.1.2.zip


cgiutils 0.3.5 - pathutils 0.2.3
=

pathutils 0.2.3 November 26th 2005
cgiutils 0.3.5 November 26th 2005
http://www.voidspace.org.uk/python/recipebook.shtml#utils


These two modules contain functions and constants for *'general'* use.
They are
both included as part of the `Voidspace Pythonutils Package
`_ .
(A new release of pythonutils - containing these updated modules - is
due shortly).

**Pathutils** contains various functions for working with files and
paths. This
includes (amongst other thing) :

* Easy ways to iterate over files and directories
* A function to calculate a relative path from one location to another
* Several 'convenience' file reading/writing functions
* `py2exe `_ directory support
* A function for pretty printing file sizes
* A simple solution to cross-platform file locking
* Import from a specific location

See the `pathutils Homepage
`_.

**CGI utils** has (guess what... {sm;:?:}) various functions for use
with CGI.
It contains functions to do things that every CGI has to cope with.
They are
most useful for simple scripts, where a full blown framework would be
too
cumbersome.

It includes (amongst other thing) :

* Functions for receiving form submissions
* Cross platform functions to send emails (including creating
{acro;HTML}
  emails)
* A basic templating system
* A {acro;DNS;Domain Name System} blacklist lookup
* A function to generate a menu line for pages with lots of results

See the `cgiutils Homepage
`_.

Download them here :

*
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=utils.zip
(25k) (both modules)
*
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=pathutils.py
(19k)}
*
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=cgiutils.py
(20k)}

{small;The zip file has text versions of the docs for these two
modules.}

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


Re: how to handle two forms in cgi?

2005-12-05 Thread Fuzzyman

[EMAIL PROTECTED] wrote:
> Hi Dan,
>
> Sure. You are right. When I correct this according to your idea, it
> works now. Thank you very much. But I have second problem. When users
> run second form, other people can see adress in users' browers and know
> how to run the second form, so they don't need to run login form. How I
> can handle this case? How I can let users run login form firstly, then
> they can run second form(search form)?
>
> By the way I use python to write cgi.
>

You can use logintools to add a user authentication framework to any
CGI with very little work.

This lets you control who is able to login (whether or not new users
can sign up and you have an interface to create/invite new users).

It will also prevent any script being run unless the user is logged in.
It uses cookeis for authentication and can be added to a standard CGI
with as little as two lines of code.

It is designed for exactly the problem you have.

http://www.voidspace.org.uk/python/logintools.html

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
> Any help is appriciated!

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


Re: ElementTree - Why not part of the core?

2005-12-08 Thread Fuzzyman

Fredrik Lundh wrote:
> Steven Bethard wrote:
>
> > > ElementTree on the other hand provides incredibly easy access to XML
> > > elements and works in a more Pythonic way.  Why has the API not been
> > > included in the Python core?
> >
> > While I fully agree that ElementTree is far more Pythonic than the
> > dom-based stuff in the core, this issue has been discussed on
> > python-dev[1].  Fredrik Lundh's response:
> >
> >  shipping stable versions of ElementTree/cElementTree (or PIL, or
> >  python-doc, or exemaker, or what else you might find useful) with
> >  official Python releases is perfectly okay.
> >
> >  moving the main trunk and main development over to the Python CVS is
> >  another thing, entirely.
> >
> > I think some people were hoping that instead of adding these things to
> > the standard library, we would come up with a better package manager
> > that would make adding these things to your local library much simpler.
>
> I still hope that the standard distribution will, in a not too distant future,
> bundle more external libraries.  as things are today, "including something
> in the core" means that you have to transfer code and rights to the PSF.
>
> as I've said many times, if the Linux folks can build distributions that con-
> sists of thousands of individually maintained pieces, the Python distributors
> should be able to handle a few dozen components.
>

I'd like to add my vote in favour of this.

There are a few popular extensions that most users would like easy
access to. PIL and ElementTree both fall into this category.

Thanks

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> 

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


Re: How do I make Windows Application with Python ?

2005-01-04 Thread Fuzzyman
You need py2exe to bundle applications so they can be used on machines
without python. When you do that you have a choice of whether or not
your application should have a console box or not. In order to use
buttons and other widgets you will need to choose a GUI toolkit. I
recommend starting with Tkinter - but others would recommend wxPython.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: HTTP GET request with basic authorization?

2005-01-04 Thread Fuzzyman
There's example code with discussion at :
http://www.voidspace.org.uk/atlantibots/recipebook.html#auth
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Reaching the real world

2005-01-04 Thread Fuzzyman
I have a friend who would like to move and program lights and other
electric/electro-mechanical devices by computer. I would like to help -
and needless to say Python would be an ideal language for the
'programmers interface'.

What I'd like is an electronic interface that connects to several
relays and a python extension module to switch on and off the relays.
I've had a quick google and can't see anything too similar to what I
want. pyro (python robotics) seems to require expensive (relatively)
robotic equipment.

Does anyone know anything *similar* to what I have in mind, or have
alternative suggestions ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Embedding a restricted python interpreter

2005-01-05 Thread Fuzzyman
Fredrick Lundh (at www.effbot.org ) was working on a 'cut down python'
that only implements the bits of python he likes !! It would be great
if the core of that interpreter could be used as a 'restricted
interpreter'.

If you could externally disable os, sys, os.path modules etc  and limit
the set of modules, then you could have a useful restricted
environment. It would need a special interpreter though - so NO is the
short answer.
Regards,

Fuzzy
http://www,voidspace.org.uk/python/index.shtml

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


Re: Cookbook 2nd ed Credits

2005-01-05 Thread Fuzzyman
Hmm... I'd love to see a list... just to know if I'm on it. Permission
was sought for several of my recipes, but I don't know if any were
actually used. I'm very curious...
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: is python more popular than coldfusion?

2005-01-05 Thread Fuzzyman
Definitely !

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: How do I make Windows Application with Python ?

2005-01-05 Thread Fuzzyman
Couple of corrections - neither pypy nor starkiller are compilers.
Starkiller isn't available yet and *may* be helpful in building
compilers. Pyrex is an alternative language - a python/C hybrid that
can be compiled.

If you want to release an application then innosetup, starkit, and upx
might help - but they're not python related. You will need something
like py2exe, cx_freeze, or mcmillan installer. (Which are specific to
python - py2exe seems to be the more mature tool).

Alternatively you could consider 'Movable Python' - a frozen
distribution of python that doesn't need isntalling. See
http://sourceforge.net/projects/movpy
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Reaching the real world

2005-01-05 Thread Fuzzyman
Thank you very much (to all who replied). There;'s more than enough
here to make very good further enquiries.

Much appreciated.
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: How to make executable file ?

2005-01-05 Thread Fuzzyman
An alternative way is to use Movable Python. It's a frozen distribution
of python that can run without being 'installed'.

See http://sourceforge.net/projects/movpy

To display things in a 'window' you'll need to use a GUI toolkit like
Tkinter or wxPython.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Python Operating System???

2005-01-06 Thread Fuzzyman
The bootloader would have to be a 'python-core'. Ideally a fast
implementation of just the python syntax and language features. Now
*that* would be an excellent basis for a restricted mode python
interpreter - which could make 'python applets' closer to a reality. It
would also make python for embedded systems and embedding python in
larger programs easier as well. A purely 'core language' implementation
with no libraries.

Obviously you'd need file systems, drivers, and something to create the
functionality of the os and sys libraries. Basing it on the existing
Linux kernel would seem like a much more sensible idea

There is/was a project (Peter Hansen ?) to produce a pure python file
system. that could be an interesting component.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml



David Brown wrote:
> Hello. I recently came across a free operating system called
Unununium (or
> something like that) and it was developed in Python and Assembly.
>
> Now, I have been looking for a way to make an operating system for a
long
> long time and the only possibilities I could find were C++ and
assembly. I
> don't mind assembly so much if I don't have to use it very often. But
C++ is
> so complicated and errors are pretty much impossible to find in the
code for
> me.
>
> So, I was wondering if it would be possible to find a bootloader that
loads
> a python file at startup or something...
> 
> Is there an example somewhere of a Python OS?
> 
> Thanks!

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


Re: Contributor's List

2005-01-06 Thread Fuzzyman
My understanding is that the 2nd edition will *only* have new entries.
this may be entirely off the wall of course.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


PyCrypto 2.0, pysco 1.4 - Windows Binaries for 2.4

2005-01-12 Thread Fuzzyman
The location of the prebuilt windows installer for PyCypto 2.0 (for 
python 2.4) has changed. Apologies for any confusion, this is because of 
a website reorganisation at Voidspace.

The new location  is :
http://www.voidspace.org.uk/python/modules.shtml#pycrypto
There is also a prebuilt windows installer for psyco 1.4 (for python 
2.4). This is because there isn't yet a prebuilt binary available from 
sourceforge.
http://www.voidspace.org.uk/python/modules.shtml#psyco

Both built using the free, Microsoft, optimizing compiler. Following 
instructions from :
http://www.vrplumber.com/programming/mstoolkit/index.html

Regards,
Fuzzy
http://www.voidspace.org.uk/python/index.shtml
--
http://mail.python.org/mailman/listinfo/python-list


[Ann] PyName and downman

2005-01-12 Thread Fuzzyman
A couple of new 'modules' available from Voidspace Pythonutils.
PyName
http://www.voidspace.org.uk/python/modules.shtml#pyname
Slightly tongue in cheek, this isn't really a python module. It's three 
lists of English words containing 'py' - intended to be helpful to those 
choosing names for python projects. The word lists were produced from an 
initial file of about 8mb. Words selected all contain 'py', single words 
or hyphenated words, but no compound words.
  
* pywordlist.txt  All words contain 'py' 23kb - 1946 words
* pywordlist2.txt All words starting or ending in 'py' 16kb - 1406 words
* pywordlist3.txt All words as pywordlist2, but only words less than 10 
chars long 5kb - 658 words.

downman.py  
Version 0.2.1 14th December 2004
Simple Download Manager
http://www.voidspace.org.uk/python/cgi.shtml#downman

This is a simple download manager tool. It may be egotistical, but I 
like to know which of my projects are being downloaded (and which 
aren't). Simply make your files available in a single directory and have 
the links point to downman (see the download link for downman itself for 
an example) and downman will track the downloads. At the moment it only 
presents simple data - but all the raw data is collected to do per 
week/last month (or whatever) analysis. It will also manage links as well.

See the example output at 
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py

Regards,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Ann] Voidspace Pythonutils Website Change and Updates

2005-01-12 Thread Fuzzyman
Blinkin nora... I did... sorry. Better add a redirect *sigh*.
Thanks
Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: file uploading via urllib2 (multipart/form-data)

2005-01-14 Thread Fuzzyman

Clark C. Evans wrote:
> Hello.  I was wondering if anyone has built a module that works with
> urllib2 to upload file content via POST multipart/form-data. I'm
> aware of ASPN 146306, however, I need to use urllib2 beacuse I'm
> using HTTP Digest over SSL.
>
> Cheers,
>
> Clark

There is an example showing exactly that over at voidspace. I think
it's on the cgi page, as it is a companion to the cgi demo showing how
to receive file uploads.

Try : http://www.voidspace.org.uk/python/cgi.shtml
Regards,

Fuzzy
http://www.voidspac.org.uk/python/index.shtml

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


Re: how to stop google from messing Python code

2005-01-14 Thread Fuzzyman

Xah Lee wrote:
> gmane is great! its renaming of newsgroups is quite a headache.
> i found that comp.lang.python corresponds to
gmane.comp.python.general.
> do you know which one corresponds to comp.lang.perl.misc?
> there's no .misc or .general...
>
> --
> i thought there a strick like preceding a line by -- or something
that
> prevents google from reformating the post.
> Xah
>  [EMAIL PROTECTED]
>  http://xahlee.org/PageTwo_dir/more.html

I guess that most people use google to post to newsgroups is that they
don't have nntp access. Telling htem to use a newsreader is facetious
and unhelpful.

Google strips leading whitespace. Putting *anything* before indentation
stops the formatting getting messed up. It doesn't stop long lines
being wrapped of course.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: huygens lands on titan

2005-01-14 Thread Fuzzyman

John Thingstad wrote:
> --
> huygens lands on titan
> Using M2, Opera's revolutionary e-mail client:
http://www.opera.com/m2/

I bet it didn't...
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: how to stop google from messing Python code

2005-01-17 Thread Fuzzyman

Fredrik Lundh wrote:
> Fuzzyman wrote:
>
> > I guess that most people use google to post to newsgroups is that
they
> > don't have nntp access. Telling htem to use a newsreader is
facetious
> > and unhelpful.
>
> if you have internet access, you have NNTP access.  gmane.org
provides access
> to more than 6,500 mailing lists via NNTP, including all relevant
Python forums.
>

Not if you're behind a censoring proxy that blocks everything except
http. This is a situation many people find themselves in.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

> 

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


Re: Executing a script created by the end user

2005-01-17 Thread Fuzzyman
compile and eval is a good way to go.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Help on project, anyone?

2005-01-24 Thread Fuzzyman
Hello Chap,

I work on various projects. Several of them would *greatly* benefit
from input from another programmer. You can see them at :

http://www.voidspace.org.uk/python/index.shtml

Specifically, I have three projects that I'm looking for someone to
work on, but they are all on the 'small' scale. I couldn't tell whether
you would be happy with that, or if you wanted to join a larger team.

I have listed them in order of difficulty (easiest first). With all of
them I would work with you or offer whatever level of support you want.


1) My dateutils module is out of date and needs work on it.
http://www.voidspace.org.uk/python/modules.shtml#dateutils [1]

2) I need an online bookmarks manager. This is a CGI script that will
allow you to keep/manage an online bookmarks page. [2]

3) Simple Version Control program for single programmer. A very simple
way of doing version control/releases for small projects with only a
single programmer. [3]

If any of these interest you then please contact me - fuzzyman _AT_
voidspace _DOT_ org _DOT_ uk (in preference to my gmail account).

Whatever you decide to do, good luck with your pythoneering.

Regards,


Fuzzyman

[1] Several of the functions shadow functions in the standard library
calender.py. Some of the return values are in illogical orders and a
couple don't behave *exactly* as documented (when adding months to a
date that is at the end of a month). Basically it's in need of an
update/clean up. It is incorporated into a couple of other projects -
and it works fine for those, so *I* don't need it cleaned up. However,
it's one of my most popular downloads - so it's obviously something
people want and would appreciate an updated version.

[2] I work in several locations and really *need* a single bookmarks
repository. I have a clear idea of what I would like *and* how to do
ti. I just don't have the time to work on it. None of the existing
perl/php ones I explored did quite what I hoped. The advantage of this
project is that you could start simple and just incrementally add
features. You could have something working *very* quickly. Basically
phase 1 - a simple bookmark manager with add/delete links. Phase 2 -
parse IE/Firefox/opera bookmark files and check for duplicates
(including sections). Phase 3 - multiple users, client prorgram with
automatic synchronization. (plus lots more)

[3] I think lots of people would find this useful. A version control
system for projects where CVS/Subversion is overkill. This would be
based on DirWatcher/FSDM (
http://www.voidspace.org.uk/python/programs.shtml#dirwatcher ) - All
the code for finding which files have changed is already there, and
there is an existing Tkinter GUI for Dirwatcher.

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


Re: What's so funny? WAS Re: rotor replacement

2005-01-24 Thread Fuzzyman
I also feel the lack of a standard cryptography module in the core...
even a *basic* one. At least rotor provided that, before it was
deprecated. I (along with many other python users) write CGIs where the
only extension modules that I can use are either pure python, or ones
my web hoster is willing to install. Luckily my hoster will install
modules without too much fuss - others aren't so lucky. Cryptography is
a pretty 'standard' requirement these days.. and IMHO ought to be in
the 'standard library'.

Without commenting (or reading properly) on this exchange... it does
seem that many of ''s contributions have been very bad tempered
recently. Hmmm.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Py2.4 .exe installer

2005-01-24 Thread Fuzzyman
I built Movable Python for use on a windows box where I didn't have
admin rights.

See :

http://sourceforge.net/projects/movpy
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


urllib2 and proxy question

2005-01-24 Thread Fuzzyman
urllib2 (under windows) will auto-detect your proxy settings and use
those.

Normally that's a good thing (I guess), except when it's not !

How do I switch off this behaviour ? I'm behind a censoring proxy and
wanting to test things *locally*. IE is set to not use the proxy when
fetching local adresses, but urllib2 ignores that part of the setting
and uses the proxy for everything.

The only way I can test are changing my IE settings back and forth
every time. Most annoying.

I can see how to *add* a new proxy to urllib2, but not how to force it
to not use a proxy. I may well be missing something obvious though.
Anyone able to help ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: urllib2 and proxy question

2005-01-24 Thread Fuzzyman

rbt wrote:
> Fuzzyman wrote:
> > urllib2 (under windows) will auto-detect your proxy settings and
use
> > those.
> >
> > Normally that's a good thing (I guess), except when it's not !
> >
> > How do I switch off this behaviour ? I'm behind a censoring proxy
and
> > wanting to test things *locally*. IE is set to not use the proxy
when
> > fetching local adresses, but urllib2 ignores that part of the
setting
> > and uses the proxy for everything.
> >
> > The only way I can test are changing my IE settings back and forth
> > every time. Most annoying.
> >
> > I can see how to *add* a new proxy to urllib2, but not how to force
it
> > to not use a proxy. I may well be missing something obvious though.
> > Anyone able to help ?
> > Regards,
> >
> > Fuzzy
> > http://www.voidspace.org.uk/python/index.shtml
> >
>
> "Alternatively, the optional proxies argument may be used to
explicitly
> specify proxies.
> It must be a dictionary mapping scheme names to proxy URLs, where an
> empty dictionary causes no proxies to be used"
>
> # Don't use any proxies
> filehandle = urllib.urlopen(some_url, proxies={})

Wikkid... I'll try that. Nice one, thanks for your help.
It *still* means I have to have a different version for testing locally
- but it's better than the alternative.
Regards, 


Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Help on project, anyone?

2005-01-25 Thread Fuzzyman

Miki Tebeka wrote:
> Hello Fuzzyman,
>
> > 3) Simple Version Control program for single programmer. A very
simple
> > way of doing version control/releases for small projects with only
a
> > single programmer. [3]
> Subversion (and CVS) are dead simple to install and use.

I've heard *lots* of people say exactly the opposite.

> IMO in the long run you'll find yourself implementing most of their
> features anyway.
>
> > [3] I think lots of people would find this useful. A version
control
> > system for projects where CVS/Subversion is overkill. This would be
> > based on DirWatcher/FSDM (
> > http://www.voidspace.org.uk/python/programs.shtml#dirwatcher ) -
All
> > the code for finding which files have changed is already there, and
> > there is an existing Tkinter GUI for Dirwatcher.
> Adding changes to version control should be done as an explicit
action by
> the developer. Anything else is on the road to disaster, you'll find
> yourself spending too much time backing out of changes you didn't
want in.

Yeah, my idea is pretty flexible. You could snapshot a 'release state',
and roll back changes on individual files in between releases. You
basically maintain it on your file system in the normal way and keep an
archive of releases/changes.

I think this probably works well with the may most small projects are
actually managed.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

>
> Bye.
> --
>

> Miki Tebeka <[EMAIL PROTECTED]>
> http://tebeka.bizhat.com
> The only difference between children and adults is the price of the
toys

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Fuzzyman
An implementation of the core language semantics - without any modules
or file operations would be dead useful.

It could replace some of the function of the long dead rexec modules as
well as support projects like this.
Regards,


Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: how to ncurses on win32 platform

2005-01-25 Thread Fuzzyman

Tim Golden wrote:
> [Jorgen Grahn]
> | [Alan Gauld ]
> | > You can use ncurses via cygwin.
> | > There are DOS ports too but I couldn't get any of them to
> | > work on my XP box, YMMV...
> |
> | Or, as Alex Martelli wrote in "Python in a nutshell":
> |
> |"The curses package works only on Unix-like platforms
> | (there are persis-
> |tent rumors of Windows ports of it, but I've never found a
> | working one)."
>
> This is the only one I've seen which claims
> (at least partial) compatibility. I've looked
> it over, but never had a chance to try it out:
>
> http://flangy.com/dev/python/curses/
>
> TJG

It's a shame there isn't (as far as I can see) a source distribution,
or a 2.4 binary.

It works very well for the parts implemented.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
>
>

> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a
proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
>


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


snakespell and myspell

2005-01-25 Thread Fuzzyman
I'm looking to implement a plugin spell checker.

I'm probably going to go with PyEnchant, as it looks to be the most
promising currently maintained spell checker.

I just wondered if anyone knew what happened to snakespell and myspell.
Both seem to have dissapeared from the net. People have reported good
results from both - and it seems a shame to lose them.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: What's so funny? WAS Re: rotor replacement

2005-01-25 Thread Fuzzyman
I've already downloaded p3 - thanks :-)

I wonder how long it took (in reality) an average hacker to break the
algorithm used by rotor ?
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Fuzzyman

Nick Coghlan wrote:
> Fuzzyman wrote:
> > An implementation of the core language semantics - without any
modules
> > or file operations would be dead useful.
> >
> > It could replace some of the function of the long dead rexec
modules as
> > well as support projects like this.
>
> Securing a custom build of the CPython interpreter would probably be
> significantly easier than designing a 'secure mode' that ran on top
of the
> standard version. The former might even be a stepping stone towards
the latter.
>
> Still not easy though (the main task would be to prevent Python code
from
> accessing the OS, while still allowing module imports to work).

Pure python imports only... no C extensions.

Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
> ---
>  http://boredomandlaziness.skystorm.net

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


Re: Another scripting language implemented into Python itself?

2005-01-25 Thread Fuzzyman

Cameron Laird wrote:
[snip..]
> This is a serious issue.
>
> It's also one that brings Tcl, mentioned several
> times in this thread, back into focus.  Tcl presents
> the notion of "safe interpreter", that is, a sub-
> ordinate virtual machine which can interpret only
> specific commands.  It's a thrillingly powerful and
> correct solution to the main problem Jeff and others
> have described.

A better (and of course *vastly* more powerful but unfortunately only a
dream ;-) is a similarly limited python virutal machine.

It could make embedding python a lot simpler for lots of applications
and even 'embedded python' a lot simpler. (Not to mention 'restricted
execution' - e.g. for applets in web pages)

*Perhaps* the pypy core will be a bit like this - but it's design goals
are very different of course.

Anyway, little point in wishing on a dream - I'm certainly not up to
the job :-)
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: snakespell and myspell

2005-01-26 Thread Fuzzyman

Jarek Zgoda wrote:
> Fuzzyman wrote:
>
> > I'm looking to implement a plugin spell checker.
> >
> > I'm probably going to go with PyEnchant, as it looks to be the most
> > promising currently maintained spell checker.
> >
> > I just wondered if anyone knew what happened to snakespell and
myspell.
> > Both seem to have dissapeared from the net. People have reported
good
> > results from both - and it seems a shame to lose them.
>
> Well, myspell-python is no longer maintained, original author
resigned
> some time ago and I didn't found anybody who would like to take
> responsibility on this package. I provide myspell-1.0 download from
my
> project page at BerliOS (http://developer.berlios.de/projects/jpa/),
but
> I do not maintain this package.
>
> If you look for spell-checking library, I'd consider using python
> binding for aspell, available at
> http://www.republika.pl/wmula/proj/aspell-python/ (currently I'm
> rewriting my program to use python-aspell). This library is actively
> maintained and Wojtek Mula is active member of Polish Python
community.
>

The problem with aspell is (as far as I can see anyway) that the
library you mention is aimed at aspell 0.50.5 or the up to date 0.60
series. aspell for windows is currently only at 0.50.3.

Hmmm I think I'll explore PyEnchant for the moment. I need to see
how easy it is to add words to a user dictionary.

Regards,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> --
> Jarek Zgoda
> http://jpa.berlios.de/ | http://www.zgodowie.org/

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


Re: python without OO

2005-01-26 Thread Fuzzyman
It's perfectly possible to write good python code without using
classes. (and using functions/normal control flow).

You will have a problem with terrminology though - in python everything
is an object (more or less). Common operations use attributes and
methods of standard objects.

For example :

> somestring = 'fish'
> if somestring.startswith('f'):
> print 'It does'

The above example uses the 'startswith' method of all string objects.

Creating your own 'classes' of objects, with methods and attributes, is
just as useful.

You can certainly use/learn python without having to understand object
oreinted programming straight away. On the other hand, Python's object
model is so simple/useful that you *will* want to use it.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Please suggest on the book to follow

2005-01-27 Thread Fuzzyman
We've only just had Python 2.4. Based on previous experience that means
it will be about 18 months before python 2.5.

I learned to program from 'Programming Python'. Particularly the stuff
on Tkinter is very helpful. I don't think you'll have much to
'unlearn', although obviously there is stuff it doesn't cover (like new
style classes).
Regards,


Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


[ANN] Movable Python, linky and Techie Blog

2005-01-27 Thread fuzzyman
Minor news first :

'linky' a local link checker is available.
http://www.voidspace.org.uk/python/programs.shtml#linky

linky will check your website for dead links (within the website) as
well as comparing it to the website on your filesystem, to check for
case errors that might not be picked up if you test your website on
windows. It can also report files that don't appear to be linked to -
for finding  redundant images etc.

linky uses BeautifulSoup to do the hard work.


The Voidspace Techie Blog has moved. My (mainly python related blog)
now lives at :
http://www.voidspace.org.uk/python/weblog/index.shtml
It is created using firedrop - the excellent blog tool by Hans Nowak

MOVABLE PYTHON
http://www.voidspace.org.uk/python/movpy
http://sourceforge.net/projects/movpy

Version 0.4.5 is now available, hurrah.

There are now prebuilt distributions for Python 2.2, 2.3, *and* 2.4.

This is a bugifx/update release. The distributions it produces are very
*similar* to version 0.4.4 distributions, but there are a couple of
issues resolved. See
http://www.voidspace.org.uk/python/movpy/changelog.html for details.

*Most* of the changes relate to the PyDistFrreeze.py in the 'source'
package. This is the code that creates the frozen distributions. There
have been several simplifications and improvements. Again, see the
CHANGELOG for details.


Version 0.5.0

Bruno Thoorens has provided me with the code for the GUI for
PyDistFreeze.py When I have integrated it with PyDistFreeze.py it will
form the 0.5.0 release. This should be in the next couple of weeks time
permitting. The GUI is *excellent* :-)


Movable Python is a Python runtime that can run scripts without the
need for Python to be installed. With the inclusion of wxPython and SPE
editor it is a portable (movable) development environment. Also useful
for testing scripts with several different python versions. The source
version will build frozen environments (using py2exe - so Windoze only
currently), this can include whichever extension modules/packages you
choose.
Regards,

Michael Foord
http://www.voidspace.org.uk/python/index.shtml

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


Re: urllib2 and proxy question

2005-01-28 Thread Fuzzyman

rbt wrote:
> Fuzzyman wrote:
> > urllib2 (under windows) will auto-detect your proxy settings and
use
> > those.
> >
> > Normally that's a good thing (I guess), except when it's not !
> >
> > How do I switch off this behaviour ? I'm behind a censoring proxy
and
> > wanting to test things *locally*. IE is set to not use the proxy
when
> > fetching local adresses, but urllib2 ignores that part of the
setting
> > and uses the proxy for everything.
> >
> > The only way I can test are changing my IE settings back and forth
> > every time. Most annoying.
> >
> > I can see how to *add* a new proxy to urllib2, but not how to force
it
> > to not use a proxy. I may well be missing something obvious though.
> > Anyone able to help ?
> > Regards,
> >
> > Fuzzy
> > http://www.voidspace.org.uk/python/index.shtml
> >
>
> "Alternatively, the optional proxies argument may be used to
explicitly
> specify proxies.
> It must be a dictionary mapping scheme names to proxy URLs, where an
> empty dictionary causes no proxies to be used"
>
> # Don't use any proxies
> filehandle = urllib.urlopen(some_url, proxies={})

Rats.. this answer is for urllib - *NOT* urllib2 !
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: urllib and proxy

2005-01-28 Thread Fuzzyman
See :
http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/f1ba0de2c739127c/f694e00b1253da1e

For urllib you can pass in the 'proxies={}' keyword to the urlopen
function. This disables proxy use.

Unfortunately it *doesn't* work for urllib2 which is where I need it.
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: urllib2 and proxy question

2005-01-28 Thread Fuzzyman

rbt wrote:
> Fuzzyman wrote:
> > urllib2 (under windows) will auto-detect your proxy settings and
use
> > those.
> >
> > Normally that's a good thing (I guess), except when it's not !
> >
> > How do I switch off this behaviour ? I'm behind a censoring proxy
and
> > wanting to test things *locally*. IE is set to not use the proxy
when
> > fetching local adresses, but urllib2 ignores that part of the
setting
> > and uses the proxy for everything.
> >
> > The only way I can test are changing my IE settings back and forth
> > every time. Most annoying.
> >
> > I can see how to *add* a new proxy to urllib2, but not how to force
it
> > to not use a proxy. I may well be missing something obvious though.
> > Anyone able to help ?
> > Regards,
> >
> > Fuzzy
> > http://www.voidspace.org.uk/python/index.shtml
> >
>
> "Alternatively, the optional proxies argument may be used to
explicitly
> specify proxies.
> It must be a dictionary mapping scheme names to proxy URLs, where an
> empty dictionary causes no proxies to be used"
>
> # Don't use any proxies
> filehandle = urllib.urlopen(some_url, proxies={})

The correct equivalent for urllib2 (in answer to my question !) is :

>>> proxy_support = urllib2.ProxyHandler({})
>>> opener = urllib2.build_opener(proxy_support)
>>> urllib2.install_opener(opener)

which is slightly more complicated but does exactly the same job !
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: limited python virtual machine (WAS: Another scripting language implemented into Python itself?)

2005-01-28 Thread Fuzzyman

Dieter Maurer wrote:
> Steven Bethard <[EMAIL PROTECTED]> writes on Tue, 25 Jan 2005
12:22:13 -0700:
> > Fuzzyman wrote:
> > ...
> >  > A better (and of course *vastly* more powerful but unfortunately
only
> >  > a dream ;-) is a similarly limited python virutal machine.
>
> I already wrote about the "RestrictedPython" which is part of Zope,
> didn't I?
>

Not in this thread.

> Please search the archive to find a description...
>

Interesting. I'd be interested in whether it requires a full Zope
install and how easy (or otherwise) it is to setup. I'll investigate.

Regards,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

> 
> Dieter

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


Re: Who should security issues be reported to?

2005-01-28 Thread Fuzzyman

[EMAIL PROTECTED] wrote:
> Aahz wrote:
> > In article <[EMAIL PROTECTED]>,
> >  <[EMAIL PROTECTED]> wrote:
> > >
> > >Who are the appropriate people to report security problems to in
> > >respect of a module included with the Python distribution?  I
don't
> > >feel it appropriate to be reporting it on general mailing lists.
> >
> > There is no generally appropriate non-public mechanism for
reporting
> > security issues.  If you really think this needs to be handled
> > privately, do some research to find out which core developer is
most
> > likely to be familiar with it.  Even before you do that, check
> > SourceForge to find out whether anyone else has reported it as a
bug.
>
> I find this response a bit dissappointing frankly. Open Source people
> make
> such a big deal about having lots of people being able to look at
> source
> code and from that discover security problems, thus making it somehow
> making it better than proprietary source code. From what I can see,
if
> an
> Open Source project is quite large with lots of people involved, it
> makes it
> very hard to try and identify who you should report something to when
> there is no clearly identifiable single point of contact for security
> related

The sourceforge bug tracker *is* the single right place to post such
issues. The py-dev mailing list would be a second *useful* place to
post such a comment, although not really the right place. The OP seemed
to want an individual with whom he could have a private conversation
about it.

Regards,


Fuzzy
http://www.voidspace.org.uk/python/index.shtml

> issues. Why should I have to go through hoops to try and track down
who
> is appropriate to send it to? All you need is a single advertised
email
> address
> for security issues which is forwarded onto a small group of
developers
> who can then evaluate the issue and forward it on to the appropriate
> person.
> Such developers could probably do such evaluation in minutes, yet I
> have
> to spend a lot longer trying to research who to send it to and then
> potentially
> wait days for some obscure person mentioned in the source code who
has
> not touched it in years to respond, if at all. Meanwhile you have a
> potentially
> severe security hole sitting there wating for someone to expliot,
with
> the
> only saving grace being the low relative numbers of users who may be
> using
> it in the insecure manner and that it would be hard to identify the
> actual web
> sites which suffer the problem.
>
> I'm sorry, but this isn't really good enough. If Open Source wants to
> say that
> they are better than these proprietary companies, they need to deal
> with these
> sorts of things more professionally and establish decent channels of
> communications for dealing with it.
>
> And yes I have tried mailing the only people mentioned in the module
in
> question and am still waiting for a response.

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


Re: Help with web dashboard

2005-01-28 Thread Fuzzyman
Ifd you want to use standard CGI I've written a CGI user
authentication/management module called logintools.

See http://www.voidspace.org.uk/python/logintools.html
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Help with web dashboard

2005-01-29 Thread Fuzzyman

Chris wrote:
> In article <[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] says...
> > Ifd you want to use standard CGI I've written a CGI user
> > authentication/management module called logintools.
> >
>
> Would this be preferred (or easier) than using an application server
> (ie. Zope or Webware)?
>
> If possible, I think it would be nice if the security aspect of it
was
> already built-in so I would not need to write/test it myself.
>
> Thanks for your help.


For simple applications, writing CGIs is going to be quite a lot easier
than using something like Zope. If your final product is big and
complex then CGIs probably aren't suitable anyway.

logintools is a module providing user authentication/administration and
user management specifically for CGIs.
Regards,


Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


Re: Forcing interactive interpreter without (-i)

2005-02-01 Thread Fuzzyman
In Movable Python I use IPython and code.InteractiveConsole to provide
interactive sessions.

See the file 'movpy.py' in the source distribution to see the code.
Note that to get IPython working with py2exe you must effectively do an
explicit `import site`.

>def interactive(localvars=None):
>"""A very simple function to embed an interactive interpreter into
movpy."""
# could have the banner passed in as an optional argument, plus
maybe the IPython config file location
>IPShellEmbed = None
>try:
>from IPython.Shell import IPShellEmbed
>except ImportError:
>pass

>if not IPShellEmbed or IPOFF:
>if localvars == None:
>localvars = sys._getframe(0).f_back.f_locals#
extract locals from the calling frame - taken from IPython
>from code import InteractiveConsole
>con = InteractiveConsole(localvars)
>con.interact()
>else:
>banner = 'Movable Python\nIPython Interactive Shell. See the
manual for a list of features and tips.\nCtrl-D to exit.'
>argv = ['-ipythondir', libdir]  # where to find
the ipython config file
>ipshell = IPShellEmbed(argv, banner=banner)
>ipshell()

http://sourceforge.net/projects/movpy
Regards,

Fuzzy
http://www.voidspace.org.uk/python/index.shtml

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


  1   2   3   4   5   6   7   8   9   >