Re: Spamming PyPI with stupid packages

2012-01-01 Thread Devin Jeanpierre
> Perhaps I'm just slow, but what is sexist about this package? Do you even
> know what the package does?

The dependencies are "car", "house", and "money" (and "workhard", of
course). The joke being that women only care about how wealthy you
are.

If it's just about naming a package "girlfriend", though, I agree. And
honestly that's much better material for a joke anyway.

-- Devin

On Mon, Jan 2, 2012 at 2:08 AM, Steven D'Aprano
 wrote:
> On Mon, 02 Jan 2012 00:24:48 +0100, Alexander Kapps wrote:
>
>> Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I
>> cannot resists.
>>
> allow everyone to do "import girlfriend"
>>
>>> I'm betting on a joke, like antigravity only significantly less funny
>>> and more sexist.
>>
>> Absolutely not funny. I hope that someday people will understand that
>> sexism is just another form of racism.
>
> Perhaps I'm just slow, but what is sexist about this package? Do you even
> know what the package does?
>
>
>> Felinx Lee: Do apologize and rename your package/module
>
> So the package itself is not offensive, just the name "girlfriend"?
>
> Or is it the very concept of "girlfriend" that offends you?
>
>
>> or I'm going to
>> make a racist comment against Chinese people.
>
> I'm sure he's quaking in his boots. Some random guy on the Internet is
> going to insult him based on a wild assumption about his nationality.
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating sin/square waves sound

2012-01-01 Thread Paulo da Silva
Em 31-12-2011 01:19, K Richard Pixley escreveu:
> On 12/29/11 23:17 , Paulo da Silva wrote:
>> Hi,
>> Sorry if this is a FAQ, but I have googled and didn't find any
>> satisfatory answer.
>>
>> Is there a simple way, preferably multiplataform (or linux), of
>> generating sinusoidal/square waves sound in python?
>>
>> Thanks for any answers/suggestions.
> 
> I just posted on this elsewhere.  Look for a thread titled: "Which
> library for audio playback ?"
> 
> --rich

Thank you. I have just seen it using google and saved the bookmark of
the link. It's too late now but I'll read it tomorrow.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating sin/square waves sound

2012-01-01 Thread Paulo da Silva
Em 30-12-2011 11:23, mblume escreveu:
> Am Fri, 30 Dec 2011 07:17:13 + schrieb Paulo da Silva:
...

> Alternatively you might just generate (t,signal) samples, write them to 
> a file and convert them using "sox" (under Linux, might also be available
> under Windows) to another format.
> 
As much as I could understand at a 1st look you are writing to a wav
file and then play the file.
It would be nice if I could play directly the samples.
Anyway I'll take a look at the wave module.
Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generating sin/square waves sound

2012-01-01 Thread Paulo da Silva
Em 30-12-2011 10:05, Dave Angel escreveu:
> On 12/30/2011 02:17 AM, Paulo da Silva wrote:
>> Hi,
>> Sorry if this is a FAQ, but I have googled and didn't find any
>> satisfatory answer.
>>
>> Is there a simple way, preferably multiplataform (or linux), of
>> generating sinusoidal/square waves sound in python?
>>
>> Thanks for any answers/suggestions.
> If you're willing to be Linux-only, then I believe you can do it without
> any extra libraries.
> 
> You build up a string (8 bit char, on Python 2.x)  of samples, and write
> it to  "/dev/audio".  When i experimented, I was only interested in a
> few seconds, so a single write was all I needed.
> 
> Note that the samples are 8 bits, and they are offset by 128.  So a zero
> signal would be a string of 128 values.  A very quiet square wave might
> be a bunch of 126, followed by a bunch of 130.  and so on.  And the
> loudest might be a bunch of 2's followed by a bunch of 253's.
> 
> You'll have to experiment with data rate;   The data is sent out at a
> constant rate from your string, but I don't know what that rate is.
> 
> 
This sounds nice, but then is 8 bits the limit for /dev/audio? What
about stereo? I don't need this one ... just for curiosity.
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spamming PyPI with stupid packages

2012-01-01 Thread Steven D'Aprano
On Mon, 02 Jan 2012 11:12:28 +1100, Lie Ryan wrote:

> Legitimate python programmer or not, that does not legitimize spamming
> PyPI.

