Python as network protocol

2009-11-10 Thread Cooch
Hi, guys!

I want to implement such specific feature:
I have a server written in Python. I have a client written in C++. I
want to use Python as network protocol between them. I mean: client
send to server such string: "a = MyObject()", so object of this type
will appear in server. Any ideas how to simplify this implementation?
I make XML-RPC/SOAP server using twisted which just execute sended
string. But I don't know how to:
1. Restrict usage of some modules on client side (os, sys etc..)
2. Divide variables of different clients. Generally, I know that I
should use "exec .. in .. " construct, but don't know how to
distinguish between clients in twisted.

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


Re: Python as network protocol

2009-11-10 Thread Diez B. Roggisch

Cooch schrieb:

Hi, guys!

I want to implement such specific feature:
I have a server written in Python. I have a client written in C++. I
want to use Python as network protocol between them. I mean: client
send to server such string: "a = MyObject()", so object of this type
will appear in server. Any ideas how to simplify this implementation?
I make XML-RPC/SOAP server using twisted which just execute sended
string. But I don't know how to:
1. Restrict usage of some modules on client side (os, sys etc..)
2. Divide variables of different clients. Generally, I know that I
should use "exec .. in .. " construct, but don't know how to
distinguish between clients in twisted.


This is a *really* bad idea. Because there is no real way to restrict 
execution in python, and thus you allow clients to inject arbitrary code 
into your server. Including the notorious "os.system('rm -rf /')".


So - don't do that. Use e.g. CORBA if you need a richer, object-base 
protocol than XMLRPC.


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


Re: how to close not response win32 IE com interface

2009-11-10 Thread Michel Claveau - MVP
Hi!

The only way I know is to use sendkeys.

@+

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


Re: how to create a pip package

2009-11-10 Thread Wolodja Wentland
On Mon, Nov 09, 2009 at 19:48 -0800, Phlip wrote:
> I have a single file that I need my crew to pip install.

Where do you plan to host this file? Will it be available on PiPy?

> When I Google for "how to create a pip package" I don't hit anything.
> Of course that info is out there; I can't seem to pick up the trail of
> breadcrumbs to it.

As has already been noted in this thread you do not create a file
specifically for pip, but rather use the standard (or soon to be) way of
distributing Python distributions outlined in:

http://docs.python.org/library/distutils.html#module-distutils
http://packages.python.org/distribute/

If you do not plan to host your "file" on pypi you can easily create a
pip requirements file that references a VCS of your choice. Read how to
do this in the pip documentation on "editable" packages:

http://pypi.python.org/pypi/pip/

kind regards

Wolodja


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing GUI Module for Python

2009-11-10 Thread Dave Cook
On 2009-11-09, Antony  wrote:

>  1. PyGTK
>  2. PyQT
>  3. PySide
>  4.  wxPython
>  5 . TKinter

For cross-platform work, I'd choose either PyQt or wxPython.

If you're not too worried about the dual license, I find PyQt the best
combination of ease of use and features, particularly when used with
Qt Designer.

For commercial work, I'd use wxPython, which has a very liberal
license.  It's fairly featureful, but not very pleasant to use.

Dave Cook

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


Re: Req. comments on "first version" ch 2 progr. intro (using Python 3.x in Windows)

2009-11-10 Thread Jon Clements
[posts snipped]

The only other thing is that line_length is used as a constant in one
of the programs. However, it's being mutated in the while loop
example. It may still be in the reader's mind that line_length == 10.
(Or maybe not)

Cheers,

Jon.


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


Re: Choosing GUI Module for Python

2009-11-10 Thread Grant Edwards
On 2009-11-09, Dave Cook  wrote:
> On 2009-11-09, Antony  wrote:
>
>>  1. PyGTK
>>  2. PyQT
>>  3. PySide
>>  4.  wxPython
>>  5 . TKinter
>
> For cross-platform work, I'd choose either PyQt or wxPython.
>
> If you're not too worried about the dual license, I find PyQt
> the best combination of ease of use and features, particularly
> when used with Qt Designer.
>
> For commercial work, I'd use wxPython, which has a very
> liberal license.  It's fairly featureful, but not very
> pleasant to use.

NB: One thing to I've noticed about wxPython is that if you
follow the rules carefully, the cross-platform behavior
consistency is pretty decent.  However, if you're not careful,
it's easy to do something the "wrong" way and have it still
work fine on one platform, but not on another.  During
development, you need to test frequently on all the platforms
you care about.  If you wait until the end to test on that
second/third platform, you may have accumulated enough minor
problems that it becomes a real chore to try to figure them all
out.

-- 
Grant Edwards   grante Yow! Why don't you ever
  at   enter any CONTESTS,
   visi.comMarvin??  Don't you know
   your own ZIPCODE?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing GUI Module for Python

2009-11-10 Thread Lorenzo Gatti
On Nov 9, 9:01 pm, Simon Hibbs  wrote:

> The main objection to using PyQT untill now was that for commercial
> development you needed to buy a license (it was free for GPL
> projects). That's rapidly becoming a non-issue as the core QT
> framework is now LGPL and Nokia have a project underway to produce
> PyQT compatible LGPL python bindings under the PySide project.

I also would like to use PySide, but unlike PyQt and Qt itself it
doesn't seem likely to support Windows in the foreseeable future. A
pity, to put it mildly.

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


Re: how to close not response win32 IE com interface

2009-11-10 Thread elca



Michel Claveau - MVP-2 wrote:
> 
> Hi!
> 
> The only way I know is to use sendkeys.
> 
> @+
> 
> Michel Claveau
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 
Hello,
actually this is not hang status, i mean..it slow response, so in that case,
i would like to close IE and
want to restart from start.
so closing is no problem ,problem is ,how to set timeout ,for example if i
set 15sec, if not webpage open less than 15 sec i want to close it and
restart from start.
is this possible to use with IE com interface?
really hard to find solution
Paul,
-- 
View this message in context: 
http://old.nabble.com/how-to-close-not-response-win32-IE-com-interface-tp26265055p26281603.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Is it possible to get the Physical memory address of a variable in python?

2009-11-10 Thread Ognjen Bezanov

Hey,

Thanks for all the responses guys. In hindsight I probably should have 
explained why on earth I'd need the physical address from an interpreted 
language.


I'm trying to see if there is any way I can make Python share data 
between two hosts using DMA transfers over a firewire connection, so 
avoiding the need for another layer on top such as IPv4 + Python sockets.


Thanks to some old python bindings which I updated to python 2.6, I can 
read any write to the RAM of any firewire connected host within python. 
Because it uses DMA (the cpu is not involved in this at all), I can only 
specify a physical address within the 4GB ram limit to read from and 
write to.


Now what I've done so far is on the remote host I run python and set a 
variable as so:


a = "foo"
print a
'foo'

Then on the local host I run a python script that scans the entire RAM 
looking for the string "foo", and replaces it with the string "oof". I 
have had success with this method. Once it's done and I do "print a" on 
the remote host, I get "oof" as the variable value, so in theory it can 
work.


Problem is that it's slow. Scanning 3GB of RAM every time you want to do 
this is not a good method. I thought that if I could get python to 
return the physical address of where the value of a variable is, then I 
can just jump to that address and write the data.


From what I've been told so far, it's not possible to do this without 
some OS-specific (Linux in this case) syscall. Is this correct?


Thanks!


Ognjen

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


Re: Is it possible to get the Physical memory address of a variable in python?

2009-11-10 Thread Maxim Khitrov
On Tue, Nov 10, 2009 at 6:32 AM, Ognjen Bezanov  wrote:
> Hey,
>
> Thanks for all the responses guys. In hindsight I probably should have
> explained why on earth I'd need the physical address from an interpreted
> language.
>
> I'm trying to see if there is any way I can make Python share data between
> two hosts using DMA transfers over a firewire connection, so avoiding the
> need for another layer on top such as IPv4 + Python sockets.
>
> Thanks to some old python bindings which I updated to python 2.6, I can read
> any write to the RAM of any firewire connected host within python. Because
> it uses DMA (the cpu is not involved in this at all), I can only specify a
> physical address within the 4GB ram limit to read from and write to.
>
> Now what I've done so far is on the remote host I run python and set a
> variable as so:
>
> a = "foo"
> print a
> 'foo'
>
> Then on the local host I run a python script that scans the entire RAM
> looking for the string "foo", and replaces it with the string "oof". I have
> had success with this method. Once it's done and I do "print a" on the
> remote host, I get "oof" as the variable value, so in theory it can work.
>
> Problem is that it's slow. Scanning 3GB of RAM every time you want to do
> this is not a good method. I thought that if I could get python to return
> the physical address of where the value of a variable is, then I can just
> jump to that address and write the data.
>
> From what I've been told so far, it's not possible to do this without some
> OS-specific (Linux in this case) syscall. Is this correct?
>
> Thanks!
>
>
> Ognjen

If all you need is a memory buffer, array.array provides a
buffer_info() method that tells you the current (virtual) address. For
DMA, I think there are dma_map_* functions in linux that you may be
able to call through ctypes.

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


Re: Newbie advice

2009-11-10 Thread lkcl
On Oct 29, 7:00 am, alex23  wrote:

> However, if you're already comfortable with HTML/CSS, I'd recommend
> taking a look atPyjamas, which started as a port of the Google Web
> Toolkit, taking Python code and compiling it into javascript. The
> associated project,Pyjamas-Desktop, is a webkit-based desktop client/
> widget set; so ideally you only have to write one UI and it'll run
> both on the web & the desktop.
>
> Pyjamas:http://pyjs.org/
> Pyjamas-Desktop:http://pyjd.sourceforge.net/


 thank you for mentioning these, chris.  the information on pyjd is
slightly out-of-date.

 * pyjamas-desktop was merged into pyjamas as of the 0.6 release.

 * there are now three alternative back-ends for pyjamas-desktop,
   (just as there are three major web browser engines).  MSHTML,
   xulrunner and webkit.

   Opera's engine cannot be included because Opera's developers have
   not responded to invitations to provide an engine / library to
which
   python bindings can be added.  when they have provided python
bindings,
   a port of pyjd to use them can be done in approximately two weeks.

 * the webkit-based back-end is the least-recommended, due to
intransigence
   of the webkit developer, mark rowe.  mark rowe has shown consistent
   disrespect for free software contributions to make webkit with glib/
gobject
   bindings actually useful and useable, and has ensured that anyone
who
   wishes to proceed with getting webkit its glib/gobject bindings
will
   have an unacceptably hard time.  efforts to work with the other
webkit
   developers, which were proving successful, were deliberately
destroyed
   by, and terminated by, mark rowe.

 * the MSHTML-based back-end is surprisingly the most successful of
the
   three pyjd ports.  it requires _very_ little in the way of
libraries
   to be installed: only python-comtypes (at 250k) which is in
complete
   contrast to the other ports, which require whopping 30mbyte
installs
   of libraries and dependencies.

 * the xulrunner-based back-end is the best option for unix-based
systems.
   the design of xulrunner's core infrastructure, XPCOM, however, is
   slightly ... "incomplete".  it is based on DCOM, but does not
provide
   the exact same capabilities as DCOM (no coclasses).  the upshot is
   that current releases of xulrunner work perfectly well for
_everything_
   but 2D SVG Canvas "Image" loading.  (i have a patch for xulrunner
which
   fixes this one single error)


so - it's a mixed and interesting bag of tricks.

full and comprehensive non-javascript bindings to web technology seems
to be a thoroughly misunderstood and underexploited area, with several
variations on the same theme being available from several competitive
sources.

the nice thing about pyjamas is that just as pyjs makes all the
differences "go away" when pyjamas apps are compiled to run in web
browsers, pyjamas-desktop makes those differences "go away" when
pyjamas apps are run as pure python on the desktop.

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


Re: My own accounting python euler problem

2009-11-10 Thread Gerry
On Nov 8, 2:42 pm, Ozz  wrote:
> vsoler schreef:
>
And, of course, you'd want to take a look a this:  http://xkcd.com/287/

Gerry
>
> > Instead of subsets, do you mean permutations/combinations?  Since 2
> > invoices can have the same amount perhaps the terms permutation is
> > better.
>
> As some other poster already suggested 'powerset' 
> (http://en.wikipedia.org/wiki/Power_set) may be a better name, except
> for those duplicates, of course. On the other hand, I think viewing it
> as a powerset is the most 'natural' in this case. (imo permutations are
> about the order of objects, not about whether the objects are included
> in a set or not)
>
> cheers,
> Ozz

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


Re: comparing alternatives to py2exe

2009-11-10 Thread Philip Semanchuk


On Nov 9, 2009, at 9:16 PM, Gabriel Genellina wrote:

En Fri, 06 Nov 2009 17:00:17 -0300, Philip Semanchuk > escribió:

On Nov 3, 2009, at 10:58 AM, Jonathan Hartley wrote:


Recently I put together this incomplete comparison chart in an  
attempt

to choose between the different alternatives to py2exe:

http://spreadsheets.google.com/pub?key=tZ42hjaRunvkObFq0bKxVdg&output=html


I was interested in py2exe because we'd like to provide a one  
download, one click install experience for our Windows users. I  
think a lot of people are interested in py2exe for the same reason.  
Well, one thing that I came across in my travels was the fact that  
distutils can create MSIs. Like py2exe, MSIs provide a one  
download, one click install experience under Windows and therefore  
might be a replacement for py2exe.


But py2exe and .msi are complementary, not a replacement.
py2exe collects in one directory (or even in one file in some cases)  
all the pieces necesary to run your application. That is, Python  
itself + your application code + all referenced libraries + other  
required pieces.
The resulting files must be installed in the client machine; you  
either build a .msi file (a database for the Microsoft Installer) or  
use any other installer (like InnoSetup, the one I like).


For me, the following command was sufficient to create an msi,  
although it only worked under Windows (not under Linux or OS X):

python setup.py bdist_msi

The resulting MSI worked just fine in my extensive testing (read: I  
tried it on one machine).


The resulting .msi file requires Python already installed on the  
target machine, if I'm not mistaken. The whole point of py2exe is to  
avoid requiring a previous Python install.


You're right; the MSI I created doesn't include prerequisites. It  
packaged up our app, that's it. To be fair to MSIs, they might be  
capable of including prerequisites, the app, and the kitchen sink. But  
I don't think Python's creation process through distutils makes that  
possible.


That's why I suggested MSIs belong alongside RPM/DEB in the chart (if  
they're to be included at all).


I wouldn't say that the whole point of py2exe is to bundle Python.  
That's certainly a big benefit, but another benefit is that it can  
bundle an app into a one-click download. That's why we were interested  
in it.






It seems, then, that creating an MSI is even within the reach of  
someone like me who spends very little time in Windows-land, so it  
might be worth a column on your chart alongside rpm/deb.


As said in http://wiki.python.org/moin/DistributionUtilities the  
easiest way is to use py2exe + InnoSetup.


Easiest for you. =) The list of packages and modules that might  
require special treatment is almost a perfect superset of the modules  
we're using in our application:

http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules

py2exe looks great, but it remains to be seen if it's the easiest way  
to solve our problem. The MSI isn't nearly as nice for the end user,  
but we created it using only the Python standard library and our  
existing setup.py. Simplicity has value.




Cheers
Philip

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


Re: Most efficient way to "pre-grow" a list?

2009-11-10 Thread gil_johnson
On Nov 9, 10:56 pm, "Gabriel Genellina" wrote:
>
> [much cutting]
>
> def method3a():
>    newArray = array.array('I', [INITIAL_VALUE]) * SIZE
>    assert len(newArray)==SIZE
>    assert newArray[SIZE-1]==INITIAL_VALUE
>
> [more cutting]
>
> So arrays are faster than lists, and in both cases one_item*N outperforms  
> your doubling algorithm.
> Adding one item at a time is -at least- several hundred times slower; I  
> was not patient enough to wait.
>
> > Finally, I just looked into calling C functions, and found
> > PyMem_Malloc, PyMem_Realloc, PyMem_Free, etc. in the Memory Management
> > section of the Python/C API Reference Manual. This gives you
> > uninitialized memory, and should be really fast, but it's 6:45 AM
> > here, and I don't have the energy to try it.
>
> No, those are for internal use only, you can't use the resulting pointer  
> in Python code. An array object is a contiguous memory block, so you don't  
> miss anything.
>

Gabriel,
Thanks for the reply - your method 3a was what I wanted,
I missed "array.array('I', [INITIAL_VALUE]) * SIZ" on my
earlier pass through the Python documentation. I included
the 'one at a time' method because that was my first shot
at the problem - I was so happy to find a method that would
get the job done today that I didn't look farther than the
doubling method.

Yes, I know that I was comparing lists and arrays. Part of the
confusion in this thread is that the problem hasn't been
defined very well. The original post asked about arrays
but the solution proposed generated a list. At this point,
I have learned a lot about arrays, lists and dictionaries, and
will be better able to chose the right solution to future
problems.

It's too bad about the C functions, they sure sounded good.

And with that, I think I will withdraw from the field, and go
write some code and learn about timeit.

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


Re: My own accounting python euler problem

2009-11-10 Thread Steven D'Aprano
On Sun, 08 Nov 2009 12:31:26 -0500, geremy condra wrote:

> What you're describing is the powerset operation. Here's the example
> from the python docs:
[...]
> What I find interesting is that running it through timeit, it is much
> slower than the code suggested by Dan Bishop.

Your test doesn't show what you think it shows. You shouldn't just 
blindly apply timeit without testing to see that the functions return 
what you think they return. Your test is, I'm afraid, totally bogus and 
the conclusion you draw is completely wrong.


[...]
> #timeit.timeit("subsets1(x)", setup) doesn't appear to terminate
> timeit.timeit("subsets2(x)", setup)
> timeit.timeit("subsets3(x)", setup)

For the sake of speed, I've used a smaller x. Here are the results of 
calling the three functions:


>>> x = range(3)
>>> subsets1(x)
[[2], [2, 0], [2, 1], [2, 1, 0], [], [0], [1], [1, 0]]
>>> subsets2(x)

>>> subsets3(x)


The reason subsets1() "doesn't appear to terminate" is that you are 
trying to list all the subsets of x = range(100). That's a LOT of 
subsets: 2**100 to be precise, or approximately 1.2e30.

subsets2() and subsets3() return a generator function and an iterator 
object respectively. There may be some overhead difference between those, 
but that's trivial compared to the cost of generating the subsets 
themselves.

A better way of doing the timing is as follows:



from itertools import chain, combinations
from timeit import Timer

# use a number small enough to calculate in a reasonable time
x = list(range(10))

def subsets1(L):
   S = []
   if (len(L) == 1):
   return [L, []]
   else:
   for s in subsets1(L[1:]):
   S.append(s)
   S.append(s + [ L[0]])
   return S

def subsets2(L):
   if L:
   for s in subsets2(L[1:]):
   yield s
   yield s + [L[0]]
   else:
   yield []

def subsets3(iterable):
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in 
  range(len(s)+1))

setup = "from __main__ import subsets1, subsets2, subsets3, x"


# Check the three functions return the same results:
x1 = sorted(subsets1(x))
x2 = sorted(subsets2(x))
x3 = sorted(list(t) for t in subsets1(x))
assert x1 == x2 == x3

# Set up some timers.
t1 = Timer("subsets1(x)", setup)
t2 = Timer("list(subsets2(x))", setup)
t3 = Timer("list(subsets3(x))", setup)

# And run them!
for t in (t1, t2, t3):
print min(t.repeat(number=1000, repeat=5))



The results I get are:

1.19647693634
0.901714801788
0.175387859344

Which as you can see, shows that the recipe in the docs is nearly ten 
times faster than Dan's version. That's not surprising -- the docs 
version uses highly optimized C code from itertools, while Dan's version 
uses slow-ish Python code and recursion.


To show this is no fluke, I increased the size of x and ran the tests 
again:


>>> x = list(range(15))  # 32000+ subsets
>>> x1 = sorted(subsets1(x))
>>> x2 = sorted(subsets2(x))
>>> x3 = sorted(list(t) for t in subsets1(x))
>>> assert x1 == x2 == x3
>>> 
>>> t1 = Timer("subsets1(x)", setup)
>>> t2 = Timer("list(subsets2(x))", setup)
>>> t3 = Timer("list(subsets3(x))", setup)
>>> for t in (t1, t2, t3):
... print min(t.repeat(number=1000, repeat=5))
...
45.283468008
33.9274909496
7.40781188011



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


Re: how to create a pip package

2009-11-10 Thread Phlip
On Nov 10, 1:54 am, Wolodja Wentland 
wrote:

> http://docs.python.org/library/distutils.html#module-distutils
> http://packages.python.org/distribute/

ktx... now some utterly retarded questions to prevent false starts.

the distutils page starts with "from distutils.core import setup".

but a sample project on github, presumably a pippable project, starts
with:

from setuptools import setup, find_packages

(and it also has ez_setup())

I don't foresee my project growing larger than one* file any time
soon. 'pip freeze' prob'ly won't write a setup.py. What is the
absolute simplest setup.py to stick my project on the PYTHONPATH, and
be done with it?

[*but rest assured it has a developer test suite and a customer test
script!]

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: My own accounting python euler problem

2009-11-10 Thread geremy condra
On Tue, Nov 10, 2009 at 8:59 AM, Steven D'Aprano
 wrote:
> On Sun, 08 Nov 2009 12:31:26 -0500, geremy condra wrote:
>
>> What you're describing is the powerset operation. Here's the example
>> from the python docs:
> [...]
>> What I find interesting is that running it through timeit, it is much
>> slower than the code suggested by Dan Bishop.
>
> Your test doesn't show what you think it shows. You shouldn't just
> blindly apply timeit without testing to see that the functions return
> what you think they return. Your test is, I'm afraid, totally bogus and
> the conclusion you draw is completely wrong.



Doh! I even noticed that the asymptotic times didn't match up
and still blew right past the obvious answer. Thanks (again) for
the correction, Steven.

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


Re: Serious Privileges Problem: Please Help

2009-11-10 Thread Victor Subervi
For others who discover this error, here's what happened as I've traced it:
1) I never before had built a python interpreter on my Windoze box. That was
kind of silly, since I was uploading to my server every time I wanted to
test. So I built on my Windoze box. Thereafter, Windoze assumed that all
*.py files were native to its environment. That's where the little devil
crept in.
2) When I went to edit my files on the server, I never saw any lines ending
in "^M", the dead giveaway that Windoze has mangled the line endings. So the
problem was __invisible__.

