Re: Can you advice a Python library to query a lan subnet with SNMP and collect MAC addresses of nodes?

2011-04-19 Thread Aldo Ceccarelli
On 18 Apr, 22:38, Daniel Kluev dan.kl...@gmail.com wrote:
 Isn't it better to use subprocess.Popen and read stdout/stderr
 directly? Should be much more convenient than temporary files.

 --
 With best regards,
 Daniel Kluev

Thanks Daniel, your solution is far better WKR! Aldo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Equivalent code to the bool() built-in function

2011-04-19 Thread Kushal Kumaran
On Tue, Apr 19, 2011 at 7:09 AM, Christian Heimes li...@cheimes.de wrote:
 Am 18.04.2011 21:58, schrieb John Nagle:
     This is typical for languages which backed into a bool type,
 rather than having one designed in.  The usual result is a boolean
 type with numerical semantics, like

   True + True
 2

 I find the behavior rather useful. It allows multi-xor tests like:

 if a + b + c + d != 1:
    raise ValueError(Exactly one of a, b, c or d must be true.)


Unless you're sure all of a, b, c, and d are boolean values, an int
with a negative value slipping in could result in the sum equaling 1,
but more than one of the variables evaluating to True in boolean
contexts.

-- 
regards,
kushal
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Equivalent code to the bool() built-in function

2011-04-19 Thread Chris Angelico
On Tue, Apr 19, 2011 at 4:23 PM, Kushal Kumaran
kushal.kumaran+pyt...@gmail.com wrote:
 if a + b + c + d != 1:
    raise ValueError(Exactly one of a, b, c or d must be true.)


 Unless you're sure all of a, b, c, and d are boolean values, an int
 with a negative value slipping in could result in the sum equaling 1,
 but more than one of the variables evaluating to True in boolean
 contexts.

If they're all expressions, then you can easily guarantee that.

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


Re: Feature suggestion -- return if true

2011-04-19 Thread Jussi Piitulainen
Gregory Ewing writes:
 Chris Angelico wrote:
 
  Question: How many factorial functions are implemented because a
  program needs to know what n! is, and how many are implemented to
  demonstrate recursion (or to demonstrate the difference between
  iteration and recursion)? :)

(I can't get to the parent directly, so I follow up indirectly.)

Factorials become an interesting demonstration of recursion when done
well. There's a paper by Richard J. Fateman, citing Peter Luschny:

http://www.cs.berkeley.edu/~fateman/papers/factorial.pdf
http://www.luschny.de/math/factorial/FastFactorialFunctions.htm

Fateman's major conclusion is that you should probably not use the
'naive' factorial programs for much of anything. I take this to
include their use as examples of recursion, unless the purpose is to
make the idea of recursion look bad.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Feature suggestion -- return if true

2011-04-19 Thread Chris Angelico
On Tue, Apr 19, 2011 at 4:42 PM, Jussi Piitulainen
jpiit...@ling.helsinki.fi wrote:
 Factorials become an interesting demonstration of recursion when done
 well. There's a paper by Richard J. Fateman, citing Peter Luschny:

 http://www.cs.berkeley.edu/~fateman/papers/factorial.pdf
 http://www.luschny.de/math/factorial/FastFactorialFunctions.htm

 Fateman's major conclusion is that you should probably not use the
 'naive' factorial programs for much of anything. I take this to
 include their use as examples of recursion, unless the purpose is to
 make the idea of recursion look bad.


And here is an algorithm which nobody needs, for the Simple-Minded only:
long factorial(long n) { return n = 1 ? 1 : n * factorial(n-1); }  Do
not use it if n  12.


I suppose the n  12 issue is based on the assumption that
sizeof(long)==4. That's not an algorithmic question, that's a return
type issue... not to mention a rather naive assumption. 64-bit
integers let you go to n == 20 (iirc), and if you go bignum, even that
simple algorithm will be fine for up to n == 500 or so without stack
issues.

But sometimes you need a simple and well-known algorithm to
demonstrate a language feature with. Maybe we should switch to
Fibonacci instead... Anyone for caramel sauce?

http://www.dangermouse.net/esoteric/chef_fib.html

(As a side point, I have become somewhat noted around the house for
always saying Fibonacci whenever caramel sauce is mentioned...)

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


Re: How to create a (transparent) decorator with status information?

2011-04-19 Thread Timo Schmiade
Hey Ian,

On Mon, Apr 18, 2011 at 01:07:58PM -0600, Ian Kelly wrote:
 In the simple case, just store the state on the wrapper function itself:
 
 def call_counts(function):
   @functools.wraps(function)
   def wrapper(*args, **kwargs):
 wrapper.num_calls += 1
 return function(*args, **kwargs)
   wrapper.num_calls = 0
   return wrapper

Of course! Functions are first-class objects, so I can give them members
just as I would do with any other object. I'm still thinking too much
C++...

 If you want the state to be shared, you should probably store it in an
 object and use an instance method as the decorator:

Yes, this is the same idea that Wayne came up with. Thank you as well,
that helped me understand decorators a lot more.

Kind regards,

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


Re: IDLE bug

2011-04-19 Thread Terry Reedy

On 4/19/2011 12:05 AM, harrismh777 wrote:

Are bug reports wanted here, or just in issue tracker?


If one is somewhat experienced with Python and is sure about having 
identified a bug, and is willing to search the tracker for existing 
reports and respond to questions, then report on the tracker. If one is 
new to Python and perhaps not sure, or should not be sure, then I prefer 
that one ask here for a second opinion.


--
Terry Jan Reedy

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


Re: How to create a (transparent) decorator with status information?

2011-04-19 Thread Timo Schmiade
Hey Wayne,

On Mon, Apr 18, 2011 at 04:04:15PM -0700, Wayne Witzel III wrote:
 Going with the object approach, you could use Borg to give yourself the state 
 between instances you mentioned. And since you are using an object, you'll 
 have access to the data without needing to return it from the decorator.
 
 class StatefulDecorators(object):
 _state = {}
 def __new__(cls, *p, **k):
 self = object.__new__(cls, *p, **k)
 self.__dict__ = cls._state
 return self
 
 def count_calls(self, function):
 @functools.wraps(function)
 def wrapper(*args, **kwargs):
 try:
 self.calls += 1
 except AttributeError:
 self.calls = 1
 return function(*args, **kwargs)
 return wrapper

Brilliant! I didn't realize you could use member functions as
decorators, too! That way, you can easily create closures to self,
solving all the problems I was seeing.

Just one question remains now: What is a Borg in this context?

Thank you.

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


Re: Questions about GIL and web services from a n00b

2011-04-19 Thread Lamont Nelson
  1. Are you sure you want to use python because threading is not
good due
 to the Global Lock (GIL)?  Is this really an issue for multi-threaded
 web services as seems to be indicated by the articles from a Google
 search?  If not, how do you avoid this issue in a multi-threaded process
 to take advantage of all the CPU cores available?

To take advantage of the cores on your server you'll want to consider
a multi-process design instead of multi-threading. You can achieve
this with something like http://projects.unbit.it/uwsgi/, which will
allow you to manage the processes. I've used this behind apache
successfully.


 2. Are there good web services frameworks available for building a REST
 based service?  I admit I have looked at web2py, Django, pyramid/pylons,
 and a few others.  SOAP seems to be pretty well supported but I'm not
 finding the same for quick development of REST based services for
 exchanging JSON or XML formatted data.  This is probably just my n00b
 status, but what tools are best for building a simple REST data exchange
 API?

I've personally used Pyramid to implement REST web services with
multiple data transport formats (json, xml) for the same endpoints
with minimal fuss. It's basically as simple as returning an object
from your view and defining a renderer that knows how to translate
this object to the desired format. Look at
http://docs.pylonsproject.org/projects/pyramid/1.0/narr/renderers.html#views-which-use-a-renderer
and 
http://docs.pylonsproject.org/projects/pyramid/1.0/narr/viewconfig.html#view-config-chapter
for more information.

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


Re: Two similar logging programs but different ouputs

2011-04-19 Thread Vinay Sajip
On Apr 19, 6:35 am, Disc Magnet discmag...@gmail.com wrote:

 I couldn't find this mentioned in the documentation at:

 http://docs.python.org/library/logging.config.html#configuration-file...

 Could you please tell me where this is documented?

It's documented here:

http://docs.python.org/library/logging.config.html#dictionary-schema-details

(look for 'disable_existing_logger'), but having looked at it, it *is*
poorly documented and hard to find. I'll update the fileConfig section
to describe the behaviour more clearly.

 In the following code, foo.bar is not explicitly mentioned in the file
 configuration. As per what you said, foo.bar should be disabled.

Actually I wasn't clear enough in my earlier response. The behaviour
is that all loggers are disabled other than those explicitly named in
the configuration *and their descendants*.

I'm glad you brought these points up, they do highlight an area where
the documentation could be clearer. I'll get on it.

Regards,

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


Re: Equivalent code to the bool() built-in function

2011-04-19 Thread Steven D'Aprano
On Tue, 19 Apr 2011 16:26:50 +1000, Chris Angelico wrote:

 On Tue, Apr 19, 2011 at 4:23 PM, Kushal Kumaran
 kushal.kumaran+pyt...@gmail.com wrote:
 if a + b + c + d != 1:
    raise ValueError(Exactly one of a, b, c or d must be true.)


 Unless you're sure all of a, b, c, and d are boolean values, an int
 with a negative value slipping in could result in the sum equaling 1,
 but more than one of the variables evaluating to True in boolean
 contexts.
 
 If they're all expressions, then you can easily guarantee that.

*raises eyebrow*


Either of these should do the job:

sum(map(bool, (a, b, c, d)))

sum(bool(x) for x in (a, b, c, d))

but I don't see how 

(arbitrary expression) + (another expression) + ... + (last expression)

can have any guarantees applied. I mean, you can't even guarantee that 
they won't raise an exception. Can you explain what you mean?


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


Re: [ANN] Python 2.5.6 Release Candidate 1

2011-04-19 Thread Paul Rubin
Martin v. Löwis mar...@v.loewis.de writes:
 On behalf of the Python development team and the Python community, I'm
 happy to announce the release candidate 1 of Python 2.5.6.

 This is a source-only release that only includes security fixes. 

Thanks Martin, I'm glad these older releases are still getting important
fixes. 

I notice http://www.python.org/download/releases/2.5.6/NEWS.txt says the
release date was 17 Apr 2010.  Presumably that should have said 2011.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Equivalent code to the bool() built-in function

2011-04-19 Thread Chris Angelico
On Tue, Apr 19, 2011 at 6:43 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 but I don't see how

 (arbitrary expression) + (another expression) + ... + (last expression)

 can have any guarantees applied. I mean, you can't even guarantee that
 they won't raise an exception. Can you explain what you mean?

What Christian posted isn't something I've often done, but here's
something slightly different that exploits the same
comparisons-return-summable-values concept:

A condition with N subconditions is deemed to be satisfied if a
minimum of M of them are true. This is a general case of the boolean
Or (N = 2, M = 1) and And (N = 2, M = 2), but does not have a direct
equivalent in binary operators. You simply sum the subconditions,
compare against M, and you have your answer.

if (((port1024) + (!ip.startswith(192.168.)) +
(greylist[ip]time()) + (++spewcnt10))=3) // flag this packet as
suspicious

Contrived example as I don't recall any specifics right now, but this
will pick up any packets where three or more of the conditions are
met. Useful only in fairly specific situations, but I don't know of
any way to do this with just AND/OR/NOT that would be as clear and
simple.

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


Re: Python IDE/text-editor

2011-04-19 Thread Vlastimil Brom
2011/4/19 Alec Taylor alec.tayl...@gmail.com:
 SPE looks good, however I couldn't get it running (svn'd it). Do you
 know if there's an installer?

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


There are source archives
http://pythonide.blogspot.com/2008/02/spe-084c-python-ide-editor-released.html
download page:
http://developer.berlios.de/project/showfiles.php?group_id=4161

you may check the articles on that forum:
label: spe

SPE could be run for me (somehow) just after unpacking as mentioned on
the page quoted above (having python and wxpython installed; in my
case with some likely version problems on newer wx).

As for other suggestions, I am not sure, whether the list
http://wiki.python.org/moin/PythonEditors
has been mentioned sofar; you may check some other possibilities, if
you like to.

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