I don't see that half a dozen trivial (pointless) modules should be 
classified as spam.

Personally, I've looked at the modules, and if I were the author, I'd be 
embarrassed to make them public. They aren't useful; they are rather 
immature; they don't demonstrate good Python knowledge or programming 
skill.


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


Re: Spamming PyPI with stupid packages

2012-01-01 Thread Steven D'Aprano
On Mon, 02 Jan 2012 00:24:48 +0100, Alexander Kapps wrote:

> Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I
> cannot resists.
> 
 allow everyone to do "import girlfriend"
> 
>> I'm betting on a joke, like antigravity only significantly less funny
>> and more sexist.
> 
> Absolutely not funny. I hope that someday people will understand that
> sexism is just another form of racism.

Perhaps I'm just slow, but what is sexist about this package? Do you even 
know what the package does?


> Felinx Lee: Do apologize and rename your package/module 

So the package itself is not offensive, just the name "girlfriend"?

Or is it the very concept of "girlfriend" that offends you?


> or I'm going to
> make a racist comment against Chinese people.

I'm sure he's quaking in his boots. Some random guy on the Internet is 
going to insult him based on a wild assumption about his nationality.



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


Idiot-proof installs for python+pygame+pyopenal+app

2012-01-01 Thread Tim Chase
I'm looking at developing some tools that involve pygame+pyopenal 
and would like to make cross-platform distribution as painless as 
possible.  Is there a "best practice" for doing this without 
forcing the user to install Python, install (say) pip, pull down 
pygame & pyopenal and install those, install my (simple) app, and 
then finally run it?


On Debian, installation of all the prerequisites would just be

  apt-get install pygame python-openal

(which, via a local apt repository, I could flag as dependencies 
of my app and package it as .deb) but it gets hairier on Mac & Win32.


-tkc



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


Re: Can't write to a directory made w/ os.makedirs

2012-01-01 Thread MRAB

On 02/01/2012 03:14, David Goldsmith wrote:

On Jan 1, 7:05 am, Tim Golden  wrote:

 On 01/01/2012 12:05, David Goldsmith wrote:
   >>  ie can the Python process creating the directories,
   >
   >  Yes.
   >
   >>  and a subprocess called from it create a simple file?
   >
   >  No.
   >
   >>  Depending on where you are in the filesystem, it may indeed
   >>  be necessary to be running as administrator. But don't try
   >>  to crack every security nut with an elevated sledgehammer.
   >
   >  If you mean running as admin., those were my sentiments exactly.  So,
   >  there isn't something specific I should be doing to assure that my
   >  subproceses can write to directories?

 In the general case, no. By default, a subprocess will have
 the same security context as its parent. The exception is
 where the parent (the Python processing invoking subprocess.call
 in this example) is already impersonating a different user;
 in that case, the subprocess will inherit its grandparent's
 context.

 But unless you're doing something very deliberate here then
 I doubt if that's biting you.

 Can I ask: are you absolutely certain that the processes
 you're calling are doing what you think they are and failing
 where you think they're failing?

 TJG


I'm a mathematician: the only thing I'm absolutely certain of is
nothing.

Here's my script, in case that helps:

import os
import sys
import stat
import os.path as op
import subprocess as sub
from os import remove
from os import listdir as ls
from os import makedirs as mkdir

def doFlac2Mp3(arg, d, fl):
 if '.flac' in [f[-5:] for f in fl]:
 newD = d.replace('FLACS', 'MP3s')
 mkdir(newD)
 for f in fl:
 if f[-5:]=='.flac':
 root = f.replace('.flac', '')
 cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools\
\flac.exe" -d ' +
'--output-prefix=' + newD + '\\', f]
 res = sub.call(cmd)#, env={'PATH': os.defpath})
 if not res:
 cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools
\\lame.exe" -h',
 newD + root + '.wav',  newD + root +
'.mp3']
 res = sub.call(cmd)#, env={'PATH': os.defpath})
 if not res:
 rf = newD + root + '.wav'
 remove(rf)

top=sys.argv[1]
op.walk(top, doFlac2Mp3, None)


I think that if the command line should be something like:

"C:\Program Files (x86)\aTunes\win_tools\flac.exe" -d 
--output-prefix=FOO\ BAR


then the cmd should be something like:

cmd = ['C:\\Program Files (x86)\\aTunes\\win_tools\\flac.exe', '-d', 
'--output-prefix="' + newD + '\\"', f]

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


Re: Can't write to a directory made w/ os.makedirs

2012-01-01 Thread David Goldsmith
On Jan 1, 7:05 am, Tim Golden  wrote:
> On 01/01/2012 12:05, David Goldsmith wrote:
>  >> ie can the Python process creating the directories,
>  >
>  > Yes.
>  >
>  >> and a subprocess called from it create a simple file?
>  >
>  > No.
>  >
>  >> Depending on where you are in the filesystem, it may indeed
>  >> be necessary to be running as administrator. But don't try
>  >> to crack every security nut with an elevated sledgehammer.
>  >
>  > If you mean running as admin., those were my sentiments exactly.  So,
>  > there isn't something specific I should be doing to assure that my
>  > subproceses can write to directories?
>
> In the general case, no. By default, a subprocess will have
> the same security context as its parent. The exception is
> where the parent (the Python processing invoking subprocess.call
> in this example) is already impersonating a different user;
> in that case, the subprocess will inherit its grandparent's
> context.
>
> But unless you're doing something very deliberate here then
> I doubt if that's biting you.
>
> Can I ask: are you absolutely certain that the processes
> you're calling are doing what you think they are and failing
> where you think they're failing?
>
> TJG

I'm a mathematician: the only thing I'm absolutely certain of is
nothing.

Here's my script, in case that helps:

import os
import sys
import stat
import os.path as op
import subprocess as sub
from os import remove
from os import listdir as ls
from os import makedirs as mkdir

def doFlac2Mp3(arg, d, fl):
if '.flac' in [f[-5:] for f in fl]:
newD = d.replace('FLACS', 'MP3s')
mkdir(newD)
for f in fl:
if f[-5:]=='.flac':
root = f.replace('.flac', '')
cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools\
\flac.exe" -d ' +
   '--output-prefix=' + newD + '\\', f]
res = sub.call(cmd)#, env={'PATH': os.defpath})
if not res:
cmd = ['"C:\\Program Files (x86)\\aTunes\\win_tools
\\lame.exe" -h',
newD + root + '.wav',  newD + root +
'.mp3']
res = sub.call(cmd)#, env={'PATH': os.defpath})
if not res:
rf = newD + root + '.wav'
remove(rf)

top=sys.argv[1]
op.walk(top, doFlac2Mp3, None)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: readline for mac python? (really, reproducing mac python packages)

2012-01-01 Thread K Richard Pixley

On 1/1/12 16:49 , K Richard Pixley wrote:

I'm having trouble finding a reasonable python environment on mac.

The supplied binaries, (2.7.2, 3.2.2), are built with old versions of
macosx and are not capable of building any third party packages that
require gcc.

The source builds easily enough out of the box, (./configure
--enable-framework && make && sudo make install), but when I do that, I
end up with a python interpreter that lacks readline.

How do I get readline involved?

Or better... is there an instruction sheet somewhere on how to reproduce
the python.org binary packages?

--rich


Bah.  I just needed to dig a little deeper into the source.  All the doc 
I wanted is in there.


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


Re: Spamming PyPI with stupid packages

2012-01-01 Thread Ben Finney
Ben Finney  writes:

> Alexander Kapps  writes:
>
> > Absolutely not funny. I hope that someday people will understand
> > that sexism is just another form of racism.
>
> That's not right. Racism and sexism are not forms of each other.
>
> Instead, racism and sexism are both forms of bigotry.

Hmm, even that's not really true. Racism and sexism are both forms of
prejudice.

Bigotry always entails prejudice, but not vice versa.

How complex are the ways humans mistreat each other :-)

-- 
 \   “Everyone is entitled to their own opinions, but they are not |
  `\entitled to their own facts.” —US Senator Pat Moynihan |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spamming PyPI with stupid packages

2012-01-01 Thread Ben Finney
Alexander Kapps  writes:

> Absolutely not funny. I hope that someday people will understand that
> sexism is just another form of racism.

That's not right. Racism and sexism are not forms of each other.

Instead, racism and sexism are both forms of bigotry.

And yes, I agree that the packages at issue are unfunny and the intent
is bigoted.

> I was about to write a really harsh reply, but cooled down before I got a
> chance to hit the Send button.

You would do better to send it to the author, rather than here.

> Felinx Lee: Do apologize and rename your package/module or I'm going
> to make a racist comment against Chinese people.

Please don't. We must be better than the bigots whose behaiour you
rightly deplore.

-- 
 \ “God was invented to explain mystery. God is always invented to |
  `\ explain those things that you do not understand.” —Richard P. |