Wow. What a pain in the &(%(
Thanks for everyone's help!
V

On Mon, Nov 9, 2009 at 9:12 PM, Dave Angel  wrote:

> Victor Subervi wrote:
>
>> On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi > >wrote:
>>
>>
>>
>>> On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury >> >wrote:
>>>
>>>
>>>

  
>>>
>>>
>>> Hold everything. Apparently line-endings got mangled. What I don't
>>>
>>>
>> understand is why I didn't see them when I opened the file to edit, and
>> why
>> they didn't copy and paste when I did that. But dos2unix cleaned up a
>> couple
>> of files so I presume it will clean up the rest. However, I tried one
>> file,
>> that reads exactly the same as index.py, and when I surfed to it got a 500
>> error. Here's what the log said:
>>
>> 
>>
>>
> What I've diagnosed as happening when a python script with Windows
> line-ending was posted on my server's cgi environment:
>
> The actual error seemed to be a failure to find the python interpreter,
> since some Unix shells take the shebang line to include the \r character
> that preceded the newline.   Seems to me they could be more tolerant, since
> I don't think control characters are likely in the interpreter file name.
>
> DaveA
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Serious Privileges Problem: Please Help

2009-11-10 Thread Scott David Daniels

Dave Angel wrote:

Victor Subervi wrote:
On Mon, Nov 9, 2009 at 2:30 PM, Victor Subervi 
wrote:
On Mon, Nov 9, 2009 at 2:27 PM, Rami Chowdhury 
wrote:



Hold everything. Apparently line-endings got mangled. What I don't

...
 
What I've diagnosed as happening when a python script with Windows 
line-ending was posted on my server's cgi environment:


The actual error seemed to be a failure to find the python interpreter, 
since some Unix shells take the shebang line to include the \r character 
that preceded the newline.   Seems to me they could be more tolerant, 
since I don't think control characters are likely in the interpreter 
file name.


You could work around this by creating a symlink (or even hard link to
the python executable named "python\r"

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Create object from variable indirect reference?

2009-11-10 Thread NickC


I can't seem to find a way to do something that seems straighforward, so I 
must have a mental block.  I want to reference an object indirectly 
through a variable's value.

Using a library that returns all sorts of information about "something", I 
want to provide the name of the "something" via a variable (command line 
argument).  The something is a class in the library and I want to 
instantiate an object of the class so I can start querying it.  I can't 
figure out how to pass the name of the class to the library.

Or, put another way, I can't figure out how to indirectly reference the 
value of the command line argument to create the object.

To make it clearer, it's roughly equivalent to this in bash:
 Sun="1AU" ; body=Sun; echo ${!body} --> outputs "1AU". 

command line:
$ ./ephemeris.py Moon

code:
import ephem
import optparse

# various option parsing (left out for brevity), 
# so variable options.body contains string "Moon",
# or even "Moon()" if that would make it easier.

# Want to instantiate an object of class Moon.
# Direct way:
moon1 = ephem.Moon()
# Indirect way from command line with a quasi bashism that obviously fails:
moon2 = ephem.${!options.body}()

Can someone point me in the right direction here?

(The library is PyEphem, an extraordinarily useful library for anyone 
interested in astronomy.)

Many thanks,

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


Re: Create object from variable indirect reference?

2009-11-10 Thread Jon Clements
On Nov 10, 2:59 pm, NickC  wrote:
> I can't seem to find a way to do something that seems straighforward, so I
> must have a mental block.  I want to reference an object indirectly
> through a variable's value.
>
> Using a library that returns all sorts of information about "something", I
> want to provide the name of the "something" via a variable (command line
> argument).  The something is a class in the library and I want to
> instantiate an object of the class so I can start querying it.  I can't
> figure out how to pass the name of the class to the library.
>
> Or, put another way, I can't figure out how to indirectly reference the
> value of the command line argument to create the object.
>
> To make it clearer, it's roughly equivalent to this in bash:
>  Sun="1AU" ; body=Sun; echo ${!body} --> outputs "1AU".
>
> command line:
> $ ./ephemeris.py Moon
>
> code:
> import ephem
> import optparse
>
> # various option parsing (left out for brevity),
> # so variable options.body contains string "Moon",
> # or even "Moon()" if that would make it easier.
>
> # Want to instantiate an object of class Moon.
> # Direct way:
> moon1 = ephem.Moon()
> # Indirect way from command line with a quasi bashism that obviously fails:
> moon2 = ephem.${!options.body}()
>
> Can someone point me in the right direction here?
>
> (The library is PyEphem, an extraordinarily useful library for anyone
> interested in astronomy.)
>
> Many thanks,
>
> --
> NickC

A direct way is to use:

moon1 = getattr(ephem, 'Moon')()

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


Re: Create object from variable indirect reference?

2009-11-10 Thread Rami Chowdhury
On Tue, 10 Nov 2009 06:59:25 -0800, NickC   
wrote:


I can't seem to find a way to do something that seems straighforward, so  
I

must have a mental block.  I want to reference an object indirectly
through a variable's value.

Using a library that returns all sorts of information about "something",  
I

want to provide the name of the "something" via a variable (command line
argument).  The something is a class in the library and I want to
instantiate an object of the class so I can start querying it.  I can't
figure out how to pass the name of the class to the library.

Or, put another way, I can't figure out how to indirectly reference the
value of the command line argument to create the object.

To make it clearer, it's roughly equivalent to this in bash:
 Sun="1AU" ; body=Sun; echo ${!body} --> outputs "1AU".

command line:
$ ./ephemeris.py Moon

code:
import ephem
import optparse

# various option parsing (left out for brevity),
# so variable options.body contains string "Moon",
# or even "Moon()" if that would make it easier.

# Want to instantiate an object of class Moon.
# Direct way:
moon1 = ephem.Moon()
# Indirect way from command line with a quasi bashism that obviously  
fails:

moon2 = ephem.${!options.body}()

Can someone point me in the right direction here?

(The library is PyEphem, an extraordinarily useful library for anyone
interested in astronomy.)

Many thanks,



Since Python 'variables' are really keys in a namespace dictionary, it's  
fairly straightforward to get at them given a string value -- what you  
probably want in this case is the built-in function getattr()  
(http://www.diveintopython.org/power_of_introspection/getattr.html)...


So getattr(ephem, "Moon") should give you the class object ephem.Moon,  
which you can then instantiate...




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python as network protocol

2009-11-10 Thread Daniel Fetchinson
>> I want to implement such specific feature:
>> I have a server written in Python. I have a client written in C++. I
>> want to use Python as network protocol between them. I mean: client
>> send to server such string: "a = MyObject()", so object of this type
>> will appear in server. Any ideas how to simplify this implementation?
>> I make XML-RPC/SOAP server using twisted which just execute sended
>> string. But I don't know how to:
>> 1. Restrict usage of some modules on client side (os, sys etc..)
>> 2. Divide variables of different clients. Generally, I know that I
>> should use "exec .. in .. " construct, but don't know how to
>> distinguish between clients in twisted.

Have you considered using pyro?

http://pyro.sourceforge.net/

> This is a *really* bad idea.

How do you know for sure? Maybe the OP wants to use this thing with 3
known researchers working on a cluster that is not even visible to the
outside world. In such a setup the model the OP suggested is a
perfectly reasonable one. I say this because I often work in such an
environment and security is never an issue for us. And I find it
always amusing that whenever I outline our code to a non-scientist
programmer they always run away in shock and never talk to us again :)
Nevertheless our code works perfectly for our purposes.

> Because there is no real way to restrict
> execution in python, and thus you allow clients to inject arbitrary code
> into your server. Including the notorious "os.system('rm -rf /')".
>
> So - don't do that. Use e.g. CORBA if you need a richer, object-base
> protocol than XMLRPC.

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonw.exe under Windows-7 (Won't run for one admin user)

2009-11-10 Thread SD_V897

Rhodri James wrote:

On Fri, 06 Nov 2009 21:19:44 -, SD_V897  wrote:


Rhodri James wrote:
On Tue, 03 Nov 2009 16:00:16 -, SD_V897  
wrote:


I have a perplexing issue, I have four users set up on a W7 
computer. The program runs fine for all users except the admin user 
who needs it for school assignments.

 A little more information, please.  How does it not work for the admin
user?  Is there a traceback?  What do you get if you try to invoke it
from a command line?




Hi Rhodri, here's a dump file, don't know if this helps or not..


So Windows is reporting a crash, then.  I'll repeat my last question in 
particular; what happens when your admin user runs the program you're 
trying to invoke from the command line?




Hi Rhodri, Python Command-Line works fine. Are toy recommending to 
invoke IDLE from there or from windows command line? Sorry I'm not to up 
on Python is there a command that would run IDLE from command?


If I run idle.py -c -d

I get idle is not defined.

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


Re: Python as network protocol

2009-11-10 Thread Martin
On Tue, Nov 10, 2009 at 16:31, Daniel Fetchinson
 wrote:
>> This is a *really* bad idea.
>
> How do you know for sure? Maybe the OP wants to use this thing with 3
> known researchers working on a cluster that is not even visible to the
> outside world. In such a setup the model the OP suggested is a
> perfectly reasonable one. I say this because I often work in such an
> environment and security is never an issue for us. And I find it
> always amusing that whenever I outline our code to a non-scientist
> programmer they always run away in shock and never talk to us again :)
> Nevertheless our code works perfectly for our purposes.

It is a bad idea because that's exactly why we now have a spam
problem. It _was_ a trusted environment once upon a time. Just check
your spam messages to see why ignoring security can lead to really bad
results.

Do you know for sure that in say 3-5 years from now on your software
isn't released into the wild and then has no security at all?

regards,
Martin


-- 
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is None or == None ?

2009-11-10 Thread Grant Edwards
On 2009-11-10, Rhodri James  wrote:
> On Sun, 08 Nov 2009 19:45:31 -, Terry Reedy  wrote:
>
>> I believe the use of tagged pointers has been considered and so far  
>> rejected by the CPython developers. And no one else that I know of has  
>> developed a fork for that. It would seem more feasible with 64 bit  
>> pointers where there seem to be spare bits. But CPython will have to  
>> support 32 bit machines for several years.
>
> I've seen that mistake made twice (IBM 370 architecture (probably 360 too,  
> I'm too young to have used it) and ARM2/ARM3).  I'd rather not see it a  
> third time, thank you.

MacOS applications made the same mistake on the 68K.  They
reserved the high-end bits in a 32-bit pointer and used them to
contain meta-information.  After all, those bits were "extra" --
nobody could ever hope to actually address more than 4MB of
memory, right? Heck, those address lines weren't even brought
out of the CPU package.

Guess what happened?

It wasn't the decades-long global debacle that was the MS-DOS
memory model, but it did cause problems when CPUs came out that
implemented those address lines and RAM became cheap enough
that people needed to use them.

-- 
Grant Edwards   grante Yow! Either CONFESS now or
  at   we go to "PEOPLE'S COURT"!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is None or == None ?

2009-11-10 Thread Marco Mariani

Grant Edwards wrote:


MacOS applications made the same mistake on the 68K.


And and awful lot of the Amiga software, with the same 24/32 bit CPU.

I did it too, every pointer came with 8 free bits so why not use them?



It wasn't the decades-long global debacle that was the MS-DOS
memory model, but it did cause problems when CPUs came out that
implemented those address lines and RAM became cheap enough
that people needed to use them.


I suppose that's the reason many games didn't work on the 68020+

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


Re: Python as network protocol

2009-11-10 Thread Steven D'Aprano
On Tue, 10 Nov 2009 16:31:13 +0100, Daniel Fetchinson wrote about using 
exec:

>> This is a *really* bad idea.
> 
> How do you know for sure? Maybe the OP wants to use this thing with 3
> known researchers working on a cluster that is not even visible to the
> outside world. In such a setup the model the OP suggested is a perfectly
> reasonable one. I say this because I often work in such an environment
> and security is never an issue for us. And I find it always amusing that
> whenever I outline our code to a non-scientist programmer they always
> run away in shock and never talk to us again 

You might be a great scientist, but perhaps you should pay attention to 
the experts on programming who tell you that this is opening a potential 
security hole in your system.

No, it's not a "perfectly reasonable" tactic. It's a risky tactic that 
only works because the environment you use it in is so limited and the 
users so trusted. Can you guarantee that will never change? If not, then 
you should rethink your tactic of using exec.

Besides, as a general rule, exec is around an order of magnitude slower 
than running code directly. If performance matters at all, you are better 
off to try to find an alternative to exec.


> Nevertheless our code works perfectly for our purposes.

Until the day that some manager decides that it would be great to make 
your code into a service available over the Internet, or until one of the 
other scientists decides that he really needs to access it from home, or 
somebody pastes the wrong text into the application and it blows up in 
your face... it's not just malice you need to be careful of, but also 
accidents.

The history of computing is full of systems that were designed with no 
security because it wasn't needed, until it was needed, but it was too 
late by then.

There's no need, or at least very little need, to put locks on the 
internal doors of your house, because we're not in the habit of taking 
internal doors and turning them into outside doors. But code designed to 
run inside your secure, safe network has a tendency to be re-purposed to 
run in insecure, unsafe networks, usually by people who have forgotten, 
or never knew, that they were opening up their system to code injection 
attacks.



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


Re: My own accounting python euler problem

2009-11-10 Thread MRAB

Gerry wrote:

On Nov 8, 2:42 pm, Ozz  wrote:

vsoler schreef:


And, of course, you'd want to take a look a this:  http://xkcd.com/287/


I've found 2 solutions.

(And I really should get back to what I was doing...)


Gerry

Instead of subsets, do you mean permutations/combinations?  Since 2
invoices can have the same amount perhaps the terms permutation is
better.

As some other poster already suggested 'powerset' 
(http://en.wikipedia.org/wiki/Power_set) may be a better name, except
for those duplicates, of course. On the other hand, I think viewing it
as a powerset is the most 'natural' in this case. (imo permutations are
about the order of objects, not about whether the objects are included
in a set or not)

cheers,
Ozz




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


Re: Create object from variable indirect reference?

2009-11-10 Thread NickC

Many thanks for the replies.  getattr() works great:

>>> name='Moon'
>>> m2 = getattr(ephem,name)()
>>> m2.compute(home)
>>> print ephem.localtime(m2.rise_time)
2009-11-11 01:30:36.02

shows the moon will rise at 1:30am localtime tonight at my home location.

Excellent.

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


Re: how to create a pip package

2009-11-10 Thread Floris Bruynooghe
On Nov 10, 2:30 pm, Phlip  wrote:
> On Nov 10, 1:54 am, Wolodja Wentland 
> wrote:
>
> >http://docs.python.org/library/distutils.html#module-distutils
> >http://packages.python.org/distribute/
>
> ktx... now some utterly retarded questions to prevent false starts.
>
> the distutils page starts with "from distutils.core import setup".
>
> but a sample project on github, presumably a pippable project, starts
> with:
>
>     from setuptools import setup, find_packages
>
> (and it also has ez_setup())
>
> I don't foresee my project growing larger than one* file any time
> soon. 'pip freeze' prob'ly won't write a setup.py. What is the
> absolute simplest setup.py to stick my project on the PYTHONPATH, and
> be done with it?

Do what the distutils page says, setuptools tries to extend distutils
with many fancy things but if you don't need those (and that's what it
sounds like) then sticking to distutils is better as you only require
the python stdlib.

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


Re: Create object from variable indirect reference?

2009-11-10 Thread Hrvoje Niksic
NickC  writes:

> moon2 = ephem.${!options.body}()

moon2 = getattr(ephem, options.body)()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is None or == None ?

2009-11-10 Thread Chris Kaynor
On Tue, Nov 10, 2009 at 7:56 AM, Marco Mariani  wrote:

> Grant Edwards wrote:
>
>  MacOS applications made the same mistake on the 68K.
>>
>
> And and awful lot of the Amiga software, with the same 24/32 bit CPU.
>
> I did it too, every pointer came with 8 free bits so why not use them?
>
>
>
>  It wasn't the decades-long global debacle that was the MS-DOS
>> memory model, but it did cause problems when CPUs came out that
>> implemented those address lines and RAM became cheap enough
>> that people needed to use them.
>>
>
> I suppose that's the reason many games didn't work on the 68020+
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

As a note, the official specification (Ihttp://
www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24593.pdf),
the 64-bit pointers are required to be in canonical form for the exact
reason of helping prevent these mistakes from being repeated.

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


Re: My own accounting python euler problem

2009-11-10 Thread Mel
Gerry wrote:

> On Nov 8, 2:42 pm, Ozz  wrote:
>> vsoler schreef:
>>
> And, of course, you'd want to take a look a this:  http://xkcd.com/287/

:) I remember that.

mwil...@tecumseth:~/sandbox$ python xkcd_complete.py
[1, 0, 0, 2, 0, 1] 1505
[7] 1505

Mel.

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


Re: is None or == None ?

2009-11-10 Thread Grant Edwards
On 2009-11-10, Marco Mariani  wrote:
> Grant Edwards wrote:
>
>> MacOS applications made the same mistake on the 68K.


> And and awful lot of the Amiga software, with the same 24/32
> bit CPU.
>
> I did it too, every pointer came with 8 free bits so why not
> use them?

TANSTAFB  ;)

I should probably add that MacOS itself used the same trick
until system 7.

>> It wasn't the decades-long global debacle that was the MS-DOS
>> memory model, but it did cause problems when CPUs came out that
>> implemented those address lines and RAM became cheap enough
>> that people needed to use them.
>
> I suppose that's the reason many games didn't work on the 68020+

Probably.  IIRC, it took a while for some vendors to come out
with "32-bit clean" versions of products.

http://en.wikipedia.org/wiki/Mac_OS_memory_management#32-bit_clean

-- 
Grant Edwards   grante Yow! I know how to do
  at   SPECIAL EFFECTS!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as network protocol

2009-11-10 Thread Grant Edwards
On 2009-11-10, Steven D'Aprano  wrote:
> On Tue, 10 Nov 2009 16:31:13 +0100, Daniel Fetchinson wrote about using 
> exec:
>
>>> This is a *really* bad idea.
>> 
>> How do you know for sure? Maybe the OP wants to use this thing
>> with 3 known researchers working on a cluster that is not even
>> visible to the outside world.

And those three researchers are perfect?  They've never even
made a typographical error?

>> In such a setup the model the OP suggested is a perfectly
>> reasonable one. I say this because I often work in such an
>> environment and security is never an issue for us. And I find
>> it always amusing that whenever I outline our code to a
>> non-scientist programmer they always run away in shock and
>> never talk to us again 
>
> You might be a great scientist, but perhaps you should pay
> attention to the experts on programming who tell you that this
> is opening a potential security hole in your system.
>
> No, it's not a "perfectly reasonable" tactic. It's a risky
> tactic that only works because the environment you use it in
> is so limited and the users so trusted.

Even then it only works until a trusted user makes a mistake
and types the wrong thing. A stupid mistake can do just as much
damage as an evil mastermind.

-- 
Grant Edwards   grante Yow! Is this an out-take
  at   from the "BRADY BUNCH"?
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to create a pip package

2009-11-10 Thread Wolodja Wentland
On Tue, Nov 10, 2009 at 06:30 -0800, Phlip wrote:
> On Nov 10, 1:54 am, Wolodja Wentland 
> wrote:
> 
> > http://docs.python.org/library/distutils.html#module-distutils
> > http://packages.python.org/distribute/
> 
> ktx... now some utterly retarded questions to prevent false starts.

> the distutils page starts with "from distutils.core import setup".

[..]

> from setuptools import setup, find_packages

It will be enough to use the method outlined in the distutils
documentation. Setuptools is a third-party library that used to be the
de-facto standard for Python packaging. I don't want to go into detail
why setuptools might not be the best choice for a project and leave that
to [1] and [2].

The Distribute project was started in order to fix several bugs in
setuptools which was essentially unmaintained for a year and provides a
backward compatible fork in the 0.6 branch.

kind regards

Wolodja

[1] http://www.b-list.org/weblog/2008/dec/14/packaging/
[2] http://blog.ianbicking.org/2008/12/14/a-few-corrections-to-on-packaging/


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to create a pip package

2009-11-10 Thread Phlip
> >     from setuptools import setup, find_packages
>
> It will be enough to use the method outlined in the distutils
> documentation. Setuptools is a third-party library that used to be the
> de-facto standard for Python packaging. I don't want to go into detail
> why setuptools might not be the best choice for a project...

Good - thanks, all! Those were the exact details I sought to avoid...

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


Re: Python as network protocol

2009-11-10 Thread Diez B. Roggisch

Daniel Fetchinson schrieb:

I want to implement such specific feature:
I have a server written in Python. I have a client written in C++. I
want to use Python as network protocol between them. I mean: client
send to server such string: "a = MyObject()", so object of this type
will appear in server. Any ideas how to simplify this implementation?
I make XML-RPC/SOAP server using twisted which just execute sended
string. But I don't know how to:
1. Restrict usage of some modules on client side (os, sys etc..)
2. Divide variables of different clients. Generally, I know that I
should use "exec .. in .. " construct, but don't know how to
distinguish between clients in twisted.


Have you considered using pyro?

http://pyro.sourceforge.net/


Have you considered that C++ doesn't support Pyro?





This is a *really* bad idea.


How do you know for sure? Maybe the OP wants to use this thing with 3
known researchers working on a cluster that is not even visible to the
outside world. In such a setup the model the OP suggested is a
perfectly reasonable one. I say this because I often work in such an
environment and security is never an issue for us. And I find it
always amusing that whenever I outline our code to a non-scientist
programmer they always run away in shock and never talk to us again :)
Nevertheless our code works perfectly for our purposes.


If you read the OP message, he himself stated that he wants to lock down 
the interpreter. Which isn't possible. So (scientific) reasoning can 
tell us that his application might not run in a happy-go-lucky 
environment of scientific research.


