Listing modules from all installed packages

2013-06-08 Thread Julien Phalip
Hi,

I'm trying to write a function that programmatically obtains and returns the 
exact location of all first-level modules for all installed packages.

For example, if the packages named 'django' and 'django-debug-toolbar' are 
installed, I'd like this function to return something like:
>>> installed_modules()
/Users/my_user/.virtualenvs/my_venv/lib/python2.6/site-packages/django
/Users/my_user/.virtualenvs/my_venv/src/debug_toolbar

That is, this function needs to consider all installed packages, including 
those that have been installed in "edit" mode (i.e. in the src/ folder). Note 
also that the main module for the 'django-debug-toolbar' is in fact named 
'debug_toolbar'.

So far the closest I've been to retrieving the list of first-level modules is 
as follows:

import os
import pkg_resources
import setuptools

pkgs = set()

for dist in pkg_resources.working_set:
if os.path.isdir(dist.location):
for pkg in setuptools.find_packages(dist.location):
if '.' not in pkg:
pkgs.add(pkg)

The idea is then to loop through that list of modules, import them and get 
their exact locations by fetching their __file__ attribute values.

However, this feels very hackish and I don't think it's actually quite correct 
either. I'm sure there must be a better way. If possible I'd also like to avoid 
having to use setuptools.

Do you have any tips on how to achieve this?

Many thanks!

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


Re: Listing modules from all installed packages

2013-06-14 Thread Julien Phalip
On Saturday, June 8, 2013 11:22:16 PM UTC-7, Carlos Nepomuceno wrote:
> Just realized that you've asked for installed packages. Perhaps the following 
> will do the trick. I don't know why the 'lib-tk' isn't included. Why not?
> 
> toplevel_packages = ['%s\\%s'%(ml.path,name)for ml,name,ispkg in 
> pkgutil.iter_modules() if ispkg]
> print '\n'.join(toplevel_packages)

Thanks a lot Carlos, this gives me exactly what I needed!

Best wishes,

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


Preserving unicode filename encoding

2012-10-20 Thread Julien Phalip
Hi,

I've noticed that the encoding of non-ascii filenames can be inconsistent 
between platforms when using the built-in open() function to create files.

For example, on a Ubuntu 10.04.4 LTS box, the character u'ş' (u'\u015f') gets 
encoded as u'ş' (u's\u0327'). Note how the two characters look exactly the 
same but are encoded differently. The original character uses only one code 
(u'\u015f'), but the resulting character that is saved on the file system will 
be made of a combination of two codes: the letter 's' followed by a diacritical 
cedilla (u's\u0327'). (You can learn more about diacritics in [1]). On the Mac, 
however, the original encoding is always preserved.

This issue was also discussed in a blog post by Ned Batchelder [2]. One 
suggested approach is to normalize the filename, however this could result in 
loss of information (what if, for example, the original filename did contain 
combining diacritics and we wanted to preserve them).

Ideally, it would be preferable to preserve the original encoding. Is that 
possible or is that completely out of Python's control?

Thanks a lot,

Julien

[1] http://en.wikipedia.org/wiki/Combining_diacritic#Unicode_ranges
[2] http://nedbatchelder.com/blog/201106/filenames_with_accents.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem connecting to SMTP/IMAP server using SSL

2012-04-11 Thread Julien Phalip
Hi Michael,

Thanks again for your reply. I've tried using SMTP with TLS. And again it works 
with the VPN turned on but it still won't work with the VPN turned off. For 
some reason I don't understand, it simply won't instantiate the 
SMTP/SMTP_SSL/IMAP4/IMAP4_SSL objects at all and will hang forever if the VPN 
is turned off.

I'm really at loss there :)

Julien

On Apr 2, 2012, at 6:57 PM, Michael Hrivnak wrote:

> Your phone may be using TLS on the normal IMAP port (143).  Or, are
> you sure your phone is using IMAP and not active sync?
> 
> Michael
> 
> On Mon, Apr 2, 2012 at 6:25 PM, Julien  wrote:
>> Hi Michael,
>> 
>> Thanks for your reply. I did try port 993. I know that port generally
>> works for me, as I can access the Gmail IMAP/SMTP server using SSL. It
>> also works for that other Exchange server but only when the VPN is
>> turned on.
>> 
>> Somehow my iPhone works fine without a VPN, as long as it uses SSL. So
>> I'm really unsure why I can't achieve the same thing from my laptop
>> using imaplib.IMAP4_SSL() without the VPN turned on.
>> 
>> Thank you,
>> 
>> Julien
>> 
>> On Apr 2, 3:10 pm, Michael Hrivnak  wrote:
>>> That method uses the default port 993.  Can you connect to that port
>>> at all from your computer?  For example, try using a telnet client.
>>> 
>>> Michael
>>> 
>>> On Sat, Mar 31, 2012 at 1:39 AM, Julien  wrote:
 Hi,
>>> 
 I'm able to connect to an Exchange server via SMTP and IMAP from my
 iPhone using SSL and without using a VPN. So I would expect to be able
 to do the same from my computer using Python.
>>> 
 However, the following hangs and times out on my computer when I'm not
 connected to the VPN:
>>> 
>>> import imaplib
>>> imap = imaplib.IMAP4_SSL("my.server.address")
>>> 
 If I am connected to the VPN, then it works fine.
>>> 
 Do you know why it won't work with SSL and without the VPN? Am I
 missing something?
>>> 
 Thanks a lot,
>>> 
 Julien
 --
 http://mail.python.org/mailman/listinfo/python-list
>> 
>> --
>> http://mail.python.org/mailman/listinfo/python-list



smime.p7s
Description: S/MIME cryptographic signature
-- 
http://mail.python.org/mailman/listinfo/python-list