_o__)Feynman, 1988 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


readline for mac python? (really, reproducing mac python packages)

2012-01-01 Thread K Richard Pixley

I'm having trouble finding a reasonable python environment on mac.

The supplied binaries, (2.7.2, 3.2.2), are built with old versions of 
macosx and are not capable of building any third party packages that 
require gcc.


The source builds easily enough out of the box, (./configure 
--enable-framework && make && sudo make install), but when I do that, I 
end up with a python interpreter that lacks readline.


How do I get readline involved?

Or better... is there an instruction sheet somewhere on how to reproduce 
the python.org binary packages?


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


Re: Spamming PyPI with stupid packages

2012-01-01 Thread Devin Jeanpierre
Sorry, I lied. It's been a while and I misremembered. The package
mentioned in the blog post was removed of the author's free will, and
PyPI doesn't police submissions.

-- Devin

On Sun, Jan 1, 2012 at 7:05 PM, Devin Jeanpierre  wrote:
>> Absolutely not funny. I hope that someday people will understand that sexism
>> is just another form of racism.
>
> One can understand that sexism is a terrible thing, and at the same
> time make sexist jokes.
>
>> Felinx Lee: Do apologize and rename your package/module or I'm going to make
>> a racist comment against Chinese people.
>
> This is a joke, right? Making some kind of racist remark about Chinese
> people wouldn't help anything at all, and it's hypocritical given your
> stance on sexist jokes. It's one thing to make a joke, to make people
> laugh, and inadvertently hurt someone's feelings. It's much worse to
> make a malicious comment to try to hurt someone deliberately.
>
> On a slightly different note, PyPI uploads are in fact already
> policed. See http://holdenweb.blogspot.com/2011/07/childish-behavior.html
> for an example
>
> Coincidentally, it also involved a joke that the PyPI maintainers
> found in poor taste. It's also a good example, if you read deeper into
> the history of the name and project, of how overzealous policing of
> these jokes can drive people away from your community, just as
> underzealous policing can. Please be less angry and more careful, and
> appreciate that, most likely, nobody here is operating under evil
> intentions. They are just operating under what you might call poor
> taste.
>
> -- Devin
>
> On Sun, Jan 1, 2012 at 6:24 PM, Alexander Kapps  wrote:
>> Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I cannot
>> resists.
>>
>>
> allow everyone to do "import girlfriend"
>>
>>
>>> I'm betting on a joke, like antigravity only significantly less
>>> funny and more sexist.
>>
>>
>> Absolutely not funny. I hope that someday people will understand that sexism
>> is just another form of racism.
>>
>> I was about to write a really harsh reply, but cooled down before I got a
>> chance to hit the Send button.
>>
>> Felinx Lee: Do apologize and rename your package/module or I'm going to make
>> a racist comment against Chinese people.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spamming PyPI with stupid packages

2012-01-01 Thread Lie Ryan

On 01/02/2012 09:33 AM, Robert Kern wrote:

On 1/1/12 10:18 PM, Matt Chaput wrote:

Someone seems to be spamming PyPI by uploading multiple stupid
packages. Not sure if it's some form of advertising spam or just idiocy.

Don't know if we should care though... maybe policing uploads is worse
than cluttering PyPI's disk space and RSS feed with dumb 1 KB packages.


girlfriend 1.0.1 10 A really simple module that allow everyone to do
"import girlfriend"
girlfriends 1.0 4 Girl Friends
car 1.0 2 Car, a depended simple module that allow everyone to do
"import girlfriend"
house 1.0 2 House, a depended simple module that allow everyone to do
"import girlfriend"
money 1.0 2 Money, a depended simple module that allow everyone to do
"import girlfriend"
workhard 1.0 2 Keep working hard, a depended simple module that allow
everyone to do "import girlfriend"


I'm betting on a joke, like antigravity only significantly less funny
and more sexist. The author is a legitimate Python programmer, and the
links go to his blog where he talks about Python stuff.