Additionally, there is always the option of mistakes being made 
involuntarily, so desigining a system that encourages these is a bad idea.


And last but not least, instead of having a well-defined protocol 
relying on arbitrary in-process manipulation is a nightmare to maintain, 
and might well lead to nasty bugs, crashes or even subtler problems 
(think changing a global constant for all the others...) that are nearly 
impossible to debug.


Plus the issues the others mentioned.

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


Re: Python as network protocol

2009-11-10 Thread geremy condra
On Tue, Nov 10, 2009 at 10:56 AM, Steven D'Aprano
 wrote:
> On Tue, 10 Nov 2009 16:31:13 +0100, Daniel Fetchinson wrote about using
> exec:
>
>>> This is a *really* bad idea.
>>
>> How do you know for sure? Maybe the OP wants to use this thing with 3
>> known researchers working on a cluster that is not even visible to the
>> outside world. In such a setup the model the OP suggested is a perfectly
>> reasonable one. I say this because I often work in such an environment
>> and security is never an issue for us. And I find it always amusing that
>> whenever I outline our code to a non-scientist programmer they always
>> run away in shock and never talk to us again
>
> You might be a great scientist, but perhaps you should pay attention to
> the experts on programming who tell you that this is opening a potential
> security hole in your system.
>
> No, it's not a "perfectly reasonable" tactic. It's a risky tactic that
> only works because the environment you use it in is so limited and the
> users so trusted. Can you guarantee that will never change? If not, then
> you should rethink your tactic of using exec.
>
> Besides, as a general rule, exec is around an order of magnitude slower
> than running code directly. If performance matters at all, you are better
> off to try to find an alternative to exec.
>
>
>> Nevertheless our code works perfectly for our purposes.
>
> Until the day that some manager decides that it would be great to make
> your code into a service available over the Internet, or until one of the
> other scientists decides that he really needs to access it from home, or
> somebody pastes the wrong text into the application and it blows up in
> your face... it's not just malice you need to be careful of, but also
> accidents.
>
> The history of computing is full of systems that were designed with no
> security because it wasn't needed, until it was needed, but it was too
> late by then.
>
> There's no need, or at least very little need, to put locks on the
> internal doors of your house, because we're not in the habit of taking
> internal doors and turning them into outside doors. But code designed to
> run inside your secure, safe network has a tendency to be re-purposed to
> run in insecure, unsafe networks, usually by people who have forgotten,
> or never knew, that they were opening up their system to code injection
> attacks.
>
>
>
> --
> Steven

Steven, remember a few weeks ago when you tried to explain to me that
the person who was storing windows administrative passwords using a
40 byte xor cipher with the hardcoded password might not be doing
something stupid because I didn't know what their threat model was?
Yeah- what you just said is what I was trying to explain then.

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


Re: list vs tuple for a dict key- why aren't both hashable?

2009-11-10 Thread Syeberman
On Nov 8, 3:42 pm, Mick Krippendorf  wrote:
> Wells wrote:
> > I'm not quite understanding why a tuple is hashable but a list is not.
>
> The short answer has already been given.
>
The short answer isn't entirely correct, however.  Tuples are only
hashable so long as their elements are all hashable.  The
documentation, though, doesn't properly describe this:
  http://docs.python.org/glossary.html#term-hashable
  "All of Python’s immutable built-in objects are hashable"
-- 
http://mail.python.org/mailman/listinfo/python-list


Calendar Stuff

2009-11-10 Thread Victor Subervi
Hi;
I have the following code:

import calendar, datetime

def cal():
  ...
  myCal = calendar.Calendar(calendar.SUNDAY)
  today = datetime.date.today()
  day = today.day
  mo = today.month
  yr = today.year
#  month = myCal.monthdayscalendar(int(time.strftime("%Y"))
  month = myCal.monthdayscalendar(yr, mo)
  print 'hi'

html headers are included. No matter which one of the last two lines I
comment out, I never get to the point of printing 'hi'. (If I comment them
both out, it does print.) What do?
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-URL! - weekly Python news and links (Nov 10)

2009-11-10 Thread Gabriel Genellina
QOTW:  "Don't get me wrong - innovation often comes from scratching ones
personal itch. But you seem to be suffering from a rather bad case of
neurodermatitis." - Diez B. Roggisch, on ... well, personal style in 
problem-solving
http://groups.google.com/group/comp.lang.python/msg/4cf102bdd3a3267b


Why aren't lists usable as dictionary keys? What do you mean, "hashable"?
http://groups.google.com/group/comp.lang.python/t/929905a622d704b4/

`x == None` or `x is None` -- which one is the right way?
http://groups.google.com/group/comp.lang.python/t/1d9112d5bbe243d3/

At Microsoft, they performed empirical research about common
software engineering assumptions: "high test coverage is better",
"write test code first", "use assertions", and others:
http://groups.google.com/group/comp.lang.python/t/e06ac9acd1fc97fa/

The best way to populate a list of size N:
http://groups.google.com/group/comp.lang.python/t/fd07df5ffde3db83/

A new variant of an old problem: I got a single check from my customer -
which ones among all pending invoices did he intend to pay?
http://groups.google.com/group/comp.lang.python/t/13f7645d99543e8/

How to test code that uses urllib without depending on external resources?
http://groups.google.com/group/comp.lang.python/t/707f53122777e84a/

Singletons are hard to test too:
http://groups.google.com/group/comp.lang.python/t/dbe458917dd9b393/

How to use Filters in the logging module:
http://groups.google.com/group/comp.lang.python/t/6a002ee599fd94ba/

Delete items from a list that match a certain pattern:
http://groups.google.com/group/comp.lang.python/t/f6d0a08ad2642ddf/

What is the correct way to port codecs.open to python 3.1?
http://groups.google.com/group/comp.lang.python/t/b93ad93148bdc26d/

py2exe, cx_freeze, py2app: a comparison
http://groups.google.com/group/comp.lang.python/t/5abb44388a28ce25/

How to cancel a thread from another one:
http://groups.google.com/group/comp.lang.python/t/af903ef349b1bddf/

Why does "help(import)" not work?
http://groups.google.com/group/comp.lang.python/t/d8821fe86b3eda9a/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiasts":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" site:
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://code.activestate.com/recipes/langs/python/

Many Python conferences around the world are in prepara

Re: Python as network protocol

2009-11-10 Thread Daniel Fetchinson
>>> This is a *really* bad idea.
>>
>> How do you know for sure? Maybe the OP wants to use this thing with 3
>> known researchers working on a cluster that is not even visible to the
>> outside world. In such a setup the model the OP suggested is a
>> perfectly reasonable one. I say this because I often work in such an
>> environment and security is never an issue for us. And I find it
>> always amusing that whenever I outline our code to a non-scientist
>> programmer they always run away in shock and never talk to us again :)
>> Nevertheless our code works perfectly for our purposes.
>
> It is a bad idea because that's exactly why we now have a spam
> problem. It _was_ a trusted environment once upon a time. Just check
> your spam messages to see why ignoring security can lead to really bad
> results.
>
> Do you know for sure that in say 3-5 years from now on your software
> isn't released into the wild and then has no security at all?

In my case, yes, I know for sure that the software I was talking about
will only be used by my colleagues (3-4 people) and will only be used
on our system. Why? Because the code is completely unportable and
undocumented and was made to serve one purpose alone: to just work on
our clusters which are not visible from the internet. And it serves
this purpose great.

In case we need to share this code, release it, modify it, etc, etc,
we will think about all the security issues. But not until then.

The point I'm trying to make is that of course I'm aware of the risks
in our approach, the environment we are working in allows for these
risks. In another situation I wouldn't use this type of approach. As a
programmer I decide what solution to use in which environment and I
intend to not over kill.

No risk environment = security holes are okay.
Risky environment = secure code from day one.

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Threaded import hang in cPickle.dumps

2009-11-10 Thread Zac Burns
Using python 2.6

cPickle.dumps has an import which is causing my application to hang.
(figured out by overriding builtin.__import__ with a print and seeing
that this is the last line of code being run. I'm running
cPickle.dumps in a thread, which leads me to believe that the first
restriction here is the cause:
http://docs.python.org/library/threading.html#importing-in-threaded-code

What can I do about this?

--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threaded import hang in cPickle.dumps

2009-11-10 Thread Zac Burns
Oh, I'm pickling an NotImplementedError and it's importing exceptions.
--
Zachary Burns
(407)590-4814
Aim - Zac256FL
Production Engineer (Digital Overlord)
Zindagi Games



On Tue, Nov 10, 2009 at 10:50 AM, Zac Burns  wrote:
> Using python 2.6
>
> cPickle.dumps has an import which is causing my application to hang.
> (figured out by overriding builtin.__import__ with a print and seeing
> that this is the last line of code being run. I'm running
> cPickle.dumps in a thread, which leads me to believe that the first
> restriction here is the cause:
> http://docs.python.org/library/threading.html#importing-in-threaded-code
>
> What can I do about this?
>
> --
> Zachary Burns
> (407)590-4814
> Aim - Zac256FL
> Production Engineer (Digital Overlord)
> Zindagi Games
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as network protocol

2009-11-10 Thread Daniel Fetchinson
>>> This is a *really* bad idea.
>>
>> How do you know for sure? Maybe the OP wants to use this thing with 3
>> known researchers working on a cluster that is not even visible to the
>> outside world. In such a setup the model the OP suggested is a perfectly
>> reasonable one. I say this because I often work in such an environment
>> and security is never an issue for us. And I find it always amusing that
>> whenever I outline our code to a non-scientist programmer they always
>> run away in shock and never talk to us again
>
> You might be a great scientist, but perhaps you should pay attention to
> the experts on programming who tell you that this is opening a potential
> security hole in your system.

Well, I'm completely aware of the potential security threats. It's not
something I'm overlooking, rather, I'm taking them into account
according to their real importance in our specific environment. And by
the way, I'm not a great scientist :)

However if the environment is such that the potential risks can not be
exploited (not even in theory), because exactly 3 people have access
to a machine and all of them are trustworthy and the clusters on which
the code runs is not accessible from the internet, well, then the
'security hole' which would be dangerous otherwise, is risk free in
this case.

> No, it's not a "perfectly reasonable" tactic.

I believe it is.

> It's a risky tactic that
> only works because the environment you use it in is so limited and the
> users so trusted.

Exactly!

> Can you guarantee that will never change?

Yes. I will simply not release the code to anyone.

> If not, then you should rethink your tactic of using exec.

I agree.

> Besides, as a general rule, exec is around an order of magnitude slower
> than running code directly. If performance matters at all, you are better
> off to try to find an alternative to exec.

That is a good point, thanks. If we'll have performance issues, I'll
remember this.


>> Nevertheless our code works perfectly for our purposes.
>
> Until the day that some manager decides that it would be great to make
> your code into a service available over the Internet, or until one of the
> other scientists decides that he really needs to access it from home, or
> somebody pastes the wrong text into the application and it blows up in
> your face

I agree. If any of those things would occur, our software would be
pretty dangerous.

> ... it's not just malice you need to be careful of, but also accidents.

Agreed. If we mistype something (as suggested by others), well, it's
our fault. We know what will happen, if we still do it, well, it's our
fault, we'll fix it. Believe it or not, so far (after about 1.5 years
of operation) there were no typos that created problems.

> The history of computing is full of systems that were designed with no
> security because it wasn't needed, until it was needed, but it was too
> late by then.
>
> There's no need, or at least very little need, to put locks on the
> internal doors of your house, because we're not in the habit of taking
> internal doors and turning them into outside doors. But code designed to
> run inside your secure, safe network has a tendency to be re-purposed to
> run in insecure, unsafe networks, usually by people who have forgotten,
> or never knew, that they were opening up their system to code injection
> attacks.

On general grounds, you are right, of course.

My point is that hacking can still be a fun and easy-going activity
when one writes code for himself (almost) without regards to security
and nasty things like that creeping in from the outside. I'm the king
in my castle, although I'm fully aware of the fact that my castle
might be ugly from the outside :)

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is None or == None ?

2009-11-10 Thread Steven D'Aprano
On Tue, 10 Nov 2009 15:46:10 +, Grant Edwards wrote:

> On 2009-11-10, Rhodri James  wrote:
>> On Sun, 08 Nov 2009 19:45:31 -, Terry Reedy 
>> wrote:
>>
>>> I believe the use of tagged pointers has been considered and so far
>>> rejected by the CPython developers. And no one else that I know of has
>>> developed a fork for that. It would seem more feasible with 64 bit
>>> pointers where there seem to be spare bits. But CPython will have to
>>> support 32 bit machines for several years.
>>
>> I've seen that mistake made twice (IBM 370 architecture (probably 360
>> too, I'm too young to have used it) and ARM2/ARM3).  I'd rather not see
>> it a third time, thank you.
> 
> MacOS applications made the same mistake on the 68K.  They reserved the
> high-end bits in a 32-bit pointer and used them to contain
> meta-information.


Obviously that was their mistake. They should have used the low-end bits 
for the metadata, instead of the more valuable high-end.


High-end-is-always-better-right?-ly y'rs,


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


Re: Calendar Stuff

2009-11-10 Thread MRAB

Victor Subervi wrote:

Hi;
I have the following code:

import calendar, datetime

def cal():
  ...
  myCal = calendar.Calendar(calendar.SUNDAY)
  today = datetime.date.today()
  day = today.day
  mo = today.month
  yr = today.year
#  month = myCal.monthdayscalendar(int(time.strftime("%Y"))
  month = myCal.monthdayscalendar(yr, mo)
  print 'hi'

html headers are included. No matter which one of the last two lines I 
comment out, I never get to the point of printing 'hi'. (If I comment 
them both out, it does print.) What do?



Read the tracebacks?

The commented line will raise an exception because:

1. There's a final ')' missing.

2. You haven't imported 'time'.

3. .monthdayscalendar() requires the year and month.

I don't know why you're writing 'int(time.strftime("%Y"))' because you
already have the year in 'yr'.

The code above works for me if I comment out the line '...'.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python as network protocol

2009-11-10 Thread Steven D'Aprano
On Tue, 10 Nov 2009 12:28:49 -0500, geremy condra wrote:

> Steven, remember a few weeks ago when you tried to explain to me that
> the person who was storing windows administrative passwords using a 40
> byte xor cipher with the hardcoded password might not be doing something
> stupid because I didn't know what their threat model was? Yeah- what you
> just said is what I was trying to explain then.

No, I'm sure that wasn't me... perhaps some other Steven D'Aprano... from 
the Evil Dimension...

*wink*

Seriously, I'm not sure if I knew that the person was storing Windows 
admin passwords at the time. If I had, I probably would have agreed with 
you. But using a 40 byte xor cipher to obfuscate some strings in a game 
is perfectly valid -- not every locked box needs to be a safe with 18 
inch tempered steel walls.