Looking for a urllib(2) cookie handler

2011-04-19 Thread Mark Carter
I'm in python 2.6.5, and have Firefox 3.6.13. I would like to download
some html from a site and scrape it programatically. The site requires
a cookie, which I have in Firefox.

Is there a simple python recipe I can use to read the contents of a
url and say just use the cookie that I have in Firefox?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a urllib(2) cookie handler

2011-04-19 Thread Chris Rebert
On Tue, Apr 19, 2011 at 4:44 AM, Mark Carter alt.mcar...@gmail.com wrote:
 I'm in python 2.6.5, and have Firefox 3.6.13. I would like to download
 some html from a site and scrape it programatically. The site requires
 a cookie, which I have in Firefox.

 Is there a simple python recipe I can use to read the contents of a
 url and say just use the cookie that I have in Firefox?

Untested (3rd Google hit for import firefox cookies python):
http://blog.mithis.net/archives/python/90-firefox3-cookies-in-python

At a minimum, I think you'll need to replace:
from pysqlite2 import dbapi2 as sqlite
With:
import sqlite3 as sqlite

You'll also have to figure out where Firefox's `cookies.sqlite` file
is located on your system.

Cheers,
Chris
--
My compiler is compiling, I swear!
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a urllib(2) cookie handler

2011-04-19 Thread Mark Carter
On Apr 19, 12:44 pm, Mark Carter alt.mcar...@gmail.com wrote:

 url and say just use the cookie that I have in Firefox?

mechanize looks kinda like what I want, but i still can't get it to
work properly. So far I have:

import cookielib
import mechanize

cookiefile = C:\\Users\\$ME\\AppData\\Roaming\\Mozilla\\Firefox\
\Profiles\\zl648qvt.default\\cookies.sqlite
cookies = mechanize.MozillaCookieJar(filename = cookiefile,
delayload=True)
#cookies = cookielib.MozillaCookieJar()
#cookies = cookielib.MSIECookieJar()
#cookies.load_from_registry()  # finds cookie index file from registry
br = mechanize.Browser()
br.set_cookiejar(cookies)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-
US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
url = $URL
r = br.open(url)

#print cj
#opener =
mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))


html = r.read()
print html

where $ME and $URL are replaced with suitable values. It doesn't
appear to acutally be using the cookies.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a urllib(2) cookie handler

2011-04-19 Thread Chris Rebert
On Tue, Apr 19, 2011 at 5:48 AM, Mark Carter alt.mcar...@gmail.com wrote:
 On Apr 19, 12:44 pm, Mark Carter alt.mcar...@gmail.com wrote:

 url and say just use the cookie that I have in Firefox?

 mechanize looks kinda like what I want, but i still can't get it to
 work properly. So far I have:

 import cookielib
 import mechanize

 cookiefile = C:\\Users\\$ME\\AppData\\Roaming\\Mozilla\\Firefox\
 \Profiles\\zl648qvt.default\\cookies.sqlite
 cookies = mechanize.MozillaCookieJar(filename = cookiefile,
 delayload=True)
snip
 where $ME and $URL are replaced with suitable values. It doesn't
 appear to acutally be using the cookies.

http://wwwsearch.sourceforge.net/mechanize/doc.html :
Firefox since version 3 persists cookies in an sqlite database, which
is not supported by MozillaCookieJar.

Please see my prior response.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Equivalent code to the bool() built-in function

2011-04-19 Thread Westley Martínez
On Tue, 2011-04-19 at 19:00 +1000, Chris Angelico wrote:
 On Tue, Apr 19, 2011 at 6:43 PM, Steven D'Aprano
 steve+comp.lang.pyt...@pearwood.info wrote:
  but I don't see how
 
  (arbitrary expression) + (another expression) + ... + (last expression)
 
  can have any guarantees applied. I mean, you can't even guarantee that
  they won't raise an exception. Can you explain what you mean?
 
 What Christian posted isn't something I've often done, but here's
 something slightly different that exploits the same
 comparisons-return-summable-values concept:
 
 A condition with N subconditions is deemed to be satisfied if a
 minimum of M of them are true. This is a general case of the boolean
 Or (N = 2, M = 1) and And (N = 2, M = 2), but does not have a direct
 equivalent in binary operators. You simply sum the subconditions,
 compare against M, and you have your answer.
 
 if (((port1024) + (!ip.startswith(192.168.)) +
 (greylist[ip]time()) + (++spewcnt10))=3) // flag this packet as
 suspicious
 
 Contrived example as I don't recall any specifics right now, but this
 will pick up any packets where three or more of the conditions are
 met. Useful only in fairly specific situations, but I don't know of
 any way to do this with just AND/OR/NOT that would be as clear and
 simple.
 
 Chris Angelico

Exclusive or:
 if not (True and False and False and False) or
   (False and True and False and False) or
   (False and False and True and False) or
   (False and False and False and True):
... print(True)

Maybe a little silly.

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


Re: installing setuptools on Windows custom python install

2011-04-19 Thread Eric Frederich
I do not have a DLLs folder.
I created this installation of Python myself since I needed it built
with Visual Studio 2005.
I followed instructions under PC\readme.txt
This file mentioned nothing about a DLLs folder.

From PC\readme.txt .

The best installation strategy is to put the Python executable (and
DLL, for Win32 platforms) in some convenient directory such as
C:/python, and copy all library files and subdirectories (using XCOPY)
to C:/python/lib.

I see that there is a _socket project in the Visual Studio solution.
I built this manually and copied the _socket.pyx file do a manually
created DLLs folder.
This seems to have worked but it bothers me that there is no mention
of this stuff in the readme.txt file.

The readme file did mention that there is a config.c file that I am to
edit to enable other modules.
If I added a call to init_socket() in this file would the socket
library then be built into the main dll file?
I'm not sure exactly how to use this config.c file.

Thanks,
~Eric

On Mon, Apr 18, 2011 at 2:30 PM, Wolfgang Rohdewald
wolfg...@rohdewald.de wrote:
 On Montag 18 April 2011, Eric Frederich wrote:
   File F:\My_Python27\lib\socket.py, line 47, in module
     import _socket
 ImportError: No module named _socket

 F:\pyside\setuptools-0.6c11

 I have C:\Python27

 and within that, DLLS\_socket.pyd

 this is what import _socket should find

 do you have that?

 --
 Wolfgang

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


Re: How to create a (transparent) decorator with status information?

2011-04-19 Thread Ian Kelly
On Tue, Apr 19, 2011 at 1:12 AM, Timo Schmiade the_...@gmx.de wrote:
 Just one question remains now: What is a Borg in this context?

http://code.activestate.com/recipes/66531/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Equivalent code to the bool() built-in function

2011-04-19 Thread Grant Edwards

On Tue, Apr 19, 2011 at 7:09 AM, Christian Heimes li...@cheimes.de wrote:
 Am 18.04.2011 21:58, schrieb John Nagle:
 ?? ?? This is typical for languages which backed into a bool type,
 rather than having one designed in. ??The usual result is a boolean
 type with numerical semantics, like

 ?? True + True
 2

 I find the behavior rather useful. It allows multi-xor tests like:

 if a + b + c + d != 1:
 ?? ??raise ValueError(Exactly one of a, b, c or d must be true.)

I guess I never thought about it, but there isn't an 'xor' operator to
go along with 'or' and 'and'.  Must not be something I need very often.

-- 
Grant Edwards   grant.b.edwardsYow! I am having FUN...
  at   I wonder if it's NET FUN or
  gmail.comGROSS FUN?
-- 
http://mail.python.org/mailman/listinfo/python-list


multiple Python 2.7 Windows installations

2011-04-19 Thread Eric Frederich
Hello,

I am trying to get an installer built with distutils to recognize
multiple installations.
The installer currently finds my installation at C:\Python27
I have a custom Python27 built myself with Visual Studio sitting
somewhere else, say C:\MyPython27.

I looked at PC/bdist_wininst/install.c in the GetPythonVersions
routine and see that it is searching Software\Python\PythonCore.

So, I assume I need to get my Python installation listed in the registry.
I am unfamiliar with the Windows Registry
I tried to create another 2.7 key but regedit wouldn't let me.
So, if I can only have one 2.7 key, it would seem that the routine
GetPythonVersions will only ever get 1 version of 2.7.
Does this mean that it is unsupported to have more than one Python 2.7
installation on Windows?

Again, that GetPythonVersions routine looks pretty alien to me so
I may be wrong.

Some help please?

Thanks,
~Eric
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Namespaces in functions vs classes

2011-04-19 Thread Gerald Britton
Ethan -- I'm just getting back to this question.  If you recall, you asked:

[snip]

8
script with possible name clashes

eggs = 'scrambled eggs'
meat = 'steak'

class Breakfast():
 meat = 'spam'
 def serve(self):
 print(Here's your %s and %s! %
(eggs, meat))

Breakfast().serve()
8

What will serve print?

Well, I think it should print the same thing as:

def Breakfast():
meat = 'spam'
def serve(self):
print(Here's your %s and %s! %
   (eggs, meat))
return serve(None)

Breakfast()

but it doesn't!  The function definition uses the local (to the
function) variable meat, whereas the class method uses the global
definition of meat.  The class attribute meat is not seen by the
serve method unless it is qualified.  I now understand the Python does
not consider a class definition as a separate namespace as it does for
function definitions.  That is a helpful understanding.

Anyway, thanks for jumping in to the discussion.

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


Re: How to create a (transparent) decorator with status information?

2011-04-19 Thread Timo Schmiade
On Tue, Apr 19, 2011 at 08:20:05AM -0600, Ian Kelly wrote:
 On Tue, Apr 19, 2011 at 1:12 AM, Timo Schmiade the_...@gmx.de wrote:
  Just one question remains now: What is a Borg in this context?
 
 http://code.activestate.com/recipes/66531/
 -- 
 http://mail.python.org/mailman/listinfo/python-list

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


Noob Question

2011-04-19 Thread Rob McGillivray
Hi All,

I'm new to Python, and trying to get python 3.2 installed on Centos 5.6. When I 
run 'make test', I receive several errors. The readme states that you can 
generally ignore messages about skipped tests, but as you can see below, some 
of the tests failed and a number were 'unexpected skips', so I'm not sure if I 
can go ahead with the install or need to perform further troubleshooting.

The output of 'make test' is shown below:

313 tests OK.
5 tests failed:
test_argparse test_distutils test_httpservers test_import
test_zipfile
31 tests skipped:
test_bz2 test_codecmaps_cn test_codecmaps_hk test_codecmaps_jp
test_codecmaps_kr test_codecmaps_tw test_curses test_dbm_gnu
test_dbm_ndbm test_gdb test_gzip test_kqueue test_ossaudiodev
test_readline test_smtpnet test_socketserver test_sqlite test_ssl
test_startfile test_tcl test_timeout test_tk test_ttk_guionly
test_ttk_textonly test_urllib2net test_urllibnet test_winreg
test_winsound test_xmlrpc_net test_zipfile64 test_zlib
11 skips unexpected on linux2:
test_bz2 test_dbm_gnu test_dbm_ndbm test_gzip test_readline
test_ssl test_tcl test_tk test_ttk_guionly test_ttk_textonly
test_zlib
sys:1: ResourceWarning: unclosed file _io.TextIOWrapper name='/dev/null' 
mode='a' encoding='UTF-8'
make: *** [test] Error 1

Any help would be appreciated. Apologies if this post is to the wrong group. If 
so, please advise the appropriate group.

Thanks in advance,

Rob

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


Fatal Python Error Need Help

2011-04-19 Thread Yogesh Gupta
Hello,

I am trying to run a python based program on MacOSX, which needs following
packages

numpy
PIL
matplotlib

I can successfully import all 3 using python2.5 (only using /sw64/bin/python
or /sw64/bin/python2.5) , although i have python2.6 and 2.7 installed. I get
following error when in run executable:

*Fatal Python error: Interpreter not initialized (version mismatch?)
Abort trap*

Seems like a correct python version needs to be defined somewhere, that i am
unable to find.

Some details about location of various pythons are as follows (i have not
specified a python path in my .bashrc or .bash_profile):

*$which python*
/sw64/bin/python