Legitimate python programmer or not, that does not legitimize spamming 
PyPI.


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


Re: Spamming PyPI with stupid packages

2012-01-01 Thread Devin Jeanpierre
> Absolutely not funny. I hope that someday people will understand that sexism
> is just another form of racism.

One can understand that sexism is a terrible thing, and at the same
time make sexist jokes.

> Felinx Lee: Do apologize and rename your package/module or I'm going to make
> a racist comment against Chinese people.

This is a joke, right? Making some kind of racist remark about Chinese
people wouldn't help anything at all, and it's hypocritical given your
stance on sexist jokes. It's one thing to make a joke, to make people
laugh, and inadvertently hurt someone's feelings. It's much worse to
make a malicious comment to try to hurt someone deliberately.

On a slightly different note, PyPI uploads are in fact already
policed. See http://holdenweb.blogspot.com/2011/07/childish-behavior.html
for an example

Coincidentally, it also involved a joke that the PyPI maintainers
found in poor taste. It's also a good example, if you read deeper into
the history of the name and project, of how overzealous policing of
these jokes can drive people away from your community, just as
underzealous policing can. Please be less angry and more careful, and
appreciate that, most likely, nobody here is operating under evil
intentions. They are just operating under what you might call poor
taste.

-- Devin

On Sun, Jan 1, 2012 at 6:24 PM, Alexander Kapps  wrote:
> Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I cannot
> resists.
>
>
 allow everyone to do "import girlfriend"
>
>
>> I'm betting on a joke, like antigravity only significantly less
>> funny and more sexist.
>
>
> Absolutely not funny. I hope that someday people will understand that sexism
> is just another form of racism.
>
> I was about to write a really harsh reply, but cooled down before I got a
> chance to hit the Send button.
>
> Felinx Lee: Do apologize and rename your package/module or I'm going to make
> a racist comment against Chinese people.
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spamming PyPI with stupid packages

2012-01-01 Thread Alexander Kapps
Uh oh, should I really send this? ... Yes. Yes, I should! Sorry, I 
cannot resists.



allow everyone to do "import girlfriend"



I'm betting on a joke, like antigravity only significantly less
funny and more sexist.


Absolutely not funny. I hope that someday people will understand 
that sexism is just another form of racism.


I was about to write a really harsh reply, but cooled down before I 
got a chance to hit the Send button.


Felinx Lee: Do apologize and rename your package/module or I'm going 
to make a racist comment against Chinese people.

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


Re: Spamming PyPI with stupid packages

2012-01-01 Thread Robert Kern

On 1/1/12 10:18 PM, Matt Chaput wrote:

Someone seems to be spamming PyPI by uploading multiple stupid packages. Not 
sure if it's some form of advertising spam or just idiocy.

Don't know if we should care though... maybe policing uploads is worse than 
cluttering PyPI's disk space and RSS feed with dumb 1 KB packages.


girlfriend 1.0.110  A really simple module that allow everyone to do 
"import girlfriend"
girlfriends 1.0 4   Girl Friends
car 1.0 2   Car, a depended simple module that allow everyone to do "import 
girlfriend"
house 1.0   2   House, a depended simple module that allow everyone to do 
"import girlfriend"
money 1.0   2   Money, a depended simple module that allow everyone to do 
"import girlfriend"
workhard 1.02   Keep working hard, a depended simple module that allow everyone 
to do "import girlfriend"


I'm betting on a joke, like antigravity only significantly less funny and more 
sexist. The author is a legitimate Python programmer, and the links go to his 
blog where he talks about Python stuff.


  https://bitbucket.org/felinx

You can tell him that you don't appreciate his abuse of PyPI here if you like:

  http://feilong.me/2012/01/python-import-girlfriend

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Spamming PyPI with stupid packages

2012-01-01 Thread Matt Chaput
Someone seems to be spamming PyPI by uploading multiple stupid packages. Not 
sure if it's some form of advertising spam or just idiocy.

Don't know if we should care though... maybe policing uploads is worse than 
cluttering PyPI's disk space and RSS feed with dumb 1 KB packages.