I can only repeat what I said to Daniel: can you guarantee that the nice 
safe, low-risk environment will never change? If not, then choose a more 
realistic threat model, and build the walls of your locked box 
accordingly.


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


Python C api: create a new object class

2009-11-10 Thread lallous

Hello

I have 3 questions, hope someone can help:

1)
How can I create an instance class in Python, currently I do:

class empty:
 pass

Then anytime I want that class (which I treat like a dictionary):

o = empty()
o.myattr = 1
etc

Is there is a one line syntax to instantiate an instance?

Any other ways than this:
o = new.classobj('object', (), {})

2)

How can I, similarly, create an object "o" in C api:

PyObject *o = what_to_call()


PyObject_SetAttrString(o, "attrname", py_val)

...

One way I found was first calling PyClass_New() (to create an empty class) 
and then passing the return value to PyInstance_NewRaw to get a new instance 
of that empty class.


Can I achieve the same otherwise?

3)

Given a PyObject* is there is a way to tell if one can call 
PyObject_SetAttrString() on that object w/o getting an error?


For example, before calling a PyObject* one can see if it is callable, but 
can I test if an object supports setattr?


(from C api)

Thank you,

Elias 


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


Re: advice needed for lazy evaluation mechanism

2009-11-10 Thread Steven D'Aprano
On Sun, 08 Nov 2009 14:41:27 -0800, markolopa wrote:

> Hi,
> 
> Could you please give me some advice on the piece of code I am writing?
> 
> My system has several possible outputs, some of them are not always
> needed. I started to get confused with the code flow conditions needed
> to avoid doing unnecessary work. 

How many dozens of man-hours (yours, and the people who have to maintain 
the software after you have moved on) of confusion are you going to spend 
to avoid how many microseconds of execution time? So what if your system 
takes 35ms instead of 18ms to calculate the result?

As Tony Hoare famously said: "We should forget about the small 
efficiencies, say about 97% of the time: Premature optimization is the 
root of all evil."

Of course, all of this assumes that the routines you are trying to avoid 
calling don't require hours of running time each time you call them... 


> So I am trying to restructure it using lazy evaluation.

Oh great, avoiding confusion with something even more confusing.


> - Is there a more standard (pythonic) way to do what I am trying to do?

Yes. Avoid it. Do the simplest thing that works until you *know* -- 
because you have profiled it -- that it is too slow. Until then, all that 
complication you've built, all that over-engineered jungle of classes and 
abstract classes, is unnecessary. I find it beyond all credibility that 
your data is so complicated that you need a plug-in system just to manage 
the methods you need to calculate your data.

Just create some properties, like this one:

class Example(object):
def __init__(self, birth_year):
self.birth_year = birth_year
@property
def age(self):
return 2009 - self.birth_year  # FIXME -- it won't be 2009 forever

And there you have a lazily-evaluated age property. Not complicated 
enough? The 3ms it takes to calculate the age is too long? Cache it!

class Example(object):
def __init__(self, birth_year):
self.birth_year = birth_year
self._age = None
@property
def age(self):
a = self._age
if a is None:
a = 2009 - self.birth_year
self._age = a
return a

Now all you need is to invalidate the cache if the birth_year changes. So 
you make birth_year a property too:

class Example(object):
def __init__(self, birth_year):
self.birth_year = birth_year
@property
def birth_year(self):
return self._birth_year
@property.setter
# Requires Python 2.6. Also untested.
def birth_year(self, year):
self._birth_year = year
self._age = None
@property
def age(self):
a = self._age
if a is None:
a = 2009 - self.birth_year
self._age = a
return a



> Are there libraries, design patterns, functional programming structures
> to use to achieve what I am looking for (i.e. am I trying to reinvent
> the wheel)?

The most important buzzwords you want are YAGNI and Premature 
Generalisation, and perhaps a touch of Architecture Astronaut:

http://www.joelonsoftware.com/items/2008/05/01.html


> - Is the coding style good?
> - Can I avoid the eval command in Repository.add_routine? What I want
> there is to be able to have a generic code for the repository which does
> not depend on the files containing the routines I want it to hold.

You mean the exec?

cmd = "from %s import %s\nroutine = %s()" % (file_name, class_name, 
class_name)
exec(cmd)  # XXX: ugly


Yes. Untested:

module = __import__(filename)
class_object = getattr(module, class_name)
routine = class_object()

Of course you can turn that into a one-liner:

routine = getattr(__import__(filename), class_name)()




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


New syntax for blocks

2009-11-10 Thread r
Forgive me if i don't properly explain the problem but i think the
following syntax would be quite beneficial to replace some redundant
"if's" in python code.

if something_that_returns_value() as value:
#do something with value

# Which can replace the following syntactical construct...

value = something_that_returns_value()
if value:
#do something with value

i dunno, just seems to make good sense. You save one line of code but
more importantly one indention level. However i have no idea how much
trouble the implementation would be? Now i know you could write a
function and do the following to forgo the indention...

value = something_that_returns_value()
if not value:
return
#do something with value

but that's even uglier and i would like the construct to work in
both sinlge 'ifs' and also conditional's Now some might say...Whats
the big deal, you only save one line of code?...True, but if you can
save one line of code 100 or 1000 times how many lines of code is that
my inquisitive friend?  ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


New to Python need on advice on this script

2009-11-10 Thread Jim Valenza
Hello all - I'm new to the world of Python as I am a GIS guy who would like
to broaden his horizons. I have a question about a script that we've been
working on: The purpose of the code is to *Syncronize SDE DropBox with
Regulatory Project working files.

I am looking for where the script dumps the domain list to a table and loops
through the table? Is It necessary? Seems like you should be able to simply
loop through the domain list. I was just trying to see if there was a more
straitforward way. Thanks