*$ ls -ltr /sw64/bin/python**
-rwxr-xr-x  1 root  admin  1763200 Apr 14 19:45 /sw64/bin/python2.5
-rwxr-xr-x  1 root  admin 1419 Apr 14 19:45 /sw64/bin/python2.5-config
-rwxr-xr-x  1 root  admin 8984 Apr 14 19:47 /sw64/bin/python2.6
-rwxr-xr-x  1 root  admin 1366 Apr 14 19:47 /sw64/bin/python2.6-config
-rwxr-xr-x  1 root  admin 8984 Apr 14 19:49 /sw64/bin/python2.7
-rwxr-xr-x  1 root  admin 1550 Apr 14 19:50 /sw64/bin/python2.7-config
lrwxr-xr-x  1 root  admin9 Apr 15 18:17 /sw64/bin/python -
python2.5
lrwxr-xr-x  1 root  admin   16 Apr 15 18:17 /sw64/bin/python-config -
python2.5-config

*$ls -ltr /System/Library/Frameworks/Python.framework/Versions*
drwxr-xr-x   8 root  wheel  272 Jun  7  2010 2.3
drwxr-xr-x  12 root  wheel  408 Nov 30 13:46 2.5
drwxr-xr-x  12 root  wheel  408 Nov 30 13:46 2.6
lrwxr-xr-x   1 root  wheel3 Apr 19 11:20 Current - 2.5

*$ls -ltr /usr/bin/python**
-rwxr-xr-x  5 root  wheel925 Jul  9  2009 /usr/bin/python-config
lrwxr-xr-x  1 root  wheel 76 Jun  7  2010 /usr/bin/pythonw2.6 -
../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6
lrwxr-xr-x  1 root  wheel 76 Jun  7  2010 /usr/bin/pythonw2.5 -
../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5
lrwxr-xr-x  1 root  wheel 82 Jun  7  2010 /usr/bin/python2.6-config -
../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
lrwxr-xr-x  1 root  wheel 75 Jun  7  2010 /usr/bin/python2.6 -
../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x  1 root  wheel 82 Jun  7  2010 /usr/bin/python2.5-config -
../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
lrwxr-xr-x  1 root  wheel 75 Jun  7  2010 /usr/bin/python2.5 -
../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
-rwxr-xr-x  2 root  wheel  86000 Jun 25  2010 /usr/bin/pythonw
-rwxr-xr-x  2 root  wheel  86000 Jun 25  2010 /usr/bin/python


Could someone point me to a solution?

Thanks so much for your time.

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


Re: Equivalent code to the bool() built-in function

2011-04-19 Thread Jean-Paul Calderone
On Apr 19, 10:23 am, Grant Edwards inva...@invalid.invalid wrote:
 On Tue, Apr 19, 2011 at 7:09 AM, Christian Heimes li...@cheimes.de wrote:
  Am 18.04.2011 21:58, schrieb John Nagle:
  ?? ?? This is typical for languages which backed into a bool type,
  rather than having one designed in. ??The usual result is a boolean
  type with numerical semantics, like

  ?? True + True
  2

  I find the behavior rather useful. It allows multi-xor tests like:

  if a + b + c + d != 1:
  ?? ??raise ValueError(Exactly one of a, b, c or d must be true.)

 I guess I never thought about it, but there isn't an 'xor' operator to
 go along with 'or' and 'and'.  Must not be something I need very often.


You also can't evaluate xor without evaluating both operands, meaning
there
is never a short-circuit; both and and or can short-circuit, though.
Also
boolean xor is the same as !=.

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


Re: Fatal Python Error Need Help

2011-04-19 Thread Ned Deily
In article banlktimr2goozgoxstobjf5jur+3cxg...@mail.gmail.com,
 Yogesh Gupta yogesh.gupt...@gmail.com wrote:
 I am trying to run a python based program on MacOSX, which needs following
 packages
 
 numpy
 PIL
 matplotlib
 
 I can successfully import all 3 using python2.5 (only using /sw64/bin/python
 or /sw64/bin/python2.5) , although i have python2.6 and 2.7 installed. I get
 following error when in run executable:
 
 *Fatal Python error: Interpreter not initialized (version mismatch?)
 Abort trap*
 
 Seems like a correct python version needs to be defined somewhere, that i am
 unable to find.

No, you have a more serious problem.  From the paths displayed, I'm 
guessing you used Fink to install those Pythons and packages.  You may 
want to ask on the Fink mailing lists or IRC channel.

http://www.finkproject.org/help/index.php?phpLang=en

-- 
 Ned Deily,
 n...@acm.org

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


Re: Namespaces in functions vs classes

2011-04-19 Thread Ethan Furman

Gerald Britton wrote:

I now understand the Python does
not consider a class definition as a separate namespace as it does for
function definitions.  That is a helpful understanding.


That is not correct.  Classes are separate namespaces -- they just 
aren't automatically searched.  The only namespaces that are 
automatically searched are local, non-local, global, and built-in.


Similarly, if you have a dictionary of values

-- d = {'eggs':'green', 'method':'train'}

then 'd' is a namespace, but if you're function/method/whatever just tries:

-- if method == 'boat':
-- blah()

then you'll get a NameError because the 'd' namespace will not be 
automatically searched.  You would have to do:


-- if d['method'] == 'boat':
-- blah()

to find the variable in that namespace.

Hope this helps.

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


Re: who moved reload?

2011-04-19 Thread Calvin Spealman
I have a great solution : stop using reload. It often dangerous and more
often silly.

On Apr 7, 2011 5:44 AM, harrismh777 harrismh...@charter.net wrote:

All right...  somebody is sacked (er, fired) !

Who moved reload()?

This kinda stuff is driving me bonkers... there was no need to move reload()
anyplace...

... so for those of you who haven't found out yet, if you want to reload a
module in 3.x you have to import reload() first from module 'imp' ... now
that is just plain wrong.  :-}


import mymod

from imp import reload
reload(mymod)= now reload() will work.



Somebody out there thinks this is funny, right?

 reload(mymod)
Traceback (most recent call last):
 File pyshell#1, line 1, in module
   reload(mymod)
NameError: name 'reload' is not defined  ???




regards,
m harris
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Namespaces in functions vs classes

2011-04-19 Thread Gerald Britton
Gerald Britton wrote:
 I now understand the Python does
 not consider a class definition as a separate namespace as it does for
 function definitions.  That is a helpful understanding.

That is not correct.  Classes are separate namespaces -- they just
aren't automatically searched.  The only namespaces that are
automatically searched are local, non-local, global, and built-in.

I see you misunderstood my observation:  Python does not consider a class
definition as a separate namespace *as it does* for function definitions.

Of course classes are separate namespaces, or they would not work at
all.  However,
Python does not automatically search class namespaces -- even within the class
definition -- *as it does* within function definitions.

That is the key insight I was seeking.  To search a class namespace one must
qualify the lookup with the class or instance name.
-- 
http://mail.python.org/mailman/listinfo/python-list


3.2 test failures on Centos 5.6 (was Re: Noob Question)

2011-04-19 Thread Terry Reedy

On 4/19/2011 10:55 AM, Rob McGillivray wrote:


I'm new to Python, and trying to get python 3.2 installed on Centos
5.6. When I run 'make test', I receive several errors.


Welcome to Python.

Newbie lesson 1: write an informative subject line that will catch the 
attention of people who can answer. (I just happened to open this 
because it is a slow day so far ;-).) Example:

  3.2 test failures on Centos 5.6
If you do not get any better answer than I can provide, I suggest 
reposting with that subject (my changed line will not be visible to some 
who have threads collapsed).


Lesson 2: provide all relevant info needed to answer. You did pretty 
good, except: What are you trying to install? A public binary built by 
someone else for Centos? Or one *you* compiled? If the latter, did you 
use the official 3.2 source from the site or the latest 3.2.x source 
from the hg repository? (If either, I suggest trying the other.)


 The readme

states that you can generally ignore messages about skipped tests,
but as you can see below, some of the tests failed and a number were
'unexpected skips', so I'm not sure if I can go ahead with the
install or need to perform further troubleshooting.


I have never built Python or used it on *nix, but I will give some 
informed guesses ;-).



The output of 'make test' is shown below:

5 tests failed: test_argparse test_distutils
test_httpservers test_import test_zipfile


You need to run each of these in verbose mode to see who severe the 
failure is. Test_import would be of most concern to me.


 11 skips

unexpected on linux2: test_bz2 test_dbm_gnu test_dbm_ndbm test_gzip
test_readline test_ssl test_tcl test_tk test_ttk_guionly
test_ttk_textonly test_zlib


These look like things with 3rd party dependencies. tcl/tk/ttk tests 
depend on finding tcl/tk installed. If you do not want to use the 
modules, no problem. If you do,


 sys:1: ResourceWarning: unclosed

file_io.TextIOWrapper name='/dev/null' mode='a' encoding='UTF-8'
make: *** [test] Error 1


This is a bug either in some test or in the Python shutdown procedure, 
at least after running the tests. There were other things like this 
fixed near the end of 3.2 development and it may be fixed now.



Any help would be appreciated. Apologies if this post is to the wrong
group. If so, please advise the appropriate group.


Right place to start. If there are Centos specific issues, you might 
want to look for a Centos list.


--
Terry Jan Reedy

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


Re: Namespaces in functions vs classes

2011-04-19 Thread Ian Kelly
On Tue, Apr 19, 2011 at 10:31 AM, Ethan Furman et...@stoneleaf.us wrote:
 Gerald Britton wrote:

 I now understand the Python does
 not consider a class definition as a separate namespace as it does for
 function definitions.  That is a helpful understanding.

 That is not correct.  Classes are separate namespaces -- they just aren't
 automatically searched.  The only namespaces that are automatically searched
 are local, non-local, global, and built-in.

The problem is that they are treated differently at run-time.  A
function namespace is compiled into a collection of local variable
names and closures, and it is effectively immutable.  This is
necessary in order to generate the correct bytecode for each type of
storage location.  A class namespace ultimately becomes a dict, and it
is a key feature that these be mutable.  However, this means that a
class namespace can't have closures.
-- 
http://mail.python.org/mailman/listinfo/python-list