> girlfriend 1.0.1  10  A really simple module that allow everyone to 
> do "import girlfriend"
> girlfriends 1.0   4   Girl Friends
> car 1.0   2   Car, a depended simple module that allow everyone to do 
> "import girlfriend"
> house 1.0 2   House, a depended simple module that allow everyone to 
> do "import girlfriend"
> money 1.0 2   Money, a depended simple module that allow everyone to 
> do "import girlfriend"
> workhard 1.0  2   Keep working hard, a depended simple module that allow 
> everyone to do "import girlfriend"


Matt




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


Re: .format vs. %

2012-01-01 Thread Miki Tebeka
> >>> s = "{0} {1} {2} {3}"
> >>> s.format(1, 2, 3, 4)
> '1 2 3 4'
Or even
In [4]: fmt = '{0} {1} {2} {3}'.format
In [5]: print(fmt(1, 2, 3, 4))
1 2 3 4

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


Re: Can't write to a directory made w/ os.makedirs

2012-01-01 Thread Tim Golden

On 01/01/2012 12:05, David Goldsmith wrote:
>> ie can the Python process creating the directories,
>
> Yes.
>
>> and a subprocess called from it create a simple file?
>
> No.
>
>> Depending on where you are in the filesystem, it may indeed
>> be necessary to be running as administrator. But don't try
>> to crack every security nut with an elevated sledgehammer.
>
> If you mean running as admin., those were my sentiments exactly.  So,
> there isn't something specific I should be doing to assure that my
> subproceses can write to directories?


In the general case, no. By default, a subprocess will have
the same security context as its parent. The exception is
where the parent (the Python processing invoking subprocess.call
in this example) is already impersonating a different user;
in that case, the subprocess will inherit its grandparent's
context.

But unless you're doing something very deliberate here then
I doubt if that's biting you.

Can I ask: are you absolutely certain that the processes
you're calling are doing what you think they are and failing
where you think they're failing?

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


Re: pickling instances of metaclass generated classes

2012-01-01 Thread Peter Otten
lars van gemerden wrote:

>> import pickle
>> import sys
>>
>> class MetaClass(type):
>> pass
>>
>> class M(object):
>> def __init__(self, module):
>> self.__module = module
>> def __getattr__(self, name):
>> print "creating class", name
>> class_ = MetaClass(name, (), {"__module__": self.__module})
>> setattr(self, name, class_)
>> return class_
>>
>> sys.modules["m"] = M("m")
>> import m
>> c = m.x
>> s = pickle.dumps(c)
>> print repr(s)
>> d = pickle.loads(s)
>>
>> assert c is d
>>
>> sys.modules["m"] = M("m")
>> e = pickle.loads(s)
>>
>> assert c is not e
>>
>> The official way is probably what Robert mentioned, via the copy_reg
>> module, but I didn't get it to work.
> 
> I will look further into this. does "sys.modules["m"] = M("m")" create
> a new module?

Assigning to sys.modules[modulename] can put arbitrary objects into the 
module cache, in this case an M instance. To drive the point home:

>>> import sys
>>> sys.modules["x"] = 42
>>> import x
>>> x
42
>>> sys.modules["x"] = "spam"
>>> import x
>>> x
'spam'

> Cheers, Lars
> 
> PS: I get an error when posting this to the usenet group

Sorry, that seems to happen when I post via gmane and don't manually clear 
the follow-up that my newsreader helpfully (knode) inserts. I've not yet 
found a permanent fix, but if that was the problem you should be able to 
answer this post.

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


Creating a binary only python distribution of a C extension module and including some additional python and c files in it

2012-01-01 Thread akhilesh singhania
Hi,

I have a extension module in C which I want to distribute in binary
format, ideally an rpm. Additionally, I want to include some python
files (examples on how to use the extension module) and source for a
library the module dynamically links to (c,h, and make files).

How do I specify the example python file in setup.py so that it will
be included in the rpm?

If I specify it as scripts, I get the following error:

$ python setup.py bdist --format=rpm

 running build_scripts
 creating build/scripts-2.6
 error: file 'foo.py' does not exist
 error: Bad exit status from /var/tmp/rpm-tmp.yjws9x (%build)
If I specify it as data_files, I get the following error:

$ python setup.py bdist --format=rpm

 error: Installed (but unpackaged) file(s) found:
/usr/foo.pyc
/usr/foo.pyo
If I specify it as py_modules, I do not get errors but it is not
included in the resulting rpm.

Specifying it as a script works if I use