The script is as follows:*
**
# Create the Geoprocessor
import sys, string, os, arcgisscripting, shutil, time
gp = arcgisscripting.create()
# Jim V testing
# Allow output to overwrite
gp.OverwriteOutput = 1
gp.AddToolbox("C://Program Files//ArcGIS//ArcToolbox//Toolboxes//Data
Management Tools.tbx")
#---create a logging file named "MMDD HH_MM_QualityControlLog.txt"
theTime = time.strftime('%Y%m%d %H_%M')
#logfilename = "H:\\Development\\Python\\" + theTime + "_PODsQAQCLog.txt"
logfilename =
"L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basin\\Pipeline\\QAQC_Scripts\\"
+ theTime + "_PODsQAQCLog.txt"
log = open(logfilename,'w')
log.write(time.ctime() + "\n")
print time.ctime()
THE_WORKSPACE =
os.path.normpath("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin") +
"\\"  #REAL MODE LINE
#THE_WORKSPACE = os.path.normpath("H:/Development/testdata") + "\\"  #TEST
MODE LINE
log.write("THE_WORKSPACE IS " + THE_WORKSPACE + "\n")
print "THE_WORKSPACE IS " + THE_WORKSPACE
P_CODE = "P_CODE"
#Create table of valid P_CODEs and convert to List
gp.DomainToTable_management(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\GIS_Data\RMP_Current_Geodatabase\rmp_2_5.mdb",
\
"regulatory_p_code",
r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\test.mdb\code_table",
\
"pcode", "pdesc", "")
#searchRows = gp.searchCursor(r"H:\Development\temp\test.mdb\code_table")
searchRows =
gp.searchCursor(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\test.mdb\code_table")
searchRow = searchRows.next()
domainList = []
while searchRow:
domainList.append(searchRow.pcode)
searchRow = searchRows.next()
#print domainList
try:
#Get Workspaces from text file
#for line in open("H:/Development/testdata/PRB_POD_Paths.txt", 'r'):
#REAL MODE LINE
for line in
open("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin/Pipeline/QAQC_Scripts/PRB_POD_Paths.txt",
'r'):   #REAL MODE LINE
#for line in open("H:/Development/testdata/workspaces.txt", 'r'):
#TEST MODE LINE
if not line: break
line = line.strip()
if not line.startswith("#"): # skip lines that start with #
ws, P = line.split("RMP_2_5_",1) #parse line to get path and
P_CODE
log.write("  " + "\n")
log.write("  " + "\n")
log.write(P + "\n")
print "  "
print P
src = THE_WORKSPACE + line  #defines each workspace path

#If the Geodatabase exists, perform the operations
if os.path.exists(src):
#Archive Geodatabase before running script
log.write("The Geodatabase exists " + src + "\n")
print "The Geodatabase exists " + src
archiveFolder = THE_WORKSPACE + ws + "Archive" + "\\" +
"RMP_2_5_" + P
log.write("archiveFolder is " + archiveFolder + "\n")
print "archiveFolder is " + archiveFolder
shutil.copy(src, archiveFolder)#Archive the Geodatabase
#Set workspace and variables
gp.workspace = src
log.write(gp.workspace + "\n")
print gp.workspace
P_Value = (P.strip(".mdb"))
#Valitate P_Code value against Domain list
if P_Value in domainList:
log.write("P_Code is valid:  " + P_Value + "\n")
print "P_Code is valid:  " + P_Value
# List all feature classes in feature datasets
fdss = gp.ListDatasets("","")
fds = fdss.Next()
while fds:
fcs = gp.ListFeatureClasses("*","",fds)
fc = fcs.Next()
while fc:
gp.CalculateField_management(fc, P_CODE, "'" +
P_Value + "'", "PYTHON")#Calc P_Code
gp.RepairGeometry(fc,
r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_Scripts\outy.shp")
fc = fcs.Next()
print fc
fds = fdss.Next()
#Copy the Geodatabase to the SDE InBox
sdeInbox = "S:/Production/DropBox/InBox"   #REAL MODE
LINE
#sdeInbox = "H:/Development/testInbox"   #TEST MODE LINE
log.write("sdeInb

Re: Is it possible to get the Physical memory address of a variable in python?

2009-11-10 Thread Dave Angel

Ognjen Bezanov wrote:

Hey,

Thanks for all the responses guys. In hindsight I probably should have 
explained why on earth I'd need the physical address from an 
interpreted language.


I'm trying to see if there is any way I can make Python share data 
between two hosts using DMA transfers over a firewire connection, so 
avoiding the need for another layer on top such as IPv4 + Python sockets.


Thanks to some old python bindings which I updated to python 2.6, I 
can read any write to the RAM of any firewire connected host within 
python. Because it uses DMA (the cpu is not involved in this at all), 
I can only specify a physical address within the 4GB ram limit to read 
from and write to.


Now what I've done so far is on the remote host I run python and set a 
variable as so:


a = "foo"
print a
'foo'

Then on the local host I run a python script that scans the entire RAM 
looking for the string "foo", and replaces it with the string "oof". I 
have had success with this method. Once it's done and I do "print a" 
on the remote host, I get "oof" as the variable value, so in theory it 
can work.


Problem is that it's slow. Scanning 3GB of RAM every time you want to 
do this is not a good method. I thought that if I could get python to 
return the physical address of where the value of a variable is, then 
I can just jump to that address and write the data.


From what I've been told so far, it's not possible to do this without 
some OS-specific (Linux in this case) syscall. Is this correct?


Thanks!


Ognjen


I'm sure you realize that scanning for a 3 byte tag is not only slow, 
but very dangerous.  It could easily have been three other bytes which 
just happened to match this string.  And those bytes could have been 
part of a disk directory entry (result disk corruption) or some other 
application.  Further, between the time you did the search and the time 
when you updated, the relevant bytes could have been swapped to disk, 
and something else put in the same physical address.


Anyway, I've been assuming all along that you meant address in the sense 
that a C program uses it, which is a linear address.  But as long as 
you're running on an OS that has virtual memory running, there's another 
translation going on invisibly to the application, which converts linear 
to physical.  So even after you get a memory address, you need to 
convince the OS to lock such memory in place for awhile, and then tell 
you where (physical address)  it locked it.


Note also that if a range of addresses spans a 4k boundary (for Intel 
architecture), it's possible that the physical addresses are not even 
contiguous.  But the system calls from Windows (and presumably also from 
Linux) can hide that from you, via double-buffering.


DaveA

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


Re: Calendar Stuff

2009-11-10 Thread Victor Subervi
On Tue, Nov 10, 2009 at 2:02 PM, MRAB  wrote:

> Victor Subervi wrote:
>
>> Hi;
>> I have the following code:
>>
>> import calendar, datetime
>>
>> def cal():
>>  ...
>>  myCal = calendar.Calendar(calendar.SUNDAY)
>>  today = datetime.date.today()
>>  day = today.day
>>  mo = today.month
>>  yr = today.year
>> #  month = myCal.monthdayscalendar(int(time.strftime("%Y"))
>>  month = myCal.monthdayscalendar(yr, mo)
>>  print 'hi'
>>
>> html headers are included. No matter which one of the last two lines I
>> comment out, I never get to the point of printing 'hi'. (If I comment them
>> both out, it does print.) What do?
>>
>>  Read the tracebacks?
>
> The commented line will raise an exception because:
>
> 1. There's a final ')' missing.
>
> 2. You haven't imported 'time'.
>
> 3. .monthdayscalendar() requires the year and month.
>
> I don't know why you're writing 'int(time.strftime("%Y"))' because you
> already have the year in 'yr'.
>
> The code above works for me if I comment out the line '...'.
> --
>  

It works fine for me in the python interpreter but not in the page from
which it's called! You say import time, but where do I call time in my
script? Here's the code (abbreviated just to print something out to see it
work), please advise if you can:

#!/usr/bin/python

import string
import sys,os
sys.path.append(os.getcwd())
import calendar, datetime, time
import MySQLdb
import string, re
from login import login

def calendarPrint():
  print "Content-Type: text/html"
  print
  print """
http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd";>
http://www.w3.org/1999/xhtml";>

.text { font-family: Arial, Helvetica, sans-serif; font-size: 16px;
text-decoration: none; text-align: justify }

NR Electric






"""
  myCal = calendar.Calendar(calendar.SUNDAY)
  today = datetime.date.today()
  day = today.day
  mo = today.month
  yr = today.year
  month = myCal.monthdayscalendar(yr, mo)
  print month

calendarPrint()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as network protocol

2009-11-10 Thread Diez B. Roggisch

My point is that hacking can still be a fun and easy-going activity
when one writes code for himself (almost) without regards to security
and nasty things like that creeping in from the outside. I'm the king
in my castle, although I'm fully aware of the fact that my castle
might be ugly from the outside :)


Which is a relevant statement in the context of the OP seeking advice on 
*secure ways* of executing code in a restricted environment in exactly 
what way?


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


Re: Python as network protocol

2009-11-10 Thread Robert Latest
Grant Edwards wrote:
> On 2009-11-10, Steven D'Aprano  wrote:
>>> How do you know for sure? Maybe the OP wants to use this thing
>>> with 3 known researchers working on a cluster that is not even
>>> visible to the outside world.
>
> And those three researchers are perfect?  They've never even
> made a typographical error?

Anybody with sufficient access can bring down a system by accident. It
doesn't matter if it's a single computer or an isolated cluster.

The question on how accident-proof the network needs to be depends on
how many people's work is affected by someone bringing it down. Since we
know nothing about the scale of the network we can't say that the
proposed protocol is "too unsafe".

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


Re: New to Python need on advice on this script

2009-11-10 Thread MRAB

Jim Valenza wrote:
Hello all - I'm new to the world of Python as I am a GIS guy who would 
like to broaden his horizons. I have a question about a script that 
we've been working on: The purpose of the code is to *Syncronize SDE 
DropBox with Regulatory Project working files. *
 
I am looking for where the script dumps the domain list to a table and 
loops through the table? Is It necessary? Seems like you should be able 
to simply loop through the domain list. I was just trying to see if 
there was a more straitforward way. Thanks


The script is as follows:


[snip]

I've spotted a bug:

P_Value = (P.strip(".mdb"))

The .strip() method DOESN'T strip off a string, it strips CHARACTERS off
BOTH ends.

P_Value will be P but with any number of the characters ".", "m", "d" or
"b" stripped off both ends, for example, if P == "my_database.mdb" then
P_Value will be "y_database".

You should do something like:

if P.endswith(".mdb"):
P_Value = P[ : -4]
else:
P_Value = P

Another point: you're recording the valid domains in a list and then
checking with:

if P_Value in domainList:

This will perform a linear search of the list, which can be slow if the
list is long.

It would be much more efficient to put the domains in a set instead.
Checking for the presence of an item in a set is fast.

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


Re: New syntax for blocks

2009-11-10 Thread Robert Latest
r wrote:
> Forgive me if i don't properly explain the problem but i think the
> following syntax would be quite beneficial to replace some redundant
> "if's" in python code.
>
> if something_that_returns_value() as value:
> #do something with value
>
> # Which can replace the following syntactical construct...
>
> value = something_that_returns_value()
> if value:
> #do something with value
>
> i dunno, just seems to make good sense. You save one line of code but
> more importantly one indention level.

Typical case in matching regexes. But where do we save an indentation
level?

Also it's not the "if" that is (if at all) redundant here but the assignment. 

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


DHT for Python 3.x?

2009-11-10 Thread Salim Fadhley
There are plenty of good DHT projects for Python 2.x, however from
what I can tell none of them have made the jump to 3.x yet.

I'm really keen to support Python 3.x for a project I'm working on. I
know that many developers (correctly) consider switching to Python 3
foolish since it is less supported at the moment, but nevertheless I
am keen to carry on.

So can somebody recommend me a working implementation of a DHT which
will work on Python 3.x and preferably Python 2.6 as well.

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


Can't Write File

2009-11-10 Thread Victor Subervi
Hi;
I've determined the problem in a script is I can't open a file to write it:
script = open(getpic, "w")  # where getpic is already defined
Here are the permissions:
-rwxr-xr-x  1 root root  4649 Nov 10 12:31 start.py
What am I doing wrong?
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: eGenix pyOpenSSL Distribution 0.9.0-0.9.8l

2009-11-10 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

   eGenix.com pyOpenSSL Distribution

  Version 0.9.0-0.9.8l


 An easy-to-install and easy-to-use distribution
 of the pyOpenSSL Python interface for OpenSSL -
available for Windows, Mac OS X and Unix platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.9.0-0.9.8l-1.html



INTRODUCTION

The eGenix.com pyOpenSSL Distribution includes everything you need to
get started with SSL in Python.

It comes with an easy-to-use installer that includes the most recent
OpenSSL library versions in pre-compiled form, making your application
independent of OS provided OpenSSL libraries:

http://www.egenix.com/products/python/pyOpenSSL/

pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS-
aware network applications as well as certificate management tools:

http://pyopenssl.sourceforge.net/

OpenSSL is an open-source implementation of the SSL/TLS protocol:

http://www.openssl.org/



NEWS

This new release of the eGenix.com pyOpenSSL Distribution updates the
included OpenSSL version to 0.9.8l.

The new OpenSSL version includes an important work-around for a
serious problem in TLS, the protocol implemented and used by
OpenSSL. The Man-in-the-Middle TLS protocol attack was disclosed on
2009-11-05 and is being tracked as CVE-2009-3555:

http://isc.sans.org/diary.html?storyid=7534
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3555

IMPORTANT: The work-around chosen by the OpenSSL team is to disable
SSL session renegotiations altogether. This can cause applications
relying on this feature on the client or server side to fail. You can
still download the previous version of our pyOpenSSL distribution if
you run into such problems:

http://www.egenix.com/products/python/pyOpenSSL/0.9.0-0.9.8k_1/


As always, we provide binaries that include both pyOpenSSL and the
necessary OpenSSL libraries for all supported platforms: Windows x86,
Linux x86 and x64, Mac OS X PPC and x86.

Due to popular demand, we've also added .egg-file format versions of
our eGenix.com pyOpenSSL Distribution for Windows and Linux to the
available download options. These makes setups using e.g. zc.buildout
and other egg-file based installers a lot easier.



DOWNLOADS

The download archives and instructions for installing the package can
be found at:

http://www.egenix.com/products/python/pyOpenSSL/



UPGRADING

Before installing this version of pyOpenSSL, please make sure that
you uninstall any previously installed pyOpenSSL version. Otherwise,
you could end up not using the included OpenSSL libs.

___

SUPPORT

Commercial support for these packages is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.

___

INFORMATION

About Python (http://www.python.org/):

Python is an object-oriented Open Source programming language
which runs on all modern platforms. By integrating ease-of-use,
clarity in coding, enterprise application connectivity and rapid
application design, Python establishes an ideal programming
platform for today's IT challenges.

About eGenix (http://www.egenix.com/):

eGenix is a software project, consulting and product company
focusing on expert services and professional quality products for
companies, Python users and developers.


Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Nov 10 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't Write File

2009-11-10 Thread Victor Subervi
On Tue, Nov 10, 2009 at 3:41 PM, Rami Chowdhury wrote:

> On Tue, 10 Nov 2009 12:38:36 -0800, Victor Subervi <
> victorsube...@gmail.com> wrote:
>
>  Hi;
>> I've determined the problem in a script is I can't open a file to write
>> it:
>> script = open(getpic, "w")  # where getpic is already defined
>> Here are the permissions:
>> -rwxr-xr-x  1 root root  4649 Nov 10 12:31 start.py
>> What am I doing wrong?
>> TIA,
>> Victor
>>
>
> ...and where's the file denoted by getpic?
>

getpic is incremented. For example, it can equal "getpic1.py". I've printed
this out in the except statement, since it's failing the try, so I know it's
working. (When I tried "raise" in the except, because of the way the code
reads, it defaulted to another except and didn't show me the error.)
V

>
>
> --
> Rami Chowdhury
> "Never attribute to malice that which can be attributed to stupidity" --
> Hanlon's Razor
> 408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't Write File

2009-11-10 Thread Rami Chowdhury
On Tue, 10 Nov 2009 12:57:30 -0800, Victor Subervi  
 wrote:


On Tue, Nov 10, 2009 at 3:41 PM, Rami Chowdhury  
wrote:



On Tue, 10 Nov 2009 12:38:36 -0800, Victor Subervi <
victorsube...@gmail.com> wrote:

 Hi;

I've determined the problem in a script is I can't open a file to write
it:
script = open(getpic, "w")  # where getpic is already defined
Here are the permissions:
-rwxr-xr-x  1 root root  4649 Nov 10 12:31 start.py
What am I doing wrong?
TIA,
Victor



...and where's the file denoted by getpic?



getpic is incremented. For example, it can equal "getpic1.py".


My apologies -- I wasn't clear. Can you open the file denoted by getpic  
(e.g. "getpic1.py") for writing from the command line?


It would also be helpful if you let us know details of the exception being  
raised.



--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Calendar Stuff

2009-11-10 Thread Dave Angel

(Comments inline, and at end)

Victor Subervi wrote:

On Tue, Nov 10, 2009 at 2:02 PM, MRAB  wrote:

  

Victor Subervi wrote:



Hi;
I have the following code:

import calendar, datetime

def cal():
 ...
 myCal = calendar.Calendar(calendar.SUNDAY)
 today = datetime.date.today()
 day = today.day
 mo = today.month
 yr = today.year
#  month = myCal.monthdayscalendar(int(time.strftime("%Y"))
 month = myCal.monthdayscalendar(yr, mo)
 print 'hi'

html headers are included. No matter which one of the last two lines I
comment out, I never get to the point of printing 'hi'. (If I comment them
both out, it does print.) What do?

 Read the tracebacks?
  

The commented line will raise an exception because:

1. There's a final ')' missing.

2. You haven't imported 'time'.

3. .monthdayscalendar() requires the year and month.

I don't know why you're writing 'int(time.strftime("%Y"))' because you
already have the year in 'yr'.

The code above works for me if I comment out the line '...'.
--
 



It works fine for me in the python interpreter but not in the page from
which it's called! 
Then why didn't you say so, and in particular mention that this is a 
problem only when running on a webserver as a cgi program?  And give the

error message, and examine the server's log file, and ...


You say import time, but where do I call time in my
script? 
On the commented line with the call to  time.strftime(), that looks to 
me like a ref to the time module.  You said in your original message 
that it fails whichever of the last two lines is commented out...
well one reason it would fail is no import of time.



Here's the code (abbreviated just to print something out to see it
work), please advise if you can:

#!/usr/bin/python

import string
import sys,os
sys.path.append(os.getcwd())
import calendar, datetime, time
import MySQLdb
import string, re
from login import login

def calendarPrint():
  print "Content-Type: text/html"
  print
  print """
http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd";>
http://www.w3.org/1999/xhtml";>

.text { font-family: Arial, Helvetica, sans-serif; font-size: 16px;
text-decoration: none; text-align: justify }

NR Electric






  
You can't break apart theThe slash must appear directly 
before the 'script'

"""
  myCal = calendar.Calendar(calendar.SUNDAY)
  today = datetime.date.today()
  day = today.day
  mo = today.month
  yr = today.year
  month = myCal.monthdayscalendar(yr, mo)
  print month

calendarPrint()

  
I haven't tried to upload it to a server.  But running it locally, then 
taking the output and feeding it to Firefox, I see a few things wrong.  
It's declared asw HTML, but you don't have a  opening tag.  And 
you're missing closing tags for /body and /html   Tidy complains that 
the DOCTYPE url is malformed, but you couldn't prove it by me.


And month is a list of lists, so I don't know why you're printing it.

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


Re: New syntax for blocks

2009-11-10 Thread steve

Hi,

On 11/11/2009 12:53 AM, r wrote:

Forgive me if i don't properly explain the problem but i think the
following syntax would be quite beneficial to replace some redundant
"if's" in python code.

if something_that_returns_value() as value:
 #do something with value

# Which can replace the following syntactical construct...

value = something_that_returns_value()
if value:
 #do something with value

i dunno, just seems to make good sense. You save one line of code but
more importantly one indention level. However i have no idea how much
trouble the implementation would be?
I guess the problem would be that this would go against the (design ?) principle 
of not evaluating functions in the 'if' conditional part, because it would lead 
to statements such as:


if something(someother(sumsuch() + thisthing())) + ... == value:

also, assignment in the 'if' statement was consciously avoided, if I am not 
mistaken.


However, the same 'effect' can be obtained with the 'with' statement:

class something_that_returns_value:
 def __init__(self, x):
 # do something with x, self.value is what ought to be 'returned'
 self.value = x

 def __enter__(self):
 if self.value:
 return self.value
 else:
 return ValueError()

 def __exit__(self, type, value, traceback):
 return True


with something_that_returns_value(1) as value:
 print value

with something_that_returns_value(0) as value:
 print value

with something_that_returns_value(False) as value:
 value + 10
 # never reach here
 value.dosomething()

with something_that_returns_value([1,2,3]) as value:
 value.append(4)
 print value


nasty huh ? :)

cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't Write File

2009-11-10 Thread Rami Chowdhury
On Tue, 10 Nov 2009 12:38:36 -0800, Victor Subervi  
 wrote:



Hi;
I've determined the problem in a script is I can't open a file to write  
it:

script = open(getpic, "w")  # where getpic is already defined
Here are the permissions:
-rwxr-xr-x  1 root root  4649 Nov 10 12:31 start.py
What am I doing wrong?
TIA,
Victor


...and where's the file denoted by getpic?


--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: New syntax for blocks

2009-11-10 Thread steve

On 11/11/2009 02:05 AM, steve wrote:

Hi,

On 11/11/2009 12:53 AM, r wrote:

[...snip...]
 i dunno, just seems to make good sense. You save one line of code but
 more importantly one indention level. However i have no idea how much
 trouble the implementation would be?

I guess the problem would be that this would go against the (design ?) principle
of not evaluating functions in the 'if' conditional part, because it would lead


 gah !! sorry, what was I thinking ??
That is just not true !! Anyways, at least the assignments not being allowed bit 
is true.



cheers,
- steve

--
random non tech spiel: http://lonetwin.blogspot.com/
tech randomness: http://lonehacks.blogspot.com/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: New syntax for blocks

2009-11-10 Thread Bearophile
r:

> i think the following syntax would be quite beneficial
> to replace some redundant "if's" in python code.

http://python.org/dev/peps/pep-3003/

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


Re: how to create a pip package

2009-11-10 Thread Phlip
except...

will pip pull from a simple GitHub repo? or do I need to package
something up and put it in a pythonic repository somewhere?
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: New to Python need on advice on this script

2009-11-10 Thread Valentina Boycheva
Jim, 

 

In Python 2.5 under ArcMap 9.3 domains can be only listed. To get to the
domain values, they need to be converted to tables. Also, the default
value cannot be obtained from the existing GP API. Very annoying! The
workaround is to use VBA ArcObjects or connect to the database directly,
if possible, and extract the information from the GDB. This latter will
work for PGDB, not sure about FGDB.

 

Regards,

Valentina Boycheva



 

From: Jim Valenza [mailto:jim.vale...@gmail.com] 
Sent: Tuesday, November 10, 2009 2:33 PM
To: python-list@python.org
Subject: New to Python need on advice on this script

 

Hello all - I'm new to the world of Python as I am a GIS guy who would
like to broaden his horizons. I have a question about a script that
we've been working on: The purpose of the code is to Syncronize SDE
DropBox with Regulatory Project working files. 

 

I am looking for where the script dumps the domain list to a table and
loops through the table? Is It necessary? Seems like you should be able
to simply loop through the domain list. I was just trying to see if
there was a more straitforward way. Thanks

The script is as follows:

 

# Create the Geoprocessor
import sys, string, os, arcgisscripting, shutil, time
gp = arcgisscripting.create()

# Jim V testing
# Allow output to overwrite
gp.OverwriteOutput = 1

gp.AddToolbox("C://Program Files//ArcGIS//ArcToolbox//Toolboxes//Data
Management Tools.tbx")

#---create a logging file named "MMDD HH_MM_QualityControlLog.txt" 
theTime = time.strftime('%Y%m%d %H_%M')
#logfilename = "H:\\Development\\Python\\" + theTime +
"_PODsQAQCLog.txt"
logfilename =
"L:\\SharedData\\Denver\\Regulatory\\GIS\\Powder_River_Basin\\Pipeline\\
QAQC_Scripts\\" + theTime + "_PODsQAQCLog.txt"
log = open(logfilename,'w')
log.write(time.ctime() + "\n")
print time.ctime()

THE_WORKSPACE =
os.path.normpath("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin
") + "\\"  #REAL MODE LINE
#THE_WORKSPACE = os.path.normpath("H:/Development/testdata") + "\\"
#TEST MODE LINE
log.write("THE_WORKSPACE IS " + THE_WORKSPACE + "\n")
print "THE_WORKSPACE IS " + THE_WORKSPACE

P_CODE = "P_CODE"

#Create table of valid P_CODEs and convert to List
gp.DomainToTable_management(r"L:\SharedData\Denver\Regulatory\GIS\Powder
_River_Basin\GIS_Data\RMP_Current_Geodatabase\rmp_2_5.mdb", \
"regulatory_p_code",
r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin\Pipeline\QAQC_S
cripts\test.mdb\code_table", \
"pcode", "pdesc", "")
#searchRows =
gp.searchCursor(r"H:\Development\temp\test.mdb\code_table")
searchRows =
gp.searchCursor(r"L:\SharedData\Denver\Regulatory\GIS\Powder_River_Basin
\Pipeline\QAQC_Scripts\test.mdb\code_table")
searchRow = searchRows.next()
domainList = []
while searchRow:
domainList.append(searchRow.pcode)
searchRow = searchRows.next()
#print domainList

try:

#Get Workspaces from text file
#for line in open("H:/Development/testdata/PRB_POD_Paths.txt", 'r'):
#REAL MODE LINE
for line in
open("L:/SharedData/Denver/Regulatory/GIS/Powder_River_Basin/Pipeline/QA
QC_Scripts/PRB_POD_Paths.txt", 'r'):   #REAL MODE LINE
#for line in open("H:/Development/testdata/workspaces.txt", 'r'):
#TEST MODE LINE
if not line: break
line = line.strip()
if not line.startswith("#"): # skip lines that start with #
ws, P = line.split("RMP_2_5_",1) #parse line to get path and
P_CODE
log.write("  " + "\n")
log.write("  " + "\n")
log.write(P + "\n")
print "  "
print P
src = THE_WORKSPACE + line  #defines each workspace path

#If the Geodatabase exists, perform the operations
if os.path.exists(src):
#Archive Geodatabase before running script
log.write("The Geodatabase exists " + src + "\n")
print "The Geodatabase exists " + src
archiveFolder = THE_WORKSPACE + ws + "Archive" + "\\" +
"RMP_2_5_" + P
log.write("archiveFolder is " + archiveFolder + "\n")
print "archiveFolder is " + archiveFolder
shutil.copy(src, archiveFolder)#Archive the
Geodatabase

#Set workspace and variables
gp.workspace = src
log.write(gp.workspace + "\n")
print gp.workspace
P_Value = (P.strip(".mdb"))

#Valitate P_Code value against Domain list
if P_Value in domainList:
log.write("P_Code is valid:  " + P_Value + "\n")
print "P_Code is valid:  " + P_Value

# List all feature classes in feature datasets
fdss = gp.ListDatasets("","")
fds = fdss.Next()
while fds:
fcs = gp.ListFeatureClasses("*","",fds)
fc = fcs.Next()
   

Re: module imports and st_mtime

2009-11-10 Thread Aahz
In article ,
tow   wrote:
>
>Does anyone have any ideas what might be going on, or where further to
>look? I'm at a bit of a loss.

Try asking on pythonmac-...@python.org
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

[on old computer technologies and programmers]  "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As."  --Andrew Dalke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as network protocol

2009-11-10 Thread Daniel Fetchinson
>> My point is that hacking can still be a fun and easy-going activity
>> when one writes code for himself (almost) without regards to security
>> and nasty things like that creeping in from the outside. I'm the king
>> in my castle, although I'm fully aware of the fact that my castle
>> might be ugly from the outside :)
>
> Which is a relevant statement in the context of the OP seeking advice on
> *secure ways* of executing code in a restricted environment in exactly
> what way?

Okay, I reread the original message and you are right, the OP did want
restricted scope, so probably his environment is not completely risk
free.

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can't Write File

2009-11-10 Thread Dave Angel

Victor Subervi wrote:

Hi;
I've determined the problem in a script is I can't open a file to write it:
script = open(getpic, "w")  # where getpic is already defined
Here are the permissions:
-rwxr-xr-x  1 root root  4649 Nov 10 12:31 start.py
What am I doing wrong?
TIA,
Victor

  

Wrong?

1) you don't specify the environment, python version, OS, etc.
2) you don't show the error traceback
3) you don't indicate the value of   getpic at the time this statement 
executes

4) you don't indicate what the current working directory is, os.getcwd()
5) you don't indicate what directory the start.py is located in
6) you don't indicate which user is executing this script (only root can 
write to it)
7) you don't tell what the filename of the script is, specif. if it's 
called start.py
8) you don't say what happens if you do an open(getpic, "r"), or  
os.path.isfile(getpic)