What breaks if I remove lib/python2.7/test/* ?

2011-04-19 Thread cjblaine
What breaks if I remove lib/python2.7/test/* ?  What purpose does it serve?

It is 26MB for me.

I am trying to trim my Python install for good reason.

Thanks for any info!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Namespaces in functions vs classes

2011-04-19 Thread Terry Reedy

On 4/19/2011 10:58 AM, Gerald Britton wrote:


serve method unless it is qualified.  I now understand the Python does
not consider a class definition as a separate namespace as it does for
function definitions.


Class namespaces are separate namespaces but not in the same way as for 
functions. Class bodies are executed, once, in the new class namespace 
when the class statement is executed. That new namespace is then 
attached to the new class object. Function bodies are not executed when 
the function statement is executed, but are merely compiled for repeated 
execution later, when the function is called.


It might help to know:

1. In early Python, nested functions could *not* access the namespace of 
enclosing functions.


2. Functions do not *belong* to a particular class. The following two 
snippets are equivalent:


a = 'out'
class C:
a = 'in'
def f():
print(C.a)
C.f()
# prints 'in'

a = 'out'
class C:
a = 'in'
def f():
print(C.a)
C.f = f
C.f()
#prints 'in'


3. Default argument expressions *are* executed in the namespace where 
the def statement appears. The following two snippets are *not* equivalent


a = 'out'
class C:
a = 'in'
def f(x=a): print(x)
C.f()
# prints 'in'

a = 'out'
class C:
a = 'in'
def f(x=a): print(x)
C.f = f
C.f()
# prints 'out'


--
Terry Jan Reedy

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


Re: What breaks if I remove lib/python2.7/test/* ?

2011-04-19 Thread Terry Reedy

On 4/19/2011 1:06 PM, cjblaine wrote:

What breaks if I remove lib/python2.7/test/* ?  What purpose does it serve?


It allows you to run the test suite. Some people like to run it when 
they install. Or they may run a module test if they have a problem with 
a specific module or edit the Python code. Otherwise, delete it.



It is 26MB for me.


11 mb on windows, which is still sizable in some contexts.

--
Terry Jan Reedy

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


RE: 3.2 test failures on Centos 5.6 (was Re: Noob Question)

2011-04-19 Thread Rob McGillivray
Hi Terry,

Much appreciate the pointers! :-)

I am trying to install from an RPM downloaded from python.org. I'm pretty new 
to Linux etc (very pleased to be finally getting into the wide world of OSS), 
so I'm double-challenged on a number of fronts right now.

I will run the failed tests in verbose mode as you recommended and then re-post 
my findings.

Again, appreciate the friendly welcome. :-)

Regards,

Rob


-Original Message-
From: python-list-bounces+rob=mymcgillivray@python.org 
[mailto:python-list-bounces+rob=mymcgillivray@python.org] On Behalf Of 
Terry Reedy
Sent: Tuesday, April 19, 2011 12:59 PM
To: python-list@python.org
Subject: 3.2 test failures on Centos 5.6 (was Re: Noob Question)

On 4/19/2011 10:55 AM, Rob McGillivray wrote:

 I'm new to Python, and trying to get python 3.2 installed on Centos 
 5.6. When I run 'make test', I receive several errors.

Welcome to Python.

Newbie lesson 1: write an informative subject line that will catch the 
attention of people who can answer. (I just happened to open this because it is 
a slow day so far ;-).) Example:
   3.2 test failures on Centos 5.6
If you do not get any better answer than I can provide, I suggest reposting 
with that subject (my changed line will not be visible to some who have threads 
collapsed).

Lesson 2: provide all relevant info needed to answer. You did pretty good, 
except: What are you trying to install? A public binary built by someone else 
for Centos? Or one *you* compiled? If the latter, did you use the official 3.2 
source from the site or the latest 3.2.x source from the hg repository? (If 
either, I suggest trying the other.)

  The readme
 states that you can generally ignore messages about skipped tests, but 
 as you can see below, some of the tests failed and a number were 
 'unexpected skips', so I'm not sure if I can go ahead with the install 
 or need to perform further troubleshooting.

I have never built Python or used it on *nix, but I will give some informed 
guesses ;-).

 The output of 'make test' is shown below:

 5 tests failed: test_argparse test_distutils test_httpservers 
 test_import test_zipfile

You need to run each of these in verbose mode to see who severe the failure is. 
Test_import would be of most concern to me.

  11 skips
 unexpected on linux2: test_bz2 test_dbm_gnu test_dbm_ndbm test_gzip 
 test_readline test_ssl test_tcl test_tk test_ttk_guionly 
 test_ttk_textonly test_zlib

These look like things with 3rd party dependencies. tcl/tk/ttk tests depend on 
finding tcl/tk installed. If you do not want to use the modules, no problem. If 
you do,

  sys:1: ResourceWarning: unclosed
 file_io.TextIOWrapper name='/dev/null' mode='a' encoding='UTF-8'
 make: *** [test] Error 1

This is a bug either in some test or in the Python shutdown procedure, at least 
after running the tests. There were other things like this fixed near the end 
of 3.2 development and it may be fixed now.

 Any help would be appreciated. Apologies if this post is to the wrong 
 group. If so, please advise the appropriate group.

Right place to start. If there are Centos specific issues, you might want to 
look for a Centos list.

--
Terry Jan Reedy

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

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


force --install-layout=deb on systems where that makes sense?

2011-04-19 Thread Lee Harr

Is there a way to make distutils use --install-layout=deb
but only on systems where that makes sense?

I just noticed that if someone installs without that switch,
my app will not be able to find its data files, because
sys.prefix = /usr  but the installation is actually in to
/usr/local


I suppose most people here will advise that I abandon
distutils and use something more reasonable. I am open
to that, but I went down this path because of stdeb and
the ability to do python setup.py bdist_deb
So if you can suggest some method that can also generate
a .deb file easily I am listening.

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


Pickling over a socket

2011-04-19 Thread Roger Alexander
Hi,

I'm trying to understand how to pickle Python objects over a TCP
socket.

In the example below (based on code from Foundations of Python Network
Programming), a client creates a dictionary (lines 34-38) and uses
pickle.dump at line 42 to write the pickled object using file handle
make from a socket. The server de-pickles with pickle.load  (line 24),
again using a file handle made from a socket.

When I run the program, the following output is produced:

Listening at ('127.0.0.1', 1060)
Accepted connection from ('127.0.0.1', 49938)
Traceback (most recent call last):
File pickles.py, line 24, in module
d = pickle.load( s_fh )
File /usr/local/lib/python2.7/pickle.py, line 1378, in load
return Unpickler(file).load()
File /usr/local/lib/python2.7/pickle.py, line 857, in load
key = read(1)
File /usr/local/lib/python2.7/socket.py, line 380, in read
data = self._sock.recv(left)
socket.error: [Errno 107] Transport endpoint is not connected

I'm at a loss, can anyone provide any guidance?

Thanks,

Roger Alexander

 1  import pickle
 2  import socket, sys
 3
 4  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 5
 6  HOST = sys.argv.pop() if len(sys.argv) == 3 else '127.0.0.1'
 7  PORT = 1060
 8
 9  if sys.argv[1:] == ['server']:
10
11  s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
12  s.bind((HOST, PORT))
13  s.listen(1)
14
15  print 'Listening at', s.getsockname()
16
17  sc, sockname = s.accept()
18
19  print 'Accepted connection from', sockname
20
21  sc.shutdown(socket.SHUT_WR)
22  sf = s.makefile( rb )
23
24  d = pickle.load(sf)
25
26  sc.close()
27  s.close()
28
29  elif sys.argv[1:] == ['client']:
30
31  s.connect((HOST, PORT))
32  s.shutdown(socket.SHUT_RD)
33
34  d = dict()
35
36  d[ 'Name' ] = 'Jake Thompson.'
37  d[ 'Age' ]  = 25
38  d[ 'Location' ] = 'Washington, D.C.'
39
40  sf = s.makefile( wb )
41
42  pickle.dump( d, sf, pickle.HIGHEST_PROTOCOL )
43
44  s.close()
45
46  else:
47  print sys.stderr, 'usage: streamer.py server|client [host]'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 3.2 test failures on Centos 5.6 (was Re: Noob Question)

2011-04-19 Thread Terry Reedy

On 4/19/2011 1:33 PM, Rob McGillivray wrote:


I am trying to install from an RPM downloaded from python.org.


That puzzles me. For *nix, I do not see .rpm, just tarballs, on
http://python.org/download/releases/3.2/

--
Terry Jan Reedy

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


Re: Noob Question

2011-04-19 Thread Dan Stromberg
On Tue, Apr 19, 2011 at 7:55 AM, Rob McGillivray
r...@motornostixusa.com wrote:
 Hi All,

 I'm new to Python, and trying to get python 3.2 installed on Centos 5.6. When 
 I run 'make test', I receive several errors. The readme states that you can 
 generally ignore messages about skipped tests, but as you can see below, some 
 of the tests failed and a number were 'unexpected skips', so I'm not sure if 
 I can go ahead with the install or need to perform further troubleshooting.

I'm guessing you need to install development versions of the various
libraries on which these modules depend.  If they aren't detected
during  configure, they probably won't be built.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickling over a socket

2011-04-19 Thread Chris Rebert
On Tue, Apr 19, 2011 at 11:53 AM, Roger Alexander rtalexan...@mac.com wrote:
 Hi,

 I'm trying to understand how to pickle Python objects over a TCP
 socket.

 In the example below (based on code from Foundations of Python Network
 Programming), a client creates a dictionary (lines 34-38) and uses
 pickle.dump at line 42 to write the pickled object using file handle
 make from a socket. The server de-pickles with pickle.load  (line 24),
 again using a file handle made from a socket.

 When I run the program, the following output is produced:

    Listening at ('127.0.0.1', 1060)
    Accepted connection from ('127.0.0.1', 49938)
    Traceback (most recent call last):
    File pickles.py, line 24, in module
        d = pickle.load( s_fh )
    File /usr/local/lib/python2.7/pickle.py, line 1378, in load
        return Unpickler(file).load()
    File /usr/local/lib/python2.7/pickle.py, line 857, in load
        key = read(1)
    File /usr/local/lib/python2.7/socket.py, line 380, in read
        data = self._sock.recv(left)
    socket.error: [Errno 107] Transport endpoint is not connected

 I'm at a loss, can anyone provide any guidance?

 Thanks,

 Roger Alexander

  1  import pickle
  2  import socket, sys
  3
  4  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  5
  6  HOST = sys.argv.pop() if len(sys.argv) == 3 else '127.0.0.1'
  7  PORT = 1060
  8
  9  if sys.argv[1:] == ['server']:
 10
 11      s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 12      s.bind((HOST, PORT))
 13      s.listen(1)
 14
 15      print 'Listening at', s.getsockname()
 16
 17      sc, sockname = s.accept()
 18
 19      print 'Accepted connection from', sockname
 20
 21      sc.shutdown(socket.SHUT_WR)

[Haven't done any network programming, so please excuse the naivete of
this suggestion.]

Have you tried removing line #21 and/or #32?

http://docs.python.org/library/socket.html#socket.socket.shutdown :
socket.shutdown(how) - Shut down one or both halves of the
connection. [...] Depending on the platform, shutting down one half of
the connection can also close the opposite half

Cheers,
Chris
--
http://blog.rebertia.com

 22      sf = s.makefile( rb )
 23
 24      d = pickle.load(sf)
 25
 26      sc.close()
 27      s.close()
 28
 29  elif sys.argv[1:] == ['client']:
 30
 31      s.connect((HOST, PORT))
 32      s.shutdown(socket.SHUT_RD)
snip
 42      pickle.dump( d, sf, pickle.HIGHEST_PROTOCOL )
 43
 44      s.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickling over a socket

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 4:53 AM, Roger Alexander rtalexan...@mac.com wrote:
 Hi,

 I'm trying to understand how to pickle Python objects over a TCP
 socket.

 In the example below (based on code from Foundations of Python Network
 Programming), a client creates a dictionary (lines 34-38) and uses
 pickle.dump at line 42 to write the pickled object using file handle
 make from a socket. The server de-pickles with pickle.load  (line 24),
 again using a file handle made from a socket.

Whenever there's a problem, create simplicity. I would recommend not
using the file-from-socket method, and simply using pickle.dumps() and
pickle.loads() to pickle to/from strings; those strings can then be
sent/received over the socket using standard recv/send functions.

Also, Chris Rebert's idea is a good one, and worth trying.

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


Re: Pickling over a socket

2011-04-19 Thread Dan Stromberg
On Tue, Apr 19, 2011 at 11:53 AM, Roger Alexander rtalexan...@mac.com wrote:
 Hi,

 I'm trying to understand how to pickle Python objects over a TCP
 socket.

 In the example below (based on code from Foundations of Python Network
 Programming), a client creates a dictionary (lines 34-38) and uses
 pickle.dump at line 42 to write the pickled object using file handle
 make from a socket. The server de-pickles with pickle.load  (line 24),
 again using a file handle made from a socket.

 When I run the program, the following output is produced:

    Listening at ('127.0.0.1', 1060)
    Accepted connection from ('127.0.0.1', 49938)
    Traceback (most recent call last):
    File pickles.py, line 24, in module
        d = pickle.load( s_fh )
    File /usr/local/lib/python2.7/pickle.py, line 1378, in load
        return Unpickler(file).load()
    File /usr/local/lib/python2.7/pickle.py, line 857, in load
        key = read(1)
    File /usr/local/lib/python2.7/socket.py, line 380, in read
        data = self._sock.recv(left)
    socket.error: [Errno 107] Transport endpoint is not connected

 I'm at a loss, can anyone provide any guidance?

 Thanks,

 Roger Alexander

I played around with it until something worked, and ended up with the
below.  The most significant change was probably using sc.makefile
instead of s.makefile in the server, but I seemed to need some data
framing too despite the pickling.  It's possible you won't need that
if you just flush your file in the client; I don't much pickling
experience - in particular, I don't know if you can concatenate
pickled objects and load them serially from a file-like object without
any (additional) framing.

I like to use bufsock for this sort of stuff, but I'm probably unique
in that.  ^_^   http://stromberg.dnsalias.org/~strombrg/bufsock.html

#!/usr/bin/python

import time
import pickle
import socket, sys
import pprint

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

HOST = sys.argv.pop() if len(sys.argv) == 3 else '127.0.0.1'
PORT = 1060

if sys.argv[1:] == ['server']:

s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
s.listen(1)

print 'Listening at', s.getsockname()

sc, sockname = s.accept()

print 'Accepted connection from', sockname

sf = sc.makefile( rb )

length_list = []
while True:
char = sf.read(1)
if char == '\n':
break
else:
length_list.append(int(char))
length = 0
for digit in length_list:
length = length * 10 + digit
data = sf.read(length)

d = pickle.loads(data)

pprint.pprint(d)

sc.shutdown(socket.SHUT_RDWR)
sc.close()
s.close()

elif sys.argv[1:] == ['client']:

s.connect((HOST, PORT))
# s.shutdown(socket.SHUT_RD)

d = dict()

d[ 'Name' ] = 'Jake Thompson.'
d[ 'Age' ]  = 25
d[ 'Location' ] = 'Washington, D.C.'

sf = s.makefile( wb )

string = pickle.dumps( d, pickle.HIGHEST_PROTOCOL )
sf.write('%d\n' % len(string))
sf.write(string)
sf.flush()

#time.sleep(10)
sf.close()
s.shutdown(socket.SHUT_RDWR)
# s.close()

else:
print sys.stderr, 'usage: streamer.py server|client [host]'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickling over a socket

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 5:30 AM, Dan Stromberg drsali...@gmail.com wrote:
 I played around with it until something worked, and ended up with the
 below.  The most significant change was probably using sc.makefile
 instead of s.makefile in the server...

Oh! I didn't notice that in the OP. Yep, that would do it!

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


Re: Noob Question

2011-04-19 Thread Felipe Bastos Nunes
Yes, Dan is right, it looked for the sources, and you have only binaries on
your system. Look in your distribution repositories for the *-devel or alike
for the 5 that failed and try again.

2011/4/19 Dan Stromberg drsali...@gmail.com

 On Tue, Apr 19, 2011 at 7:55 AM, Rob McGillivray
 r...@motornostixusa.com wrote:
  Hi All,
 
  I'm new to Python, and trying to get python 3.2 installed on Centos 5.6.
 When I run 'make test', I receive several errors. The readme states that you
 can generally ignore messages about skipped tests, but as you can see below,
 some of the tests failed and a number were 'unexpected skips', so I'm not
 sure if I can go ahead with the install or need to perform further
 troubleshooting.

 I'm guessing you need to install development versions of the various
 libraries on which these modules depend.  If they aren't detected
 during  configure, they probably won't be built.
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Felipe Bastos Nunes
-- 
http://mail.python.org/mailman/listinfo/python-list


optparse eats $

2011-04-19 Thread tazz_ben
So, I'm using optparse as follows:

Command line:
python expense.py $100 -f ~/desktop/test.txt
['00']


In Main:

desc = ''
p = optparse.OptionParser(description=desc)

utilities = optparse.OptionGroup(p, 'Utility Options')
utilities.add_option('--file', '-f', dest=file, help=Define the active file 
to analyze, default='', metavar='File Path')

(options, arguments) = p.parse_args()

print arguments  - What is becoming ['00']


So, any ideas?  Why is including a $ eating both the dollar signa and the 1?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: optparse eats $

2011-04-19 Thread John Gordon
In f315a5f9-b11a-48e8-b5ce-1e72dcabc...@glegroupsg2000goo.googlegroups.com 
tazz_ben b...@wbpsystems.com writes:

 So, any ideas?  Why is including a $ eating both the dollar signa and the 1?

Unix command lines tend to assume any $ inside double-quotes is a shell
variable name.  Try enclosing in single-quotes instead.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

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


Re: optparse eats $

2011-04-19 Thread Peter Otten
tazz_ben wrote:

 So, I'm using optparse as follows:
 
 Command line:
 python expense.py $100 -f ~/desktop/test.txt
 ['00']
 
 
 In Main:
 
 desc = ''
 p = optparse.OptionParser(description=desc)
 
 utilities = optparse.OptionGroup(p, 'Utility Options')
 utilities.add_option('--file', '-f', dest=file, help=Define the active
 file to analyze, default='', metavar='File Path')
 
 (options, arguments) = p.parse_args()
 
 print arguments  - What is becoming ['00']
 
 
 So, any ideas?  Why is including a $ eating both the dollar signa and the
 1?

It ain't optparse, it's your shell:

$ echo $100
00
$ echo '$100'
$100
$

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


Re: optparse eats $

2011-04-19 Thread Michael Kent
Try this on your *nix command line: echo $100

On a *nix command line, the '$1' part of $100 will be seen as 'give me the 
value of the shell variable 1', and since it has no value, will result in an 
empty string.  So it's not optparse, or Python, because the literal string you 
intend to pass as a command line argument to your Python script never has a 
chance of getting there.  Try escaping the '$' with a backslash on the command 
line.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANNOUNCE: wxPython 2.8.12.0

2011-04-19 Thread Robin Dunn

Announcing
--

The 2.8.12.0 release of wxPython is now available for download at
http://wxpython.org/download.php. This release has no major new
features or enhancements, but there have been plenty of bug fixes
since the last stable release.

Source code is available as a tarball, and binaries are also available
for Python 2.6 and 2.7, for Windows and Mac, as well some packages for
various Linux distributions in the wx apt repository.  Binaries for
Python 2.5 have been discontinued.



What is wxPython?
-

wxPython is a GUI toolkit for the Python programming language. It
allows Python programmers to create programs with a robust, highly
functional graphical user interface, simply and easily. It is
implemented as a Python extension module that wraps the GUI components
of the popular wxWidgets cross platform library, which is written in
C++.

wxPython is a cross-platform toolkit. This means that the same program
will usually run on multiple platforms without modifications.
Currently supported platforms are 32-bit and 64-bit Microsoft Windows,
most Linux or other Unix-like systems using GTK2, and Mac OS X 10.4+.
In most cases the native widgets are used on each platform to provide
a 100% native look and feel for the application.


--
Robin Dunn
Software Craftsman
http://wxPython.org

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


Re: What breaks if I remove lib/python2.7/test/* ?

2011-04-19 Thread Irmen de Jong
On 19-4-2011 19:06, cjblaine wrote:
 What breaks if I remove lib/python2.7/test/* ?  What purpose does it serve?
 
 It is 26MB for me.
 
 I am trying to trim my Python install for good reason.
 
 Thanks for any info!

Terry answered what it is for. Personally, I also once used some functions from
test.test_support in my own code. There's some handy stuff in there. Also, the 
venerable
Pystone lives in test.pystone.

However, I don't think the test/* stuff is actually considered to be part of the
standard library? I believe it becomes available on many Linux installations 
only after
installing the python-dev package (or similar). So my guess is that you are 
safe to
delete it if you really need the disk space.

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


Re: [ANN] Python 2.5.6 Release Candidate 1

2011-04-19 Thread Martin v. Loewis
 Thanks Martin, I'm glad these older releases are still getting important
 fixes. 
 
 I notice http://www.python.org/download/releases/2.5.6/NEWS.txt says the
 release date was 17 Apr 2010.  Presumably that should have said 2011.

Thanks for pointing it out. I fixed it in the repository, so it should
be fine in the final release.

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


Re: multiple Python 2.7 Windows installations

2011-04-19 Thread Martin v. Loewis
 I tried to create another 2.7 key but regedit wouldn't let me.
 So, if I can only have one 2.7 key, it would seem that the routine
 GetPythonVersions will only ever get 1 version of 2.7.
 Does this mean that it is unsupported to have more than one Python 2.7
 installation on Windows?

Exactly so - it's unsupported. There are ways around it, but they
require more familiarity with distutils and Windows internals.

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


Re: Namespaces in functions vs classes

2011-04-19 Thread Rhodri James
On Tue, 19 Apr 2011 17:47:40 +0100, Gerald Britton  
gerald.brit...@gmail.com wrote:



Gerald Britton wrote:

I now understand the Python does
not consider a class definition as a separate namespace as it does for
function definitions.  That is a helpful understanding.



That is not correct.  Classes are separate namespaces -- they just
aren't automatically searched.  The only namespaces that are
automatically searched are local, non-local, global, and built-in.


I see you misunderstood my observation:  Python does not consider a class
definition as a separate namespace *as it does* for function definitions.


This phrase normally parses as Python does not consider a class  
definition as a separate namespace.  In contrast, Python does consider a  
function definition as a separate namespace.  If you meant Python does  
not consider a class definition as a separate namespace *in the same way*  
that it does for function definitions, saying so would make life easier  
for the fairly large number of readers of this newsgroup whose first  
language isn't English.


Language abuse: it's not just Python.  A donation of just $5 will keep a  
programmer in prepositions for a month.  $50 will supply enough articles  
to keep a small company understandable for over a year.  With your  
generous help, we can beat this scourge!


Ahem.

Normal service will now be resumed.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Namespaces in functions vs classes

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 8:00 AM, Rhodri James
rho...@wildebst.demon.co.uk wrote:
 Language abuse: it's not just Python.  A donation of just $5 will keep a
 programmer in prepositions for a month.  $50 will supply enough articles to
 keep a small company understandable for over a year.  With your generous
 help, we can beat this scourge!

/me subscribes his pennies to this noble cause.

It's quite tragic, you know. There are people who have never known the
taste of real adjectives, being so linguistically impoverished that
they have to substitute profanity in their sentences. It's not just a
foreign tragedy. There are destitute persons right near us. Donate NOW
to end the hunger! All donations go 100% to the needy. *

Chris Angelico

* After processing fees and my cut, of course. Hey, these list
advertisements don't come free!
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem receiving UDP broadcast packets.

2011-04-19 Thread Grant Edwards
I'm have problems figuring out how to receive UDP broadcast packets on
Linux.

Here's the receiving code:

--receive.py---
#!/usr/bin/python
import socket

host = ''
port = 5010

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind((host, port))

while 1:
try:
message = s.recv(8192)
print Got data: %s % repr(message)
except KeyboardInterrupt:
break
--

Here's the sending code:

send.py---
#!/usr/bin/python
import sys,socket,time

host = sys.argv[1]
port = 5010

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.bind((host,port))

s.sendto(str(time.time()), ('255.255.255.255', port))
--


On the receiving machine, I've used tcpdump to verify that broadcast
packets are being seen and have a destination IP of 255.255.255.255 and
destination MAC of ff:ff:ff:ff:ff:ff

03:05:09.187327 IP 10.0.0.1.5010  255.255.255.255.5010: UDP, length 13
0x:     0018 e708 2033 0800 4500
0x0010:  0029  4000 4011 30c4 0a00 0001 
0x0020:   1392 1392 0015 6e6e 3133 3033 3235
0x0030:  3131 3830 2e34 3500 
03:05:09.407508 IP 10.0.0.1.5010  255.255.255.255.5010: UDP, length 13
0x:     0018 e708 2033 0800 4500
0x0010:  0029  4000 4011 30c4 0a00 0001 
0x0020:   1392 1392 0015 6c6c 3133 3033 3235
0x0030:  3131 3830 2e36 3700 
03:05:09.615962 IP 10.0.0.1.5010  255.255.255.255.5010: UDP, length 13
0x:     0018 e708 2033 0800 4500
0x0010:  0029  4000 4011 30c4 0a00 0001 
0x0020:   1392 1392 0015 6b6a 3133 3033 3235
0x0030:  3131 3830 2e38 3800 

But, the receiving Python program never sees any packets unless the
_source_ IP address in the packets is on the same subnet as the
receiving machine.  In this test case, the receiving machine has an IP
address of 172.16.12.34/16.  If I change the receiving machine's IP
address to 10.0.0.123, then the receiving program sees the packets.

Even though the destination address is 255.255.255.255, the receiving
machine appears to discard the packets based on the _source_ IP.  Can
anybody provide example Python code for Linux that receives UDP
broadcast packets regardless of their source IP address?

This probably is more of a Linux networking question than a Python
question, but I'm hoping somebody has solved this problem in Python.

-- 
Grant Edwards   grant.b.edwardsYow! I want my nose in
  at   lights!
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickling over a socket

2011-04-19 Thread Roger Alexander
Thanks everybody, got it working.

 I appreciate the help!

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


Teaching Python

2011-04-19 Thread Passiday
Hello,

I am planning to teach Python to a group of high school students, who have 
in-depth interest in programming, hacking etc.

I am looking for some good material, what I could use as a basic guide when 
preparing the classes plan for the course - website or book, what would roll 
out the topic methodologically gradually. The target audience is someone who 
knows most basics of the programming, but doesn't mind being reminded about 
them now and then.

Thanks for any suggestions!

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


Re: Teaching Python

2011-04-19 Thread geremy condra
On Tue, Apr 19, 2011 at 3:42 PM, Passiday passi...@gmail.com wrote:
 Hello,

 I am planning to teach Python to a group of high school students, who have 
 in-depth interest in programming, hacking etc.

 I am looking for some good material, what I could use as a basic guide when 
 preparing the classes plan for the course - website or book, what would roll 
 out the topic methodologically gradually. The target audience is someone who 
 knows most basics of the programming, but doesn't mind being reminded about 
 them now and then.

 Thanks for any suggestions!

When you say 'hacking', you mean ?

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


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Irmen de Jong
On 20-4-2011 0:21, Grant Edwards wrote:
 I'm have problems figuring out how to receive UDP broadcast packets on
 Linux.
 
[...]

 Here's the sending code:
 
 send.py---
 #!/usr/bin/python
 import sys,socket,time
 
 host = sys.argv[1]
 port = 5010
 
 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
 s.bind((host,port))

I don't think you should use s.bind() at all in the sending code.
Could that be at least part of the problem?


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


Re: Teaching Python

2011-04-19 Thread Dan Stromberg
On Tue, Apr 19, 2011 at 4:03 PM, geremy condra debat...@gmail.com wrote:
 On Tue, Apr 19, 2011 at 3:42 PM, Passiday passi...@gmail.com wrote:
 Hello,

 I am planning to teach Python to a group of high school students, who have 
 in-depth interest in programming, hacking etc.

 I am looking for some good material, what I could use as a basic guide when 
 preparing the classes plan for the course - website or book, what would roll 
 out the topic methodologically gradually. The target audience is someone who 
 knows most basics of the programming, but doesn't mind being reminded about 
 them now and then.

 Thanks for any suggestions!

 When you say 'hacking', you mean ?

Presumably he meant the real meaning of the word, not what the press
made up and ran with.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Grant Edwards
On 2011-04-19, Irmen de Jong irmen.nos...@xs4all.nl wrote:
 On 20-4-2011 0:21, Grant Edwards wrote:
 I'm have problems figuring out how to receive UDP broadcast packets on
 Linux.
 
 [...]

 Here's the sending code:
 
 send.py---
 #!/usr/bin/python
 import sys,socket,time
 
 host = sys.argv[1]
 port = 5010
 
 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
 s.bind((host,port))

 I don't think you should use s.bind() at all in the sending code.
 Could that be at least part of the problem?

If I don't call bind(), then the broadcast packets go out the wrong
interface on the sending machine.

-- 
Grant Edwards   grant.b.edwardsYow! Vote for ME -- I'm
  at   well-tapered, half-cocked,
  gmail.comill-conceived and
   TAX-DEFERRED!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Teaching Python

2011-04-19 Thread Dan Stromberg
On Tue, Apr 19, 2011 at 3:42 PM, Passiday passi...@gmail.com wrote:
 Hello,

 I am planning to teach Python to a group of high school students, who have 
 in-depth interest in programming, hacking etc.

 I am looking for some good material, what I could use as a basic guide when 
 preparing the classes plan for the course - website or book, what would roll 
 out the topic methodologically gradually. The target audience is someone who 
 knows most basics of the programming, but doesn't mind being reminded about 
 them now and then.

http://wiki.python.org/moin/BeginnersGuide/

That page has links to lists of tutorials that either assume you know
nothing about programming yet, or have some other languages under your
belt already.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Teaching Python

2011-04-19 Thread geremy condra
On Tue, Apr 19, 2011 at 4:24 PM, Dan Stromberg drsali...@gmail.com wrote:
 On Tue, Apr 19, 2011 at 4:03 PM, geremy condra debat...@gmail.com wrote:
 On Tue, Apr 19, 2011 at 3:42 PM, Passiday passi...@gmail.com wrote:
 Hello,

 I am planning to teach Python to a group of high school students, who have 
 in-depth interest in programming, hacking etc.

 I am looking for some good material, what I could use as a basic guide when 
 preparing the classes plan for the course - website or book, what would 
 roll out the topic methodologically gradually. The target audience is 
 someone who knows most basics of the programming, but doesn't mind being 
 reminded about them now and then.

 Thanks for any suggestions!

 When you say 'hacking', you mean ?

 Presumably he meant the real meaning of the word, not what the press
 made up and ran with.

Even security professionals use it both ways. Especially in the
context of a room full of teenagers, it seems reasonable to ask.

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


[OT] Piling of prepositions (was: Namespaces in functions vs classes)

2011-04-19 Thread Ben Finney
Rhodri James rho...@wildebst.demon.co.uk writes:

 Language abuse: it's not just Python. A donation of just $5 will keep
 a programmer in prepositions for a month. $50 will supply enough
 articles to keep a small company understandable for over a year. With
 your generous help, we can beat this scourge!

I lately lost a preposition
It hid, I thought, beneath my chair
And angrily I cried, “Perdition!
Up from out of in under there.”

Correctness is my vade mecum,
And straggling phrases I abhor,
And yet I wondered, “What should he come
Up from out of in under for?”

—Morris Bishop, in the _New Yorker_, 1947-09-27
URL:http://www.ourcivilisation.com/smartboard/shop/gowerse/complete/chap905.htm

-- 
 \ “Not to be absolutely certain is, I think, one of the essential |
  `\ things in rationality.” —Bertrand Russell |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Dan Stromberg
On Tue, Apr 19, 2011 at 3:21 PM, Grant Edwards invalid@invalid.invalid wrote:
 I'm have problems figuring out how to receive UDP broadcast packets on
 Linux.

 Here's the receiving code:

 --receive.py---

 But, the receiving Python program never sees any packets unless the
 _source_ IP address in the packets is on the same subnet as the
 receiving machine.

This is just how broadcasts work.

Normally, you take your subnet mask and bitwise and it with the IP
addresses of the sending and receiving machines.  If the results match
for two such pairs on two different machines, then the broadcast
should be visible, given appropriate code.

However, some routers have the ability to pass packets from one subnet
to another.  I believe this is called a helper, at least in the
Cisco world, and must be configured specially.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Irmen de Jong
On 20-4-2011 1:21, Grant Edwards wrote:
 
 If I don't call bind(), then the broadcast packets go out the wrong
 interface on the sending machine.
 

Fair enough.

Next issue then: as far as I know, broadcast packets are by default not routed 
across
subnets by gateways. Which is a good thing.

That would explain why your receiver doesn't see the packets unless its 
interface IP
address is in the same subnet as the sender's.

However it doesn't explain (for me) why the tcpdump program running on that same
receiver machine still happily spits out received packets. Unless the routing 
between
the subnets is somehow done on the receiving machine itself? My knowledge of 
networks
and TCP/IP ends here I'm afraid.

Cheers
Irmen.


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


Re: Teaching Python

2011-04-19 Thread PATRICIA MEDINA
We have been teaching game programming using python in my school district for a 
few years now. We started out using python programming for the absolute 
beginner. It was good, but didn't use pygame and was mostly text based until 
the 

last 2 chapters. Another book for reference is Game Programming: The L Line, 
The 

Express Line to Learning. We also wanted to use OOP and at the time that was 
not 

in either, or we didn't like the format. We now use our own material we put 
together from numerous texts, and from some members of the local python meetup 
group who have donated their time and expertise. It's been great!
Good luck to you!

Pat





From: Passiday passi...@gmail.com
To: python-list@python.org
Sent: Tue, April 19, 2011 5:42:00 PM
Subject: Teaching Python

Hello,

I am planning to teach Python to a group of high school students, who have 
in-depth interest in programming, hacking etc.

I am looking for some good material, what I could use as a basic guide when 
preparing the classes plan for the course - website or book, what would roll 
out 
the topic methodologically gradually. The target audience is someone who knows 
most basics of the programming, but doesn't mind being reminded about them now 
and then.

Thanks for any suggestions!

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


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Dan Stromberg
On Tue, Apr 19, 2011 at 4:40 PM, Irmen de Jong irmen.nos...@xs4all.nl wrote:
 On 20-4-2011 1:21, Grant Edwards wrote:

 If I don't call bind(), then the broadcast packets go out the wrong
 interface on the sending machine.


 Fair enough.

 Next issue then: as far as I know, broadcast packets are by default not 
 routed across
 subnets by gateways. Which is a good thing.

 That would explain why your receiver doesn't see the packets unless its 
 interface IP
 address is in the same subnet as the sender's.

 However it doesn't explain (for me) why the tcpdump program running on that 
 same
 receiver machine still happily spits out received packets. Unless the routing 
 between
 the subnets is somehow done on the receiving machine itself? My knowledge of 
 networks
 and TCP/IP ends here I'm afraid.

 Cheers
 Irmen.

I'm guessing there are two different subnets on the same physical
cable - which is a little unusual, but not impossible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Teaching Python

2011-04-19 Thread Allan Davis
How about this.  http://inventwithpython.com/

thanks,
Allan

On Tue, Apr 19, 2011 at 7:35 PM, geremy condra debat...@gmail.com wrote:

 On Tue, Apr 19, 2011 at 4:24 PM, Dan Stromberg drsali...@gmail.com
 wrote:
  On Tue, Apr 19, 2011 at 4:03 PM, geremy condra debat...@gmail.com
 wrote:
  On Tue, Apr 19, 2011 at 3:42 PM, Passiday passi...@gmail.com wrote:
  Hello,
 
  I am planning to teach Python to a group of high school students, who
 have in-depth interest in programming, hacking etc.
 
  I am looking for some good material, what I could use as a basic guide
 when preparing the classes plan for the course - website or book, what would
 roll out the topic methodologically gradually. The target audience is
 someone who knows most basics of the programming, but doesn't mind being
 reminded about them now and then.
 
  Thanks for any suggestions!
 
  When you say 'hacking', you mean ?
 
  Presumably he meant the real meaning of the word, not what the press
  made up and ran with.

 Even security professionals use it both ways. Especially in the
 context of a room full of teenagers, it seems reasonable to ask.

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




-- 
___
Allan Davis
http://www.linkedin.com/in/cajuncode
-- 
http://mail.python.org/mailman/listinfo/python-list


My stupidity / strange inconsistency overriding class methods

2011-04-19 Thread andrew cooke
Hi,

I've been staring at this problem, in various forms, all day.  Am I missing 
something obvious, or is there some strange hardwiring of isinstance?  This is 
with Python 3.2.

class A(metaclass=ABCMeta):
@classmethod
def __instancecheck__(cls, instance): return False
# no override
assert isinstance(A(), A)
assert A.__class__.__instancecheck__(A, A())

class B(type):
def foo(self): return 42
class C(metaclass=B):
@classmethod
def foo(cls): return 7
# override
assert C().__class__.foo() == 7

It seems to me that the above two cases are inconsistent.  ABCMeta declares 
__instancecheck__ just like B declares foo.  Yet C can override foo, but A is 
unable to override the instance check.

Please help!

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


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Grant Edwards
On 2011-04-19, Irmen de Jong irmen.nos...@xs4all.nl wrote:
 On 20-4-2011 1:21, Grant Edwards wrote:
 
 If I don't call bind(), then the broadcast packets go out the wrong
 interface on the sending machine.

 Fair enough.

 Next issue then: as far as I know, broadcast packets are by default
 not routed across subnets by gateways. Which is a good thing.

 That would explain why your receiver doesn't see the packets unless
 its interface IP address is in the same subnet as the sender's.

 However it doesn't explain (for me) why the tcpdump program running
 on that same receiver machine still happily spits out received
 packets.

The two machines are on the same Ethernet segment (they're connected
via a dumb Ethernet switch).

Tcpdump shows the packets because the packets are being received by
the receiving machine's Ethernet interface.  They have a destination
MAC of ff:ff:ff:ff:ff:ff, so everybody on the logical Ethernet segment
receives them.

I guess the problem is that I expected to receive a packet on an
interface anytime a packet was received with a destination IP address
that matched that of the the interface.  Apprently there's some
filtering in the network stack based on the _source_ address as well
(that seems very counter-intuitive to me).

-- 
Grant Edwards   grant.b.edwardsYow! I'm not an Iranian!!
  at   I voted for Dianne
  gmail.comFeinstein!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: My stupidity / strange inconsistency overriding class methods

2011-04-19 Thread andrew cooke
Also, there's something strange about the number of arguments (they're not 
consistent between the two examples - the A to __instancecheck__ should not 
be needed).  Yet it compiles and runs like that.  Very confused :o(
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Equivalent code to the bool() built-in function

2011-04-19 Thread Gregory Ewing

Jean-Paul Calderone wrote:


Also boolean xor is the same as !=.


Only if you have booleans. Even without short circuiting,
a boolean xor operator could provide the service of
automatically booling things for you (is that a word?).


Jean-Paul

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


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Grant Edwards
On 2011-04-19, Dan Stromberg drsali...@gmail.com wrote:
 On Tue, Apr 19, 2011 at 3:21 PM, Grant Edwards invalid@invalid.invalid 
 wrote:
 I'm have problems figuring out how to receive UDP broadcast packets on
 Linux.

 Here's the receiving code:

 --receive.py---

 But, the receiving Python program never sees any packets unless the
 _source_ IP address in the packets is on the same subnet as the
 receiving machine.

 This is just how broadcasts work.

 Normally, you take your subnet mask and bitwise and it with the IP
 addresses of the sending and receiving machines.  If the results match
 for two such pairs on two different machines, then the broadcast
 should be visible, given appropriate code.

That certainly looks like what's hapenning, but it seems very
counter-productive to me.

If I send a packet to ff:ff:ff:ff:ff:ff--255.255.255.255, it's because
I want everybody on the Ethernet segment to receive it.  If I wanted
only people on a particular subnet (e.g. 10.0.0.0/8) to receive it, I
would have sent it to the subnet broadcast address (e.g. 10.255.255.255).

 However, some routers have the ability to pass packets from one subnet
 to another.  I believe this is called a helper, at least in the
 Cisco world, and must be configured specially.

There are no routers or firewalls involved -- just a dumb Ethernet
switch.

It seems I'm going to have to use raw sockets to do what I need to do.
That's exactly what I was trying to avoid by using UDP: I'm replacing
a proprietary (non IP) MAC-level protocol that was implemented using
raw sockets.

-- 
Grant Edwards   grant.b.edwardsYow! I'm young ... I'm
  at   HEALTHY ... I can HIKE
  gmail.comTHRU CAPT GROGAN'S LUMBAR
   REGIONS!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Teaching Python

2011-04-19 Thread Ben Finney
Dan Stromberg drsali...@gmail.com writes:

 On Tue, Apr 19, 2011 at 4:03 PM, geremy condra debat...@gmail.com wrote:
  When you say 'hacking', you mean ?

 Presumably he meant the real meaning of the word, not what the press
 made up and ran with.

To be fair, the press already had its own pejorative meaning of “hack”
before the engineering and computing term, so the association was
probably inevitable.

-- 
 \ “I still have my Christmas Tree. I looked at it today. Sure |
  `\   enough, I couldn't see any forests.” —Steven Wright |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Grant Edwards
On 2011-04-19, Dan Stromberg drsali...@gmail.com wrote:
 On Tue, Apr 19, 2011 at 4:40 PM, Irmen de Jong irmen.nos...@xs4all.nl wrote:
 On 20-4-2011 1:21, Grant Edwards wrote:

 If I don't call bind(), then the broadcast packets go out the wrong
 interface on the sending machine.


 Fair enough.

 Next issue then: as far as I know, broadcast packets are by default not 
 routed across
 subnets by gateways. Which is a good thing.

 That would explain why your receiver doesn't see the packets unless its 
 interface IP
 address is in the same subnet as the sender's.

 However it doesn't explain (for me) why the tcpdump program running on that 
 same
 receiver machine still happily spits out received packets. Unless the 
 routing between
 the subnets is somehow done on the receiving machine itself? My knowledge of 
 networks
 and TCP/IP ends here I'm afraid.

 I'm guessing there are two different subnets on the same physical
 cable

Yes -- though technically they're on the same Ethernet segment rather
than physical cable, since there's an intervening Ethernet switch.

 - which is a little unusual, but not impossible.

OK, here's some background...

I'm trying to implement a device discovery/configuration protocol that
uses UDP broadcast packets to discover specific types of devices on
the local Ethernet segment.  The management program broadcasts a
discovery command to a particular UDP port.  All devices who get that
packet are expected to answer regardless of thier current IP address.

The management program can then send another broadcast packet to
configure the IP address of a device. After that, the management
program switches over to normal unicast TCP and UDP protocols (HTTP,
TFTP, etc.) to set up the device.

I had ignorantly assumed that an UDP broadcast sent to IP address
255.255.255.255 would be received by everybody who could hear it.

Apparently I'm going to have to use RAW packets and implement UDP
myself. :/

-- 
Grant Edwards   grant.b.edwardsYow! BELA LUGOSI is my
  at   co-pilot ...
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: My stupidity / strange inconsistency overriding class methods

2011-04-19 Thread andrew cooke
OK, sorry, I see the mistake.  I'm confusing __class__ on the instance and on 
te class (the latter being the metaclass).  Sorry again, Andrew
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 10:00 AM, Grant Edwards invalid@invalid.invalid wrote:
 If I send a packet to ff:ff:ff:ff:ff:ff--255.255.255.255, it's because
 I want everybody on the Ethernet segment to receive it.  If I wanted
 only people on a particular subnet (e.g. 10.0.0.0/8) to receive it, I
 would have sent it to the subnet broadcast address (e.g. 10.255.255.255).

 It seems I'm going to have to use raw sockets to do what I need to do.
 That's exactly what I was trying to avoid by using UDP: I'm replacing
 a proprietary (non IP) MAC-level protocol that was implemented using
 raw sockets.

I have to ask:

1) Why do you have two subnets on the same switch? Isn't that going to
be an eternal maintenance headache? Not that it _can't_ be done -
obviously it can - but it's likely to confuse the humans involved.

2) Can you replace that protocol at a higher level? Presumably there's
a full protocol stack with application data getting wrapped up inside
(ultimately) ethernet frames; can you cut it somewhere else and make,
say, a TCP/IP connection to the remote system?

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


Re: My stupidity / strange inconsistency overriding class methods

2011-04-19 Thread Chris Rebert
On Tue, Apr 19, 2011 at 4:52 PM, andrew cooke and...@acooke.org wrote:
 Hi,

 I've been staring at this problem, in various forms, all day.  Am I missing 
 something obvious, or is there some strange hardwiring of isinstance?  This 
 is with Python 3.2.

        class A(metaclass=ABCMeta):
            @classmethod
            def __instancecheck__(cls, instance): return False
        # no override
        assert isinstance(A(), A)
        assert A.__class__.__instancecheck__(A, A())

[You've already figured out the issue, but since I spent a while
composing this, and for the benefit for the archives, I'll post
anyway.]

Makes sense after a little thought.
http://docs.python.org/reference/datamodel.html#customizing-instance-and-subclass-checks
Note that [ __instancecheck__() is ] looked up on the type
(metaclass) of a class. [It] cannot be defined as [a classmethod] in
the actual class. This is consistent with the lookup of special
methods that are called on instances, only in this case the instance
is itself a class.

Recall from 
http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes
that lookup of __special__ methods never consults instance
dictionaries, instead skipping directly to the type's namespace; as
the quote says, in this case, the instance (of ABCMeta) is itself a
class/type (namely A). Your two assert statements are therefore almost
precisely equivalent in this case; and since the latter involves
A.__class__ (a.k.a. ABCMeta) rather than A itself, it's understandable
that that A's namespace is not consulted.

        class B(type):
            def foo(self): return 42
        class C(metaclass=B):
            @classmethod
            def foo(cls): return 7
        # override
        assert C().__class__.foo() == 7

More simply:  assert C.foo() == 7

foo is not a __special__ method name; therefore we look in the
instance dictionary of the receiver (i.e. C) before consulting the
receiver's type (i.e. B). Our check in the instance dictionary is
successful (we find C.foo), and therefore we don't even bother looking
at C's type (i.e. B, where we would find B.foo).

 It seems to me that the above two cases are inconsistent.  ABCMeta declares 
 __instancecheck__ just like B declares foo.  Yet C can override foo, but A is 
 unable to override the instance check.

The difference is in the __special__-ness of the method names in question.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 10:09 AM, Grant Edwards invalid@invalid.invalid wrote:
 The management program can then send another broadcast packet to
 configure the IP address of a device. After that, the management
 program switches over to normal unicast TCP and UDP protocols (HTTP,
 TFTP, etc.) to set up the device.


Wonder if it would be possible to (ab)use DHCP for this. If every
device registers itself with a central DHCP server, you could query
that to find out what's around, and configuring of IP addresses would
then be out of your hands.

Or can you simply use a stupid netmask like /1 that picks up all the
IP ranges? That way, the source-IP check wouldn't fail.

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


Remote Connection

2011-04-19 Thread ray
I wonder if there is a solution to provide remote connections between
two computers similar to Remote Desktop.  The difference I am looking
for is to be able to deliver speech/audio from the local machine to
the remote machine which will process the audio via Dragon Naturally
Speaking.

As an additional point, I would like to be able to deliver speech to
that remote computer from a cell phone.

I would appreciate all considerations.

The current remote machine is an XP Pro SP2, the local machine
is . . . right now an XP Pro but will change to a Windows 7 Pro.  I do
not have a cell for this; I am waiting to see if any solution may
dictate the cell details.

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


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Grant Edwards
On 2011-04-20, Chris Angelico ros...@gmail.com wrote:
 On Wed, Apr 20, 2011 at 10:09 AM, Grant Edwards invalid@invalid.invalid 
 wrote:
 The management program can then send another broadcast packet to
 configure the IP address of a device. After that, the management
 program switches over to normal unicast TCP and UDP protocols (HTTP,
 TFTP, etc.) to set up the device.


 Wonder if it would be possible to (ab)use DHCP for this. If every
 device registers itself with a central DHCP server, you could query
 that to find out what's around, and configuring of IP addresses would
 then be out of your hands.

I can't require the presense of a DHCP server, and many installations
won't have one.

 Or can you simply use a stupid netmask like /1 that picks up all the
 IP ranges? That way, the source-IP check wouldn't fail.

That would require that the device somehow knows that it's not
configured correctly and should change the netmask to /1.  The device
doesn't have any way to know that, and it must respond to the
discovery commands both before and after it's properly configured.

I've reread the protocol documentation and noticed that the device has
to respond not only to broadcasts to 255.255.255.255 but also to
subnet broadcasts send to subnets it's not on.  That pretty much
clinches the requirement to use a raw socket. :/

-- 
Grant



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


Re: Remote Connection

2011-04-19 Thread Chris Rebert
On Tue, Apr 19, 2011 at 6:04 PM, ray r...@aarden.us wrote:
 I wonder if there is a solution to provide remote connections between
 two computers similar to Remote Desktop.  The difference I am looking
 for is to be able to deliver speech/audio from the local machine to
 the remote machine which will process the audio via Dragon Naturally
 Speaking.

 As an additional point, I would like to be able to deliver speech to
 that remote computer from a cell phone.

 I would appreciate all considerations.

 The current remote machine is an XP Pro SP2, the local machine
 is . . . right now an XP Pro but will change to a Windows 7 Pro.  I do
 not have a cell for this; I am waiting to see if any solution may
 dictate the cell details.

How does this specifically involve Python at all, pray tell?

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


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 11:15 AM, Grant Edwards invalid@invalid.invalid wrote:
 Or can you simply use a stupid netmask like /1 that picks up all the
 IP ranges? That way, the source-IP check wouldn't fail.

 That would require that the device somehow knows that it's not
 configured correctly and should change the netmask to /1.  The device
 doesn't have any way to know that, and it must respond to the
 discovery commands both before and after it's properly configured.

Was hoping that you could make such a change _only_ on the computer
that's receiving the data - that way it's only one change, the devices
don't need any tweaking. But if it can't be, it can't be.

 I've reread the protocol documentation and noticed that the device has
 to respond not only to broadcasts to 255.255.255.255 but also to
 subnet broadcasts send to subnets it's not on.  That pretty much
 clinches the requirement to use a raw socket. :/

Sounds to me like someone majorly abused IP to do weird things. Looks
like you're stuck doing the same weirdness, in whatever way you can
manage :| Sorry.

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


Re: Teaching Python

2011-04-19 Thread John Bokma
Passiday passi...@gmail.com writes:

 Hello,

 I am planning to teach Python to a group of high school students, who
 have in-depth interest in programming, hacking etc.

 I am looking for some good material, what I could use as a basic guide
 when preparing the classes plan for the course - website or book, what
 would roll out the topic methodologically gradually. The target
 audience is someone who knows most basics of the programming, but
 doesn't mind being reminded about them now and then.

So you want them to Dive into Python [1]? ;-)

[1] Google for it, it's an online book, free downloadable for both 2.x
and 3.x

-- 
John Bokma   j3b

Blog: http://johnbokma.com/Facebook: http://www.facebook.com/j.j.j.bokma
Freelance Perl  Python Development: http://castleamber.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Teaching Python

2011-04-19 Thread Alec Taylor
Author
 Series
 Lectures Slides/Documentation
 Assignments
 Difficulty
  MIT
 A Gentle Introduction to Programming Using Python
 on iTunes U
http://itunes.apple.com/us/itunes-u/introduction-to-computer-science/id341597455
 http://stuff.mit.edu/iap/python/

http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2010/index.htm
 Beginner Programmer
  Python
 Tutorial
 N/A
 http://docs.python.org/tutorial/
 N/A
 Average or beginner programmer
  Python
 N/A
 N/A
 http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
 N/A
 Beginner or non-programmer
  Google
 Google's Python Class
 on YouTube (see Sidebar for links)
 http://code.google.com/edu/languages/google-python-class/index.html
 See Python Exercises in sidebar
 Good programmer
-- 
http://mail.python.org/mailman/listinfo/python-list


meteclasses 2.x/3.x compatibility

2011-04-19 Thread James Mills
Hi all,

Is there a compatible way to use meteclasses
in both Python 2.x (2.6 to 2.7) and Python 3.x
(3.0 to 3.2).

Python 2.x:

class Foo(object):

   __meteclass__ = MyMetaClass

Python 3.x:

class Foo(metaclass=MyMetaClass):
   pass

Thanks,

cheers
James

-- 
-- James Mills
--
-- Problems are solved by method
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Teaching Python

2011-04-19 Thread Alec Taylor
Here are a few tutorials which may be helpful for notes etc:

Author,Series,Lectures,Slides/Documentation,Assignments,Difficulty
MIT,A Gentle Introduction to Programming Using Python,on iTunes
Uÿhttp://itunes.apple.com/us/itunes-u/introduction-to-computer-science/id341597455,http://stuff.mit.edu/iap/python/,http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-189-a-gentle-introduction-to-programming-using-python-january-iap-2010/index.htm,Beginner
Programmer
Python,Tutorial,N/A,http://docs.python.org/tutorial/,N/A,Average or
beginner programmer
Python,N/A,N/A,http://wiki.python.org/moin/BeginnersGuide/NonProgrammers,N/A,Beginner
or non-programmer
Google,Google's Python Class,on YouTube (see Sidebar for
links),http://code.google.com/edu/languages/google-python-class/index.html,See
Python Exercises in sidebar,Good programmer

(Unfortunately can't paste table... but here is what the table looks
like: http://i51.tinypic.com/zof9yt.png, email me directly for table)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pickling over a socket

2011-04-19 Thread Jean-Paul Calderone
On Apr 19, 6:27 pm, Roger Alexander rtalexan...@mac.com wrote:
 Thanks everybody, got it working.

  I appreciate the help!

 Roger.

It's too bad none of the other respondents pointed out to you that you
_shouldn't do this_!  Pickle is not suitable for use over the network
like this.  Your server accepts arbitrary code from clients and
executes it.  It is completely insecure.  Do not use pickle and
sockets together.  Notice the large red box at the top of http://
docs.python.org/library/pickle.html.

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


Re: [OT] Piling of prepositions (was: Namespaces in functions vs classes)

2011-04-19 Thread Dave Angel

On 01/-10/-28163 02:59 PM, Ben Finney wrote:

Rhodri Jamesrho...@wildebst.demon.co.uk  writes:


Language abuse: it's not just Python. A donation of just $5 will keep
a programmer in prepositions for a month. $50 will supply enough
articles to keep a small company understandable for over a year. With
your generous help, we can beat this scourge!


I lately lost a preposition
It hid, I thought, beneath my chair
And angrily I cried, “Perdition!
Up from out of in under there.”

Correctness is my vade mecum,
And straggling phrases I abhor,
And yet I wondered, “What should he come
Up from out of in under for?”

—Morris Bishop, in the _New Yorker_, 1947-09-27
URL:http://www.ourcivilisation.com/smartboard/shop/gowerse/complete/chap905.htm



Ending a sentence with a preposition is one aberration up with which I 
will not put.


With is a lousy word to start or end a sentence with.

 origins unknown

DaveA

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


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Grant Edwards
On 2011-04-20, Chris Angelico ros...@gmail.com wrote:
 On Wed, Apr 20, 2011 at 11:15 AM, Grant Edwards invalid@invalid.invalid 
 wrote:
 Or can you simply use a stupid netmask like /1 that picks up all the
 IP ranges? That way, the source-IP check wouldn't fail.

 That would require that the device somehow knows that it's not
 configured correctly and should change the netmask to /1. ?The device
 doesn't have any way to know that, and it must respond to the
 discovery commands both before and after it's properly configured.

 Was hoping that you could make such a change _only_ on the computer
 that's receiving the data - that way it's only one change, the devices
 don't need any tweaking. But if it can't be, it can't be.

There can by any number of devices that have to receive the broadcast
packet, and any of them can be on different subnets (or have no IP
address at all).

 I've reread the protocol documentation and noticed that the device
 has to respond not only to broadcasts to 255.255.255.255 but also to
 subnet broadcasts send to subnets it's not on.

It turns out that some OSes (BSD and some flavors of Windows) can't
broadcast to 255.255.255.255, only to the subnet broadcast address.
Hence the requirement for the devices to be able to receive a subnet
broadcast regardless of their IP address.

 That pretty much clinches the requirement to use a raw socket. :/

 Sounds to me like someone majorly abused IP to do weird things.

Indeed.  The other option is to do something that's not based on IP
but done completely at the Ethernet layer.  Implementing management
programs that can do that can be very nasty on Windows, which
unfortunately matters to most customers.

So you bite the bullet on the device end and implement all sorts of
weirdness in order to allow the management program to use standard
UDP.

 Looks like you're stuck doing the same weirdness, in whatever way you
 can manage

Yup.  It doesn't even appear that it can be done with a raw UDP
socket. According to all of the documentation I can find, such a
socket is supposed to receive copies of all UDP packets seen by the
kernel, but it doesn't.  Even if I use a raw UDP socket, the kernel is
still dropping broadcast packets whose source address don't match any
interface's subnet.

AFAICT, I'm going to have to go completely raw and process in
user-space every single IP packet recieved.  That's going to be
brutal on the CPU...

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


List comprehension vs filter()

2011-04-19 Thread Chris Angelico
Context: Embedded Python interpreter, version 2.6.6

I have a list of dictionaries, where each dictionary has a type
element which is a string. I want to reduce the list to just the
dictionaries which have the same type as the first one.

lst=[{type:calc,...},{type:fixed,...},{type:calc,...},...]

I'm seeing a weird difference between two otherwise-equivalent-looking
ways of doing the job.

type=lst[0][type].lower()

lst=filter(lambda x: x[type].lower()==type,lst) # Restrict to that one type

lst=[i for i in lst if i[type].lower()==type] # Restrict to that one type

If I use the filter() method, the resulting list is completely empty.
If I use the list comprehension, it works perfectly. Oddly, either
version works in the stand-alone interpreter.

I have no idea where to start looking for the problem. Hints, please!

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


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Dan Stromberg
On Tue, Apr 19, 2011 at 6:15 PM, Grant Edwards invalid@invalid.invalid wrote:

 Or can you simply use a stupid netmask like /1 that picks up all the
 IP ranges? That way, the source-IP check wouldn't fail.

 That would require that the device somehow knows that it's not
 configured correctly and should change the netmask to /1.  The device
 doesn't have any way to know that, and it must respond to the
 discovery commands both before and after it's properly configured.

- Actually, you Might be able to configure your device to have a
netmask of 0.0.0.0, IP address of 255.255.255.255 and broadcast of
255.255.255.255.
- I've seen something a bit similar used for detecting IP address
conflicts automatically.
- A network guru I used to work with told me that you could configure
a machine with a broadcast of 255.255.255.255 more simply than messing
around with the netmask, while still achieving the same result for
general purpose networking.

 I've reread the protocol documentation and noticed that the device has
 to respond not only to broadcasts to 255.255.255.255 but also to
 subnet broadcasts send to subnets it's not on.  That pretty much
 clinches the requirement to use a raw socket. :/

With a netmask of 0.0.0.0, I suspect you will receive all broadcasts
on the wire, given appropriate listening code.

You could probably also modify a copy of tshark or tcpdump to flush
after every line of output (or run an unmodified one on a pty to avoid
maintaining your own copy of the binary), and parse that output in
Python.  That should make the Python code pretty simple.

There's an old program called pty that makes it easy to run
something on a pty, to get unbuffered output - it's in
comp.sources.unix volumes 22, 23 and 25; it's written in C.  You'd
just open a subprocess with no buffering on the python side, that runs
tcpdump or tshark under pty.  Beware though - the pty program predates
GNU autoconf, so might be a little involved to compile.

I agree though that you're kind of pushing IP in a direction it wasn't
intended to go.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem receiving UDP broadcast packets.

2011-04-19 Thread Dan Stromberg
On Tue, Apr 19, 2011 at 8:12 PM, Dan Stromberg drsali...@gmail.com wrote:
 I agree though that you're kind of pushing IP in a direction it wasn't
 intended to go.

It just occurred to me: You might get some additional mileage out of
popping the network adapter into promiscuous mode.  In fact, it Might
be necessary irrespective of the rest of your approach.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List comprehension vs filter()

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 1:10 PM, Chris Angelico ros...@gmail.com wrote:
 type=lst[0][type].lower()

 lst=filter(lambda x: x[type].lower()==type,lst) # Restrict to that one type

After posting, I realised that type is a built-in identifier, and
did a quick variable name change to posttype which shouldn't have a
problem. Now, the filter/lambda line bombs with NameError: global name
'posttype' is not defined. Could it be that the lambda is ignoring
local variables? If that's so, then it would have been comparing the
dictionary entry against the built-in type type, which will of
course never match. That could also explain why running the same code
as a standalone .py file works (variables defined in the body of a .py
file are global by default, if I have this correct). But why would
lambda bind to global variables but not local ones?

The Python code is being called from C as:

PyObject *v=PyRun_StringFlags(code,Py_file_input,py_globals,locals,0);

where py_globals and locals are dictionaries, code is a const char *
with the code.

I have Lucia di Lammermoor singing in the background, and I think I'll
be going as mad as she soon! This is so weird...

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


Re: List comprehension vs filter()

2011-04-19 Thread Chris Rebert
On Tue, Apr 19, 2011 at 8:10 PM, Chris Angelico ros...@gmail.com wrote:
snip
 type=lst[0][type].lower()

Tangent: Don't call it type; you're shadowing the built-in class of
the same name.

Cheers,
Chris
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List comprehension vs filter()

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 1:22 PM, Chris Rebert c...@rebertia.com wrote:
 On Tue, Apr 19, 2011 at 8:10 PM, Chris Angelico ros...@gmail.com wrote:
 snip
 type=lst[0][type].lower()

 Tangent: Don't call it type; you're shadowing the built-in class of
 the same name.

By shadowing you mean that the global variable still exists, right?
I'm creating a local variable with the same name? That's how I'm
interpreting the results of changing the variable name.

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


  1   2   3   >