$ python setup.py bdist --format=gztar
Additionally, can I control the hierarchy of how the files are laid
out in the rpm?

Currently, I am specifying the c,h,make files as data_files and they
get placed in /usr, which is not desirable.

Regards,
akhi
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't write to a directory made w/ os.makedirs

2012-01-01 Thread David Goldsmith
On Jan 1, 1:37 am, Tim Golden  wrote:
> On 31/12/2011 22:13, OlyDLG wrote:
>  > Hi!  I'm working on a script utilizing os.makedirs to make directories
>  > to which I'm then trying to write files created by exe's spawned w/
>  > subprocess.call; I'm developing in Stani's Python Editor, debugging
>  > using Winpdb.  I've gotten to the point where
>  > subprocess.Popen._execute_child is raising a WindowsError(5,'Access is
>  > denied') exception.  I've tried: setting the mode in the makedirs
>  > call; using os.chmod(, stat.S_IWRITE); and even setting a
>  > breakpoint before the subprocess.call and unsetting the read-only
>  > attribute of the pertinent directory tree using the Windows directory
>  > Properties dialog--which doesn't "take," if that's a clue--all to no
>  > avail.
>
> Whatever you're trying to do, resetting the read-only bit
> on the Windows directory is not the answer. It has, bizarrely,
> nothing to do with the read/write-ness of a directory; rather,
> it reflects the system-ness of a folder.
>
> There's no general answer I can see to give, without
> knowing what the security is on your folders or what
> other thing might impede your processes from writing
> files in them. Is it definite that the ERROR_ACCESS_DENIED
> is in fact the result of attempting to write a file into
> one of the newly-created directories?
>
> Can you do something like this (adapt for your own environment):
>
> 
> import os, sys
> import subprocess
>
> os.makedirs ("c:/temp/a/b/c")
>
> with open ("c:/temp/a/b/c/test1.txt", "w"):
>    pass
>
> subprocess.call ([
>    sys.executable,
>    "-c",
>    "open ('c:/temp/a/b/c/test2.txt', 'w').close ()"
> ])
>
> 
>
> ie can the Python process creating the directories,

Yes.

> and a subprocess called from it create a simple file?

No.

> Depending on where you are in the filesystem, it may indeed
> be necessary to be running as administrator. But don't try
> to crack every security nut with an elevated sledgehammer.

If you mean running as admin., those were my sentiments exactly.  So,
there isn't something specific I should be doing to assure that my
subproceses can write to directories?
>
> TJG

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


Re: [Windows 7, Python 2.6] Can't write to a directory made w/ os.makedirs

2012-01-01 Thread Tim Golden

On 31/12/2011 22:13, OlyDLG wrote:
> Hi!  I'm working on a script utilizing os.makedirs to make directories
> to which I'm then trying to write files created by exe's spawned w/
> subprocess.call; I'm developing in Stani's Python Editor, debugging
> using Winpdb.  I've gotten to the point where
> subprocess.Popen._execute_child is raising a WindowsError(5,'Access is
> denied') exception.  I've tried: setting the mode in the makedirs
> call; using os.chmod(, stat.S_IWRITE); and even setting a
> breakpoint before the subprocess.call and unsetting the read-only
> attribute of the pertinent directory tree using the Windows directory
> Properties dialog--which doesn't "take," if that's a clue--all to no
> avail.

Whatever you're trying to do, resetting the read-only bit
on the Windows directory is not the answer. It has, bizarrely,
nothing to do with the read/write-ness of a directory; rather,
it reflects the system-ness of a folder.

There's no general answer I can see to give, without
knowing what the security is on your folders or what
other thing might impede your processes from writing
files in them. Is it definite that the ERROR_ACCESS_DENIED
is in fact the result of attempting to write a file into
one of the newly-created directories?

Can you do something like this (adapt for your own environment):


import os, sys
import subprocess

os.makedirs ("c:/temp/a/b/c")

with open ("c:/temp/a/b/c/test1.txt", "w"):
  pass

subprocess.call ([
  sys.executable,
  "-c",
  "open ('c:/temp/a/b/c/test2.txt', 'w').close ()"
])



ie can the Python process creating the directories,
and a subprocess called from it create a simple file?

Depending on where you are in the filesystem, it may indeed
be necessary to be running as administrator. But don't try
to crack every security nut with an elevated sledgehammer.


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