By the time you answer each of those questions, you may notice the 
answer to your own question.


DaveA

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


Re: Python as network protocol

2009-11-10 Thread Ethan Furman

Daniel Fetchinson wrote:

I'm the king in my castle, although I'm fully aware of the fact that my castle
might be ugly from the outside :)


+1 QOTW
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python as network protocol

2009-11-10 Thread Ethan Furman

Steven D'Aprano wrote:
I can only repeat what I said to Daniel: can you guarantee that the nice 
safe, low-risk environment will never change? If not, then choose a more 
realistic threat model, and build the walls of your locked box 
accordingly.


Seems to me you can't really *guarentee* anything, especially something 
as elusive as the distant future.  Program for what your needs are, and 
document accordingly.


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


Python-URL! - weekly Python news and links (Nov 10)

2009-11-10 Thread Cameron Laird
QOTW:  "Don't get me wrong - innovation often comes from scratching
ones
personal itch. But you seem to be suffering from a rather bad case of
neurodermatitis." - Diez B. Roggisch, on ... well, personal style in
problem-solving
http://groups.google.com/group/comp.lang.python/msg/4cf102bdd3a3267b


[It's actually Gabriel Genellina who wrote these entries.]

Why aren't lists usable as dictionary keys? What do you mean,
"hashable"?
http://groups.google.com/group/comp.lang.python/t/929905a622d704b4/

`x == None` or `x is None` -- which one is the right way?
http://groups.google.com/group/comp.lang.python/t/1d9112d5bbe243d3/

At Microsoft, they performed empirical research about common
software engineering assumptions: "high test coverage is better",
"write test code first", "use assertions", and others:
http://groups.google.com/group/comp.lang.python/t/e06ac9acd1fc97fa/

The best way to populate a list of size N:
http://groups.google.com/group/comp.lang.python/t/fd07df5ffde3db83/

A new variant of an old problem: I got a single check from my
customer -
which ones among all pending invoices did he intend to pay?
http://groups.google.com/group/comp.lang.python/t/13f7645d99543e8/

How to test code that uses urllib without depending on external
resources?
http://groups.google.com/group/comp.lang.python/t/707f53122777e84a/

Singletons are hard to test too:
http://groups.google.com/group/comp.lang.python/t/dbe458917dd9b393/

How to use Filters in the logging module:
http://groups.google.com/group/comp.lang.python/t/6a002ee599fd94ba/

Delete items from a list that match a certain pattern:
http://groups.google.com/group/comp.lang.python/t/f6d0a08ad2642ddf/

What is the correct way to port codecs.open to python 3.1?
http://groups.google.com/group/comp.lang.python/t/b93ad93148bdc26d/

py2exe, cx_freeze, py2app: a comparison
http://groups.google.com/group/comp.lang.python/t/5abb44388a28ce25/

How to cancel a thread from another one:
http://groups.google.com/group/comp.lang.python/t/af903ef349b1bddf/

Why does "help(import)" not work?
http://groups.google.com/group/comp.lang.python/t/d8821fe86b3eda9a/



Everything Python-related you want is probably one or two clicks away
in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
  http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python
enthusiasts":
  http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
  http://pythonmagazine.com

Readers have recommended the "Planet" site:
  http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions.
http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.com
p.python.devel&sort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
  http://code.activestate.com/recipes/langs/python/

Many Python conferences around the world are in preparation.
Watch this space for links

Re: New syntax for blocks

2009-11-10 Thread r
On Nov 10, 2:08 pm, Robert Latest  wrote:
(..snip..)
> Also it's not the "if" that is (if at all) redundant here but the assignment.

Not exactly. The assignment happens only once just as the boolean
check of "if " happens once. The redundancy is in validating
the existence of a truthful value contained in a variable after
assignment of a value to that same variable. It's like putting on your
tennis shoes and then asking yourself 'am i wearing tennis shoes?'. Of
course we all know *why* we must verify the existence of value
afterward and the shoe analogy doesn't translate 1:1 to programming.
It's more like...

shoes = grab_a_pair_of_shoes_or_none_and_apply_to_feet()
if shoes:
shoes.this()
shoes.that()

Now did we find a pair of shoes or did we fail because the lights were
out and all we accomplished was to toil around in the closet for half
an hour bumping our head before finally giving up and returning empty
handed?

Just thinking out loud here...what if variable assignments could
return a value... hmmm? Not to them selfs of course but to a caller,
like an if statement...

if a=openfile:
  # do something with a

(if(a.__eq__(openfile)))

Python would need to stuff the value of openfile into "a", then add
the variable "a" to the proper namespace, then evaluate if "a" is
True. This would read more naturally than even my first postulation. I
bet it would confuse the crap out of noobies though!

So basically with the new syntax what your saying is this:
if the value of this expression bools to False, toss it away because i
don't need it, else assign the value to a local variable and run the
block. Basically your encaspulating an if..else block in one line of
code.


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


Re: can i configure IDLE to use python 3.2 on fedora?

2009-11-10 Thread Aahz
In article ,
Robert P. J. Day  wrote:
>
>  on fedora 11 system, there is no python 3 package so i downloaded
>and manually installed (svn checkout) python pre-3.2 in
>/usr/local/bin.  works fine, but if i install the python-tools
>package, "idle" that comes with it is hard-coded(?) to still refer to
>the officially-installed python-2.6.  i see no way to configure idle
>to use the "python3" executable instead.

Just find your python3 IDLE, I think it's in Tools/
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

[on old computer technologies and programmers]  "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As."  --Andrew Dalke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing GUI Module for Python

2009-11-10 Thread Simon Hibbs
On 10 Nov, 10:40, Lorenzo Gatti  wrote:

> I also would like to use PySide, but unlike PyQt and Qt itself it
> doesn't seem likely to support Windows in the foreseeable future. A
> pity, to put it mildly.

It's not been ruled out. They don't officialy support the Mac either,
but according to posts on the mailing list a independent developer has
got it working in MacOS X at some level. Since QT runs on Windows,
porting to the Windows version of QT shouldn't be hard.

PySide is for the future, not the present, but it gives me a lot more
confidence in using and recomending PyQT to know that there is so much
work being put in to make sure it has a great future.

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


Re: DHT for Python 3.x?

2009-11-10 Thread Martin v. Löwis
Salim Fadhley wrote:
> There are plenty of good DHT projects for Python 2.x, however from
> what I can tell none of them have made the jump to 3.x yet.
> 
> I'm really keen to support Python 3.x for a project I'm working on. I
> know that many developers (correctly) consider switching to Python 3
> foolish since it is less supported at the moment, but nevertheless I
> am keen to carry on.
> 
> So can somebody recommend me a working implementation of a DHT which
> will work on Python 3.x and preferably Python 2.6 as well.

I can't. But I recommend to port the library that you like most to 3.x,
and provide any necessary changes to the author.

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


Re: Python C api: create a new object class

2009-11-10 Thread Martin v. Löwis
> How can I create an instance class in Python, currently I do:
> 
> class empty:
>  pass
> 
> Then anytime I want that class (which I treat like a dictionary):
> 
> o = empty()
> o.myattr = 1
> etc
> 
> Is there is a one line syntax to instantiate an instance?
> 
> Any other ways than this:
> o = new.classobj('object', (), {})

Most certainly:

o = empty(1) # or: o = empty(1, etc)

This requires you to define

class empty:
  def __init__(self, myattr, etc):
self.myattr = myattr
etc

> 2)
> 
> How can I, similarly, create an object "o" in C api:
> 
> PyObject *o = what_to_call()

o = PyObject_CallFunction(pointer_to_class_object, "")

> 3)
> 
> Given a PyObject* is there is a way to tell if one can call
> PyObject_SetAttrString() on that object w/o getting an error?
> 
> For example, before calling a PyObject* one can see if it is callable,
> but can I test if an object supports setattr?
> 
> (from C api)

You could check whether the object supports setattr at all, but that
would be pretty useless, since most objects do.

What you want to test (would it support setting "myattr" to the specific
value, at this point) is impossible to test: the object may give you
an exception on every third call only (or only if the value is not
an integer, etc). So just call SetAttr, and clear any exception you
get that you don't want to get.

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


Re: Python C api: create a new object class

2009-11-10 Thread Benjamin Peterson
lallous  lgwm.org> writes:
> Is there is a one line syntax to instantiate an instance?

You can't instantiate an instance; it's already instantiated.

> 
> Any other ways than this:
> o = new.classobj('object', (), {})

class x: pass

> How can I, similarly, create an object "o" in C api:

Use PyObject_CallFunction(PyType_Type, [arguments])


> Given a PyObject* is there is a way to tell if one can call 
> PyObject_SetAttrString() on that object w/o getting an error?

No.




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


Re: Threaded import hang in cPickle.dumps

2009-11-10 Thread Benjamin Peterson
Zac Burns  gmail.com> writes:
> What can I do about this?

Not run it in a thread.



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


Re: on "Namespaces"

2009-11-10 Thread Ben Finney
Steven D'Aprano  writes:

> Modules are namespaces. So are packages.
>
> Classes and class instances are namespaces.
>
> Even function scopes are namespaces.

Steven implies it with his wording, but to make it explicit:

When you have a module, package, class, or instance-of-a-class object,
those objects are themselves namespaces. That is, the name used to refer
to the object can be a component in a namespace reference::

import foo_package
import bar_module

class Parrot(object):
widget = object()

parrot = Parrot()

# Use a package as a namespace.
foo_package.spam_module.frobnicate()

# Use a module as a namespace.
bar_module.spangulate()

