how to check whether a drive is a network drive or drive from attached hard-disk
Hi, Few very simple questions. Is there a way to detect whether a drive is a mapped network drive or not in Windows? Also, how can I get a list of drive letters currently in use in the system? Your help is highly appreciated. Thanks in advance. With regards, -Shailesh -- http://mail.python.org/mailman/listinfo/python-list
Creating a custom python python distribution
Hi, I wish to create a Python distribution includind Python and some other libraries (Zope 3, PyWin32, numpy, lxml, etc.) which are required for my applications. e.g. there are Enthough and ASPN distributions of Python. Unfortunately, I have not been able to find the right documentation for this purpose. Could some one give an overview of what needs to be done for this purpose? With regards, -Shailesh -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a custom python python distribution
Thanx a lot for all the pointers. I will certainly check into them. I actually wanted to know how do people create their own Python distribution like ASPN's Python or Enthought's Python. With regards, - Shailesh On Oct 2, 12:33 pm, azrael <[EMAIL PROTECTED]> wrote: > Maybe you should check the Slax distro. Go towww.slax.org. > There is one special slax distro caled Frodo. I think that it includes > nearly nothing but the core. > There are also several packages for the distro that you can put inside > the distro and create your own distribution. There are also detailed > instructions. This way you can create a Live distro, but there are > also instruction on how to install it on the HDD. > > If I understood your question then I guess that this should be the > answer. > > best regards -- http://mail.python.org/mailman/listinfo/python-list
problem with gethostbyaddr with intranet addresses on MAC
Hi,
I am facing a peculiar problem. socket.gethostbyaddr is not working
fine on my MAC for ip addresses on the LAN. The LAN happens to consist
of linux and windows machines and this is the only one MAC on the
LAN.
Please see the example below. I am getting error: socket.herror: (1,
'Unknown host')
apples-computer:~ apple$ ping 192.168.4.123
PING 192.168.4.123 (192.168.4.123): 56 data bytes
64 bytes from 192.168.4.123: icmp_seq=0 ttl=64 time=0.328 ms
64 bytes from 192.168.4.123: icmp_seq=1 ttl=64 time=0.236 ms
64 bytes from 192.168.4.123: icmp_seq=2 ttl=64 time=0.255 ms
^C
--- 192.168.4.123 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.236/0.273/0.328/0.040 ms
apples-computer:~ apple$ python2.4
Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from socket import *
>>> x = gethostbyname('google.com')
>>> x
'64.233.167.99'
>>> gethostbyaddr(x)
('py-in-f99.google.com', [], ['64.233.167.99'])
>>> e = '192.168.4.123'
>>> gethostbyaddr(e)
Traceback (most recent call last):
File "", line 1, in ?
socket.herror: (1, 'Unknown host')
>>>
With regards,
- Shailesh
--
http://mail.python.org/mailman/listinfo/python-list
Wrapping methods of built-in dict
Hello,
I'm trying to write a class decorator which takes a function as an
argument and wraps instancemethods of the class with the function.
After reading a few examples on ActiveState and this blog post , my first attempt goes something like
this:
def tracing_wrapper(fn):
import functools
@functools.wraps(fn)
def wrapped(*args, **kwargs):
print "invoking %s(%s, %s)" % (fn.__name__, args, kwargs)
return fn(*args, **kwargs)
return wrapped
def factory(wrapper_fn):
def class_wrapper(klass):
import inspect
for _, method in inspect.getmembers(klass, inspect.ismethod):
setattr(klass, method.__name__, wrapper_fn(method))
for _, fn in inspect.getmembers(klass, inspect.isfunction):
setattr(klass, fn.__name__, staticmethod(wrapper_fn(fn)))
return klass
return class_wrapper
@factory(tracing_wrapper)
class MyObject(object):
def a(self):
print "a"
@factory(tracing_wrapper)
class MyDict(dict):
pass
>>> a = MyObject()
>>> a.a()
invoking a((<__main__.MyObject object at 0xb7bb5bcc>,), {})
a
Naturally, when wrapping the built-in dict type, I don't get the
expected results.
>>> md = MyDict()
>>> md['hello'] = 1
>>> md.get('hello')
1
The reason as far as I understand is that the methods on the built-in
dict are not of MethodType or FunctionType so they are not included in
the result of the inspect.getmembers call and are not wrapped.
Here I'm stuck, unsure how to fix this. Could anyone suggest a way to
wrap the methods of the built-in types? This recipe for generalized proxies seems
promising, but I'm not sure how to adapt it for use here.
Thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping methods of built-in dict
On May 20, 7:31 pm, Steven D'Aprano
wrote:
> On Wed, 20 May 2009 18:42:38 -0700, shailesh wrote:
> > The reason as far as I understand is that the methods on the built-in
> > dict are not of MethodType or FunctionType
>
> That seems to be true:
>
> >>> type({}.get)
>
>
>>> type(dict.get>
>
>
> > so they are not included in
> > the result of the inspect.getmembers call and are not wrapped.
>
> But that isn't:
>
> >>> zip(*inspect.getmembers(dict))[0] # extract the names only
>
> ('__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__',
> '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__',
> '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__',
> '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
> '__setattr__', '__setitem__', '__str__', 'clear', 'copy', 'fromkeys',
> 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys',
> 'pop', 'popitem', 'setdefault', 'update', 'values')
>
> So the problem isn't directly with getmembers, but with the predicate
> functions you have passed to it (inspect.isfunction and inspect.method).
> Try inspect.ismethoddescriptor instead.
Thanks for that. Between ismethod, isfunction, ismethoddescriptor and
isbuiltin I think I can cover all the types needed for wrapping
classes.
I began writing an equivalent version for wrapping objects instead of
classes. The problem I run into is that there isn't a predicate for
some methods of dict instances
>>> all = set([ name for (name, method) in inspect.getmembers({}) ])# get
>>> all the methods
>>> builtin = set([ name for (name, method) in inspect.getmembers({},
>>> inspect.isbuiltin) ]) # get the builtin methods
>>> for m in all.difference(builtin):# print the types of what's left over
... print m, type(getattr({}, m))
...
__ne__
__setattr__
__hash__
__delitem__
__str__
__getattribute__
__class__
__cmp__
__delattr__
__iter__
__le__
__len__
__gt__
__setitem__
__lt__
__ge__
__eq__
__doc__
__init__
__repr__
>>> [ attr for attr in dir(inspect) if attr.startswith('is') ] # list of
>>> predicates supported by inspect
['isabstract', 'isbuiltin', 'isclass', 'iscode', 'isdatadescriptor',
'isframe', 'isfunction', 'isgenerator', 'isgeneratorfunction',
'isgetsetdescriptor', 'ismemberdescriptor', 'ismethod',
'ismethoddescriptor', 'ismodule', 'isroutine', 'istraceback']
>>> inspect.getmembers({}, inspect.ismethod)
[]
>>> inspect.getmembers({}, inspect.isfunction)
[]
>>> inspect.getmembers({}, inspect.ismemthoddescriptor)
[]
There doesn't seem to be a predicate returning method wrappers. Is
there an alternate way to query an object for attributes that are of
method wrappers?
This exercise also makes me question if I'm going about this
correctly. If I want to add functionality to the methods of a class or
an object are decorators and the inspect module the pythonic way to go
about it? I can think of alternative implementations either through
metaclasses or proxy objects.
Thanks again.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping methods of built-in dict
On May 21, 10:13 pm, George Sakkis wrote:
> On May 21, 5:55 pm, shailesh wrote:
>
> > There doesn't seem to be a predicate returning method wrappers. Is
> > there an alternate way to query an object for attributes that are of
> > method wrappers?
>
> Sure:>>> MethodWrapper = type({}.__init__)
> >>> isinstance([].__len__, MethodWrapper)
>
> True
>
> But you're better off catching everything by checking with callable()
> (or equivalently hasattr(obj, '__call__')).
>
> > This exercise also makes me question if I'm going about this
> > correctly. If I want to add functionality to the methods of a class or
> > an object are decorators and the inspect module the pythonic way to go
> > about it? I can think of alternative implementations either through
> > metaclasses or proxy objects.
>
> In my experience, it's quite unlikely to really want to decorate
> indiscriminately *all* methods of a class/instance, let alone all the
> special methods (e.g. __getattribute__ very rarely needs to be
> overridden). Do you have an actual use case or are you just playing
> around ?
The use case I'm exploring is automatic lock acquisition and release.
I've been trying to create a decorator which protects objects against
concurrent modification by placing all attribute behind a mutex. More
fine grained locking will probably perform better, but the convenience
and reliability of auto-locking is nice. Suggestions for alternate
implementations are most welcome.
- Shailesh
--
http://mail.python.org/mailman/listinfo/python-list
Re: httplib incredibly slow :-(
Yes it includes libcurl. I didn't have to install it separately. I still continue to use Python 2.4. So cannot say about Python 2.6. - Shailesh On Wed, Aug 12, 2009 at 10:23 PM, Chris Withers wrote: > shaileshkumar wrote: > >> We use PyCURL on Windows. http://pycurl.sourceforge.net/ provides pre- >> built versions for Windows and it works out of the box. >> > > Does it include libcurl? Are these builds available for Python 2.6? > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > - http://www.simplistix.co.uk > -- http://mail.python.org/mailman/listinfo/python-list