# Use a class as a namespace.
print Parrot.widget

# Use an arbitrary instance as a namespace.
parrot.state = "Restin'"

When you have a function object, the “function scope” is not available
in this way: you can't access the “inside” of the function from the
outside via the function object. (The function object, like any other
object, has a namespace, but that's not the *function scope* namespace.)

> When you write:
>
>
> n = None
>
> def spam(n):
> print "spam" * n
>
> def ham(n):
> print "ham" * n
>
> the n inside spam() and ham() and the global n are in different 
> namespaces, and so independent.

Right. And neither of them is available from outside those functions
(since the reference only exists while the function is executing).

-- 
 \ “Roll dice!” “Why?” “Shut up! I don't need your fucking |
  `\ *input*, I need you to roll dice!” —Luke Crane, demonstrating |
_o__)   his refined approach to play testing, 2009 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: My own accounting python euler problem

2009-11-10 Thread John Machin
On Nov 8, 8:39 am, vsoler  wrote:
> In the accounting department I am working for we are from time to time
> confronted to the following problem:
[snip]

> My second question is:
> 2. this time there are also credit notes outstanding, that is,
> invoices with negative amounts. For example,  I=[500, 400, -100, 450,
> 200, 600, -200, 700] and a check Ch=600

How can a credit note be "outstanding"? The accounting department
issues a credit note without recording what invoice it relates to?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI vs mod_python

2009-11-10 Thread John Nagle

sstein...@gmail.com wrote:


On Nov 9, 2009, at 10:18 AM, Victor Subervi wrote:

Yes, obviously. But if CGI is enabled, it should work anyway, should 
it not?


Depends on what "CGI is enabled" means.

Usually, web servers are not set to just handle cgi scripts from 
anywhere, but only from specific file system locations.  Otherwise, an 
an anonymous upload could be executed as CGI and wreak havoc.


If it won't work as a CGI program, which is relatively straightforward,
it probably won't work at all.

First, write some trivial CGI program in Python and make sure the
environment works - Python loads, the Python program loads, and you
can get a response back.

Bear in mind that most hosting services don't make much of an attempt
to support Python. Expect important libraries to be missing or obsolete.

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


Re: how to create a pip package

2009-11-10 Thread Wolodja Wentland
On Tue, Nov 10, 2009 at 13:09 -0800, Phlip wrote:
> will pip pull from a simple GitHub repo? or do I need to package
> something up and put it in a pythonic repository somewhere?

I don't quite understand, but would say: both ;-)

You can't tell pip to pull from arbitrary git repositories, but only
from those that contain the packaging code as outlined in the distutils
documentation.

These git repositories do *not* have to be hosted on pypi. You should
however be able to do the following:

$ git clone git://example.com/repo.git
$ cd repo
$ python setup.py install

The pip requirement file would contain the following line:

-e git+git://example.com/repo.git#egg=rep

I hope this answers your questions :-D

--
  .''`. Wolodja Wentland 
 : :'  :
 `. `'` 4096R/CAF14EFC 
   `-   081C B7CD FF04 2BA9 94EA  36B2 8B7F 7D30 CAF1 4EFC


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is None or == None ?

2009-11-10 Thread Rhodri James
On Tue, 10 Nov 2009 18:55:25 -, Steven D'Aprano  
 wrote:



On Tue, 10 Nov 2009 15:46:10 +, Grant Edwards wrote:


On 2009-11-10, Rhodri James  wrote:

On Sun, 08 Nov 2009 19:45:31 -, Terry Reedy 
wrote:


I believe the use of tagged pointers has been considered and so far
rejected by the CPython developers. And no one else that I know of has
developed a fork for that. It would seem more feasible with 64 bit
pointers where there seem to be spare bits. But CPython will have to
support 32 bit machines for several years.


I've seen that mistake made twice (IBM 370 architecture (probably 360
too, I'm too young to have used it) and ARM2/ARM3).  I'd rather not see
it a third time, thank you.


MacOS applications made the same mistake on the 68K.  They reserved the
high-end bits in a 32-bit pointer and used them to contain
meta-information.



Obviously that was their mistake. They should have used the low-end bits
for the metadata, instead of the more valuable high-end.


Oh, ARM used the low bits too.  After all, instructions were 4-byte  
aligned, so the PC had all those bits going spare...


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


Re: futures - a new package for asynchronous execution

2009-11-10 Thread Aahz
In article ,
Brian Quinlan   wrote:
>
>I recently implemented a package that I'd like to have include in the  
>Python 3.x standard library (and maybe Python 2.x) and I'd love to  
>have the feedback of this list.

Any recently implemented library has an extremely high bar before it gets
adopted into the standard library.  You should concentrate on persuading
people to use your library; for example, you should make regular feature
and bugfix releases and announce them on c.l.py.announce.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

[on old computer technologies and programmers]  "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As."  --Andrew Dalke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonw.exe under Windows-7 (Won't run for one admin user)

2009-11-10 Thread Rhodri James

On Tue, 10 Nov 2009 15:39:46 -, SD_V897  wrote:


Rhodri James wrote:
On Fri, 06 Nov 2009 21:19:44 -, SD_V897   
wrote:



Rhodri James wrote:
On Tue, 03 Nov 2009 16:00:16 -, SD_V897   
wrote:


I have a perplexing issue, I have four users set up on a W7  
computer. The program runs fine for all users except the admin user  
who needs it for school assignments.
 A little more information, please.  How does it not work for the  
admin

user?  Is there a traceback?  What do you get if you try to invoke it
from a command line?




Hi Rhodri, here's a dump file, don't know if this helps or not..
 So Windows is reporting a crash, then.  I'll repeat my last question  
in particular; what happens when your admin user runs the program  
you're trying to invoke from the command line?




Hi Rhodri, Python Command-Line works fine.


I'm sure it does.  That's not what I asked you.

Are toy recommending to invoke IDLE from there or from windows command  
line?


No, I'm asking you -- or rather your admin user -- to invoke the program  
that is giving you grief from the command line, i.e. "python myscript.py",  
and tell me what happens.  "It doesn't work" won't be considered at all  
helpful; without details we might as well just print out your script,  
throw darts at it, and tell you the problem is where the darts land.


The rest of your answer however suggests that I've fundamentally  
misunderstood what you've said.  Please tell me *exactly* what happens  
when it doesn't "run fine" for your admin user.


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


Re: Is it possible to get the Physical memory address of a variable in python?

2009-11-10 Thread Carl Banks
On Nov 10, 3:32 am, Ognjen Bezanov  wrote:
> Hey,
>
> Thanks for all the responses guys. In hindsight I probably should have
> explained why on earth I'd need the physical address from an interpreted
> language.
>
> I'm trying to see if there is any way I can make Python share data
> between two hosts using DMA transfers over a firewire connection, so
> avoiding the need for another layer on top such as IPv4 + Python sockets.
>
> Thanks to some old python bindings which I updated to python 2.6, I can
> read any write to the RAM of any firewire connected host within python.
> Because it uses DMA (the cpu is not involved in this at all), I can only
> specify a physical address within the 4GB ram limit to read from and
> write to.

[snip]

>  From what I've been told so far, it's not possible to do this without
> some OS-specific (Linux in this case) syscall. Is this correct?


What you'd normally need to do it to use system calls to allocate a
DMA-able memory buffer, then copy contents of your Python object
(which you get at using buffer protocol) to this buffer, then initiate
the DMA transfer.  At this point it probably would be easier to just
write a C-extension to do that, but I see no reason it can't be done
with ctypes.

However, I'm not sure how that would interact with your pre-existing
module.  I'd expect a module that does DMA to take care of physical
address mapping itself, you just pass it a logical address, or an
object that supports buffer protocol, and it does the rest.

It seems just getting a physical address and starting a DMA transfer
from it is prone to danger if memory pages are discontiguous (and they
often are), but maybe OSes these days can handle that automatically.


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


Re: Python as network protocol

2009-11-10 Thread geremy condra
On Tue, Nov 10, 2009 at 2:08 PM, Steven D'Aprano
 wrote:
> On Tue, 10 Nov 2009 12:28:49 -0500, geremy condra wrote:
>
>> Steven, remember a few weeks ago when you tried to explain to me that
>> the person who was storing windows administrative passwords using a 40
>> byte xor cipher with the hardcoded password might not be doing something
>> stupid because I didn't know what their threat model was? Yeah- what you
>> just said is what I was trying to explain then.
>
> No, I'm sure that wasn't me... perhaps some other Steven D'Aprano... from
> the Evil Dimension...
>
> *wink*

I think I saw a mustache on him. Probably evil.

> Seriously, I'm not sure if I knew that the person was storing Windows
> admin passwords at the time. If I had, I probably would have agreed with
> you. But using a 40 byte xor cipher to obfuscate some strings in a game
> is perfectly valid -- not every locked box needs to be a safe with 18
> inch tempered steel walls.

Granted, and I am going to be able to give a very nice talk on how not
to do cryptography partially as a result of that particularly egregious bit of
silliness, so I guess I can't complain too much.

> I can only repeat what I said to Daniel: can you guarantee that the nice
> safe, low-risk environment will never change? If not, then choose a more
> realistic threat model, and build the walls of your locked box
> accordingly.

Or, plan on becoming part of one of my presentations in a few years.
Either way works for me.

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


Re: is None or == None ?

2009-11-10 Thread Vincent Manis
On 2009-11-10, at 07:46, Grant Edwards wrote:
> MacOS applications made the same mistake on the 68K.  They
> reserved the high-end bits 
At the time the 32-bit Macs were about to come on the market, I saw an internal 
confidential document that estimated that at least over 80% of the applications 
that the investigators had looked at (including many from that company named 
after a fruit, whose head office is on Infinite Loop) were not 32-bit clean. 
This in spite of the original edition of Inside Mac (the one that looked like a 
telephone book) that specifically said always to write 32-bit clean apps, as 
32-bit machines were expected in the near future. 

It's not quite as bad as the program I once looked at that was released in 1999 
and was not Y2K compliant, but it's pretty close. 

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


Re: My own accounting python euler problem

2009-11-10 Thread Steven D'Aprano
On Tue, 10 Nov 2009 14:46:49 -0800, John Machin wrote:

> The problems that you mention are only a SUBSET of the total problem.
> Example: oustanding invoices are for 300, 200, and 100 and the cheque is
> for 450 -- in general the total of the cheque amounts does not equal the
> total of any possible selection of outstanding invoice amounts.
> 
> I would be very surprised if a real accounting department did not
> already have a set of business rules for dealing with a problem that has
> existed since invoices and cheques were invented.

As a sometimes accounts department,  let me put my hand up for that.

Yes. Generally the rule is, "call the damn customer and ask them what 
they're smoking", only more politely.

Usually they'll have some convoluted breakdown of what amount they are 
paying off each invoice. Sometimes they will have taken off a settlement 
discount for prompt payment (often whether or not they actually paid 
promptly). Sometimes they overpay, or underpay, or apply credits to the 
wrong invoice, or pay invoices twice, or pay the wrong amount, or just 
make up a number from thin air. Sometimes they themselves will have no 
idea what the amount represents. And, I can guarantee, they will *ALWAYS* 
use a different rounding scheme to whatever accounting software you use, 
so there's always odd one or two cents that need to be manually adjusted 
somewhere.



> I would be extremely surprised if a real accounting department could be
> persuaded to imagine a subset of their unpaid/underpaid/overpaid invoice
> problem as being an instance of the (extended) knapsack problem :-)

That's because the average accounting department is mathematically 
illiterate :)

Nevertheless, many accounting software packages, like Quickbooks, will 
take a wild stab at allocating payments for you, usually using some 
variation of "if you can't find an exact match for a single invoice, just 
blindly allocate it to the oldest invoices you can". Frankly, I'd much 
prefer a knapsack solution.




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


Re: Choosing GUI Module for Python

2009-11-10 Thread Antony
On Nov 11, 3:08 am, Simon Hibbs  wrote:
> On 10 Nov, 10:40, Lorenzo Gatti  wrote:
>
> > I also would like to use PySide, but unlike PyQt and Qt itself it
> > doesn't seem likely to support Windows in the foreseeable future. A
> > pity, to put it mildly.
>
> It's not been ruled out. They don't officialy support the Mac either,
> but according to posts on the mailing list a independent developer has
> got it working in MacOS X at some level. Since QT runs on Windows,
> porting to the Windows version of QT shouldn't be hard.
>
> PySide is for the future, not the present, but it gives me a lot more
> confidence in using and recomending PyQT to know that there is so much
> work being put in to make sure it has a great future.
>
> Simon Hibbs

Thanks All
  I have got an idea,the way i need to choose GUI module in Python ,
As "r" said i am going to start from tkinter without any IDE .
if i need any advanced feature then i will move on to some other
module
First i have to try the code ...

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


LinkedIn Messages, 11/10/2009

2009-11-10 Thread LinkedIn Communication
LinkedIn





 REMINDERS: 
Invitation Reminders: 
 * View Invitation from Frank Pan 
http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I379833192_3/0PnP8VcjcPe3ATcQALqnpPbOYWrSlI/svi/
 





PENDING MESSAGES:

There are a total of 4 messages awaiting your response. Visit your InBox now: 
http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/inb/


--

Don't want to receive email notifications? Adjust your message settings:
https://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/prv/

LinkedIn values your privacy. At no time has LinkedIn made your email address 
available to any other LinkedIn user without your permission. (c) 2009, 
LinkedIn Corporation.

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


Re: is None or == None ?

2009-11-10 Thread Steven D'Aprano
On Tue, 10 Nov 2009 16:05:01 -0800, Vincent Manis wrote:

> At the time the 32-bit Macs were about to come on the market, I saw an
> internal confidential document that estimated that at least over 80% of
> the applications that the investigators had looked at (including many
> from that company named after a fruit, whose head office is on Infinite
> Loop) were not 32-bit clean. This in spite of the original edition of
> Inside Mac (the one that looked like a telephone book) that specifically
> said always to write 32-bit clean apps, as 32-bit machines were expected
> in the near future.

That is incorrect. The original Inside Mac Volume 1 (published in 1985) 
didn't look anything like a phone book. The original Macintosh's CPU (the 
Motorola 68000) already used 32-bit addressing, but the high eight pins 
were ignored since the CPU physically lacked the pins corresponding to 
those bits.

In fact, in Inside Mac Vol II, Apple explicitly gives the format of 
pointers: the low-order three bytes are the address, the high-order byte 
is used for flags: bit 7 was the lock bit, bit 6 the purge bit and bit 5 
the resource bit. The other five bits were unused.

By all means criticize Apple for failing to foresee 32-bit apps, but 
criticizing them for hypocrisy (in this matter) is unfair. By the time 
they recognized the need for 32-bit clean applications, they were stuck 
with a lot of legacy code that were not clean. Including code burned into 
ROMs.




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


  1   2   >