Re: How to get outer class name from an inner class?

2012-05-08 Thread alex23
On May 9, 6:05 am, John Gordon  wrote:
> I'd like to group the classes underneath a parent class, like so:
>
> class Question(ApplicationException):
>
>     class TooShort(ApplicationException):
>         pass
>
>     class TooLong(ApplicationException):
>         pass
>
> This will make it easier in the future for organizing lots of sub-errors.
>
> My problem is this: the get_message() method in the base class only knows
> the current class name, i.e. "TooShort" or "TooLong".  But that's not
> enough; I also need to know the outer class name, i.e. "Question.TooShort"
> or "Question.TooLong".  How do I get the outer class name?

This might do the trick:

  import inspect

  def exception_members(scope):
  classes = (m[1] for m in inspect.getmembers(scope,
inspect.isclass))
  return set(
  c for c in classes if Exception in c.__mro__
  )

  class ApplicationException(Exception):
  @property
  def outer_scope(self):
  for _class in
exception_members(inspect.getmodule(self.__class__)):
  if self.__class__ in exception_members(_class):
  return _class

  def get_message(self):
  scope = self.outer_scope
  class_name = scope.__name__ + '.' if scope else ''
  class_name += self.__class__.__name__
  return class_name

When get_message is run, it looks in the module where the exception
was defined for any new classes derived from Exception, then looks at
the members of each of those to see if it matches the current object's
class.

Not really well tested, so beware :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Last CFP- CyberSecurity - Malaysia - IEEE

2012-05-08 Thread sdiwc conferences
The International Conference on Cyber Security, Cyber Warfare and
Digital Forensic (CyberSec2012)
University Putra Malaysia, Kuala Lumpur, Malaysia
   June 26-28, 2012
   http://www.sdiwc.net/CyberSec2012/

The CyberSec2012 is technically co-sponsored by IEEE Malaysia Chapter
and All papers will be submitted to IEEE for potential inclusion to
IEEE Xplore and Ei Compendex.



The proposed conference on the above theme will be held at University
Putra Malaysia, Kuala Lumpur, Malaysia, From June 26-28, 2012 which
aims to enable researchers to build connections between different
digital applications.

The conference welcomes papers on the following (but not limited to)
research topics:

*Cyber Security
-Privacy issues
-Formal Methods Application in Security
-Incident Handling and Penetration Testing
-Operating Systems and Database Security
-Security in Cloud Computing
-Security in Social Networks
-Multimedia and Document Security
-Hardware-Based security
-VOIP, Wireless and Telecommunications Network Security
-Security of Web-based Applications and Services
-Enterprise Systems Security
-SCADA and Embedded systems security
-Distributed and Pervasive Systems Security
-Secure Software Development, Architecture and Outsourcing
-Security for Future Networks
-Security protocols
-Legal Issues

*Digital Forensic
-Data leakage, Data protection and Database forensics
-Forensics of Virtual and Cloud Environments
-Network Forensics and Traffic Analysis Hardware Vulnerabilities and
Device Forensics
-Information Hiding
-File System and Memory Analysis Multimedia Forensic
-Executable Content and Content Filtering
-Anti-Forensics and Anti-Anti-Forensics Techniques
-Malware forensics and Anti-Malware techniques
-Evidentiary Aspects of Digital Forensics
-Investigation of Insider Attacks
-Cyber-Crimes
-Large-Scale Investigations
-New threats and Non-Traditional approaches

*Information Assurance and Security Management
-Corporate Governance
-Laws and Regulations
-Threats, Vulnerabilities, and Risk Management
-Business Continuity & Disaster Recovery Planning
-Critical Infrastructure Protection
-Digital Rights Management and Intellectual Property Protection
-Security Policies and Trust Management
-Identity Management
-Decidability and Complexity
-Economics of Security
-Fraud Management

*Cyber warfare and Physical Security
-Surveillance Systems
-Cyber Warfare Trends and Approaches
-Social engineering
-Authentication and Access Control Systems
-Biometrics Applications
-Electronic Passports, National ID and Smart Card Security
-Template Protection and Liveliness detection
-Biometrics standards and standardization
-New theories and algorithms in biometrics

Researchers are encouraged to submit their work electronically. All
papers will be fully refereed by a minimum of two specialized
referees. Before final acceptance, all referees comments must be
considered.

Important Dates
==

Submission Date   : May 12, 2012
Notification of acceptance: May 22, 2012
Camera Ready submission   : May 25, 2012
Registration  : May 30, 2012
Conference dates  : June 26-28, 2012
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-08 Thread Terry Reedy

On 5/8/2012 5:47 PM, Terry Reedy wrote:


 From what others have posted, it has a new code repository (that being
the ostensible reason for the fork), project site, and mailing list --
the latter two incompetently. Apparently, the only thing he has kept are
the domain and project names (the latter for sure not legitimately).


Update: the pyjs.org group (or member thereof) has registered pyjs as a 
new project name on pypi and released pyjames0.8.1 as pyjs0.8.1. So they 
seem not to be claiming the name 'pyjames', at least not on pypi.


--
Terry Jan Reedy

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


Re: How to get outer class name from an inner class?

2012-05-08 Thread Steve Howell
On May 8, 1:05 pm, John Gordon  wrote:
> I'm trying to come up with a scheme for organizing exceptions in
> my application.
>
> Currently, I'm using a base class which knows how to look up the text
> of a specific error in a database table, keyed on the error class name.
>
> The base class looks like this:
>
> class ApplicationException(Exception):
>     """Base class for application-specific errors."""
>
>     def get_message(self):
>         """Return the error message associated with this class name."""
>
>         class_name = self.__class__.__name__
>         return UserMessage.objects.get(key=class_name).text
>
> And then I define a bunch of subclasses which all have different names:
>
> class QuestionTooShortError(NetIDAppsError):
>     """User entered a security question which is too short."""
>     pass
>
> class QuestionTooLongError(NetIDAppsError):
>     """User entered a security question which is too long."""
>     pass
>
> This scheme works, but I'd like to make it more streamlined.  Specifically,
> I'd like to group the classes underneath a parent class, like so:
>
> class Question(ApplicationException):
>
>     class TooShort(ApplicationException):
>         pass
>
>     class TooLong(ApplicationException):
>         pass
>
> This will make it easier in the future for organizing lots of sub-errors.
>
> My problem is this: the get_message() method in the base class only knows
> the current class name, i.e. "TooShort" or "TooLong".  But that's not
> enough; I also need to know the outer class name, i.e. "Question.TooShort"
> or "Question.TooLong".  How do I get the outer class name?

This may be somewhat relevant to you, although it doesn't specifically
answer your question for pre-3.3:

http://www.python.org/dev/peps/pep-3155/ (Qualified name for classes
and functions)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I run a python program from an internet address?

2012-05-08 Thread alex23
On May 8, 9:20 am, Albert  wrote:
> I have a small text based python program that I want to make available
> to people who might be behind a firewall or can't install python on
> their office computers, but can access the internet.  It is just an
> algorithm that makes a handful of straightforward calculations on some
> input that the user provides and spits out some text as output that
> they might want to print out on a printer.  I can program python on my
> local machine, but don't know how to make the code accessible from a
> browser.

You could do this quite easily with CherryPy:


import cherrypy

class WebApp(object):
def calc(self, a, b):
c = int(a) + int(b)
return str(c)
calc.exposed = True

cherrypy.quickstart(WebApp())

This can be called via '/calc/1/2' or 'calc?a=1&b=2'. You can add a
method to provide a form and another to produce a pretty output and
it's good to go.

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


Re: Using modules from Debian "python3-..." packages with locally compiled Python 3.3

2012-05-08 Thread Edward C. Jones

Terry Reedy said:

> Question 1: if you use the .pth method, do you get the same result? 
(I expect you will, but good to

> check.)

Recompiled Pyhton 3.3 without the SITEPATH change.  Same result:

> python3.3
Python 3.3.0a3 (default, May  8 2012, 19:57:45)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1015, in _find_and_load
  File "", line 634, in load_module
  File "", line 294, in 
module_for_loader_wrapper

  File "", line 522, in _load_module
  File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in 


from . import add_newdocs
ImportError: cannot import name add_newdocs
>>>

> Question2: has anyone successfully run numpy with 3.3 on Debian or 
anything else? If no one here

> answers, try Debian or numpy lists.

I don't know.  But Python 3.3.0a3 has been in Debian experimental for 
only a few days.


I have a bunch of code that I want to port to Python 3.  I delayed for 
years because numpy and PIL
had not been ported to Python 3.  Numpy has now been converted and there 
are alternatives to PIL.
Since I want to deal with unicode only once, I would prefer to use 3.3 
but 3.2 would be OK.


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


Re: indexed property? Can it be done?

2012-05-08 Thread Charles Hixson

On 05/08/2012 01:19 PM, Adam Tauno Williams wrote:

On Mon, 2012-05-07 at 20:15 -0700, Charles Hixson wrote:
   

class Node:
  def__init__(self, nodeId, key, value, downRight, downLeft, parent):
  dirty=True
  dlu=utcnow()
  self.node=[nodeId, downLeft, [key], [value],
[downRight], parent, dirty, dlu]
Note that node[3] is a list of keys (initially 1) and node[3] is a list
of values, etc.
What I'd like to do is to be able to address them thusly:
k = node.key[2]
v = node.value[2]
but if there's a way to do this, I haven't been able to figure it out.
Any suggestions?
 

Do not do this;  this is bad code in any language.
   


I'm sorry, but why do you say that?  In D or Eiffel it is a standard 
approach, with compiler support.  I will admit that one shouldn't do it 
in C++, or, it appears, in Python.  This is far from justifying saying 
one should never do it.


--
Charles Hixson

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


Re: which book?

2012-05-08 Thread Mark Lawrence

On 08/05/2012 19:16, d.po...@gmail.com wrote:

folks
hi,
I am going to learn python for some plot issues. which book or sources, do you 
recommend please?
Cheers,
Dave


matplotlib - google and yee shall find.

--
Cheers.

Mark Lawrence.

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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-08 Thread Mark Lawrence

On 08/05/2012 22:47, Terry Reedy wrote:

On 5/8/2012 12:42 PM, Chris Angelico wrote:

On Wed, May 9, 2012 at 2:12 AM, Terry Reedy wrote:



You still have it backwards. Risinger forked the project with a new code
host and mailing list, but stole the name and and some data in the
process
and made the false claim that his fork was the original. It is not
clear if
he damaged anything in the process.


Yes, but now that it's happened, the most obvious way forward is to
fork the hijacked project back to the original, given that the
hijacked one is being posted as the original.


Risinger's fork is NOT the original, no matter what his claim. People
should not give credit to his false claim or regard it as an
accomplished fact.

 From what others have posted, it has a new code repository (that being
the ostensible reason for the fork), project site, and mailing list --
the latter two incompetently. Apparently, the only thing he has kept are
the domain and project names (the latter for sure not legitimately).

Luke has not abandoned pyjamas and has not, as of now, ceded ownership
of the name to anyone. I am pretty sure Luke he has no plans to adandon
his current codebase and and re-fork off of the Risinger et al revised
codebase.


If Luke continues his original project, it would still be the true
pyjamas
project, not a fork.


Yeah, but if he doesn't have command of the domain any more, then
he'll likely be spawning it under a new name somewhere.


Yes, but so what? The domain name is not the project. Open source
projects change domain names all the time (though hopefully rarely for
any particular project).



{Not replying To Terry Reedy or anybody else specifically, but didn't 
know where to jump in]


Who cares, in the sense that zero people (apart from five(ish) morons) 
will follow the hijacked project, while the vast majority will support
Luke as a matter of principal. I suggest the thieves be subjected to 
this http://en.wikipedia.org/wiki/Send_to_Coventry


--
Cheers.

Mark Lawrence.

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


Re: Using modules from Debian "python3-..." packages with locally compiled Python 3.3

2012-05-08 Thread Terry Reedy

On 5/8/2012 3:13 PM, Edward C. Jones wrote:

I use up-to-date Debian testing (wheezy), amd64 architecture. I downloaded,
compiled and installed Python 3.3.0 alpha 3 (from python.org) using
"altinstall". Debian wheezy comes with python3.2 (and 2.6 and 2.7). I
installed the Debian package "python3-bs4" (BeautifulSoup4 for Python3).


Your problem with bs4 seems to be that it got installed in a way that 
3.2 could find it and 3.3 could not.



1. Put bs4.pth in /usr/local/lib/python3.3/site-packages. This file should
contain the line:
/usr/lib/python3/dist-packages
This works.


As it should, being the standard alternative to putting the module in 
site-packages.



2. At the start of each Python program using bs4:
import sys
sys.path.append('/usr/lib/python3/dist-packages')
import bs4
This works.


Another standard methods.


3. In the Python 3.3 source code, do ".configure" then edit
Modules/Setup to
contain
SITEPATH=:/usr/lib/python3/dist-packages
Finish compiling and altinstalling python. "import bs4" works.


An option only for those who compile. The two above work on windows for 
those who do not.



The last is the best because I only have to do it once.


The .pth entry is also once only.

> Next I tried numpy.  It is installed from Debian package "python3-numpy".

I bet the Debian packager has not tested the python packages with 3.3ax 
yet. On Windows, compiled packages don't work with new Python versions. 
On *nix, things are better but not necessarily perfect.


> If I compile and install Python 3.3 _with_ the

change in (3) above, I get:

 > python3.3
Python 3.3.0a3 (default, May 8 2012, 14:43:28)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import numpy
Traceback (most recent call last):
File "", line 1, in 
File "", line 1015, in _find_and_load
File "", line 634, in load_module
File "", line 294, in
module_for_loader_wrapper
File "", line 522, in _load_module
File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in

from . import add_newdocs
ImportError: cannot import name add_newdocs


In this case, the problem in Python rather than C code.


"add_newdocs.py" is present in the numpy directory.
The "import numpy" works for the Debian python 3.2.
What is the problem?


Question 1: if you use the .pth method, do you get the same result? (I 
expect you will, but good to check.)


Question 2: has anyone successfully run numpy with 3.3 on Debian or 
anything else? If no one here answers, try Debian or numpy lists.


Comment: the import machinery is heavily revised for 3.3. I believe 
 is new. I believe relative imports may 
have been changed to fix bugs. One could have been introduced (though 
there are no reports on the tracker). If so, we need to fix it. Or 
perhaps there is something special about __init__ I am not aware of.


--
Terry Jan Reedy

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


Re: How to get outer class name from an inner class?

2012-05-08 Thread Terry Reedy

On 5/8/2012 4:05 PM, John Gordon wrote:

I'm trying to come up with a scheme for organizing exceptions in
my application.

Currently, I'm using a base class which knows how to look up the text
of a specific error in a database table, keyed on the error class name.

The base class looks like this:

class ApplicationException(Exception):
 """Base class for application-specific errors."""

 def get_message(self):
 """Return the error message associated with this class name."""

 class_name = self.__class__.__name__
 return UserMessage.objects.get(key=class_name).text

And then I define a bunch of subclasses which all have different names:

class QuestionTooShortError(NetIDAppsError):
 """User entered a security question which is too short."""
 pass

class QuestionTooLongError(NetIDAppsError):
 """User entered a security question which is too long."""
 pass

This scheme works, but I'd like to make it more streamlined.  Specifically,
I'd like to group the classes underneath a parent class, like so:

class Question(ApplicationException):

 class TooShort(ApplicationException):
 pass

 class TooLong(ApplicationException):
 pass

This will make it easier in the future for organizing lots of sub-errors.


I think maybe you are being much too fine-grained in your exception 
hierarchy. Python has, for instance, just one ValueError, with details 
in the error. The details can include specific values only known at the 
point of the error. You are putting some specifics in the exception name 
and then (apparently) given them somewhat redundant canned messages 
lacking situation-specific details.


For instance
errfmt = "Security question length {:d} not in legal range {:d} - {:d}"
if not (secquemin <= len(secque) <= secquemax):
  raise ValueError(errfmt.format(len(secque), secquemin, secquemax))
# or ApplicationError or AppValueError if you want.

The messages in Python are not this good, but they slowly improve as 
people raises an issue on the tracker and others implement and apply fixex.


--
Terry Jan Reedy

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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-08 Thread Terry Reedy

On 5/8/2012 12:42 PM, Chris Angelico wrote:

On Wed, May 9, 2012 at 2:12 AM, Terry Reedy  wrote:



You still have it backwards. Risinger forked the project with a new code
host and mailing list, but stole the name and and some data in the process
and made the false claim that his fork was the original. It is not clear if
he damaged anything in the process.


Yes, but now that it's happened, the most obvious way forward is to
fork the hijacked project back to the original, given that the
hijacked one is being posted as the original.


Risinger's fork is NOT the original, no matter what his claim. People 
should not give credit to his false claim or regard it as an 
accomplished fact.


From what others have posted, it has a new code repository (that being 
the ostensible reason for the fork), project site, and mailing list -- 
the latter two incompetently. Apparently, the only thing he has kept are 
the domain and project names (the latter for sure not legitimately).


Luke has not abandoned pyjamas and has not, as of now, ceded ownership 
of the name to anyone. I am pretty sure Luke he has no plans to adandon 
his current codebase and and re-fork off of the Risinger et al revised 
codebase.



If Luke continues his original project, it would still be the true pyjamas
project, not a fork.


Yeah, but if he doesn't have command of the domain any more, then
he'll likely be spawning it under a new name somewhere.


Yes, but so what? The domain name is not the project. Open source 
projects change domain names all the time (though hopefully rarely for 
any particular project).


--
Terry Jan Reedy

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


Re: Retrieving result from embedded execution

2012-05-08 Thread William R. Wing (Bill Wing)
On May 8, 2012, at 3:07 PM, F L wrote:

> Hello everyone,
> 
> We are trying to implement our own interactive interpreter in our application
> using an embedded Python interpreter.
> 
> I was wondering what would be the best way to retreive as text the result of  
> executing Python code. The text must be exactly the same as it would be in the
> standalone interpreter.
> 
> We used to do this by changing the embedded interpreter's sys.stdout and 
> sys.stderr
> with a FILE created in C++. We could then execute code using the 
> PyRun_InteractiveOne
> function and easily retrieve the result from the FILE. The problem is, our 
> application
> shouldn't create any files if possible.
> 
> We also tried replacing sys.stdout and sys.stderr with a custom made Python 
> object
> which could be more easily read from C++. We then used the function 
> PyRun_String
> to execute the code. The problem here is that using the Py_file_input start 
> token
> doesn't write everything we need to sys.stdout. (i.e. executing 2+2 does not 
> write 4).
> It also doesn't print a traceback to sys.stderr when there is an exception. 
> Using the
> other two start tokens is impossible since we need to be able to execute more 
> than 
> one instruction at once. We also tried using the function PyRun_SimpleString 
> but we
> encounter the same problems.
> 
> We are using python 2.7. 
> 
> Any suggestions? 
> 
> Thank you for your time.

[byte]

I'm pretty new to Python myself, and I may not understand what you are trying 
to do, but have you looked at the subprocess module?

Documented here:  http://docs.python.org/library/subprocess.html  

Using subprocess.Popen would let you hook stdin and staout directly to pipes 
that will pass data back to the calling program with no intermediate steps.

-Bill

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


Re: How to get outer class name from an inner class?

2012-05-08 Thread Chris Rebert
On Tue, May 8, 2012 at 1:05 PM, John Gordon  wrote:
> I'm trying to come up with a scheme for organizing exceptions in
> my application.
>
> Currently, I'm using a base class which knows how to look up the text
> of a specific error in a database table, keyed on the error class name.
>
> The base class looks like this:
>
> class ApplicationException(Exception):
>    """Base class for application-specific errors."""
>
>    def get_message(self):
>        """Return the error message associated with this class name."""
>
>        class_name = self.__class__.__name__
>        return UserMessage.objects.get(key=class_name).text
>
> And then I define a bunch of subclasses which all have different names:
>
> class QuestionTooShortError(NetIDAppsError):
>    """User entered a security question which is too short."""
>    pass
>
> class QuestionTooLongError(NetIDAppsError):
>    """User entered a security question which is too long."""
>    pass
>
> This scheme works, but I'd like to make it more streamlined.  Specifically,
> I'd like to group the classes underneath a parent class, like so:
>
> class Question(ApplicationException):
>
>    class TooShort(ApplicationException):
>        pass
>
>    class TooLong(ApplicationException):
>        pass
>
> This will make it easier in the future for organizing lots of sub-errors.

You could use modules instead…
Nested classes are stylistically questionable.

> My problem is this: the get_message() method in the base class only knows
> the current class name, i.e. "TooShort" or "TooLong".  But that's not
> enough; I also need to know the outer class name, i.e. "Question.TooShort"
> or "Question.TooLong".  How do I get the outer class name?

Use __qualname__ and chop off the last dotted part (i.e. the innermost
class' name, thus yielding its parent's name).
PEP 3155 -- Qualified name for classes and functions:
http://www.python.org/dev/peps/pep-3155/

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


Re: indexed property? Can it be done?

2012-05-08 Thread Adam Tauno Williams
On Mon, 2012-05-07 at 20:15 -0700, Charles Hixson wrote: 
> class Node:
>  def__init__(self, nodeId, key, value, downRight, downLeft, parent):
>  dirty=True
>  dlu=utcnow()
>  self.node=[nodeId, downLeft, [key], [value], 
> [downRight], parent, dirty, dlu]
> Note that node[3] is a list of keys (initially 1) and node[3] is a list 
> of values, etc.
> What I'd like to do is to be able to address them thusly:
> k = node.key[2]
> v = node.value[2]
> but if there's a way to do this, I haven't been able to figure it out.  
> Any suggestions?

Do not do this;  this is bad code in any language.  


signature.asc
Description: This is a digitally signed message part
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get outer class name from an inner class?

2012-05-08 Thread John Gordon
In  John Gordon  writes:

> class QuestionTooShortError(NetIDAppsError):
> """User entered a security question which is too short."""
> pass

> class QuestionTooLongError(NetIDAppsError):
> """User entered a security question which is too long."""
> pass

Oops!  These classes inherit from ApplicationException, not NetIDAppsError.

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

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


How to get outer class name from an inner class?

2012-05-08 Thread John Gordon
I'm trying to come up with a scheme for organizing exceptions in
my application.

Currently, I'm using a base class which knows how to look up the text
of a specific error in a database table, keyed on the error class name.

The base class looks like this:

class ApplicationException(Exception):
"""Base class for application-specific errors."""

def get_message(self):
"""Return the error message associated with this class name."""

class_name = self.__class__.__name__
return UserMessage.objects.get(key=class_name).text

And then I define a bunch of subclasses which all have different names:

class QuestionTooShortError(NetIDAppsError):
"""User entered a security question which is too short."""
pass

class QuestionTooLongError(NetIDAppsError):
"""User entered a security question which is too long."""
pass

This scheme works, but I'd like to make it more streamlined.  Specifically,
I'd like to group the classes underneath a parent class, like so:

class Question(ApplicationException):

class TooShort(ApplicationException):
pass

class TooLong(ApplicationException):
pass

This will make it easier in the future for organizing lots of sub-errors.

My problem is this: the get_message() method in the base class only knows
the current class name, i.e. "TooShort" or "TooLong".  But that's not
enough; I also need to know the outer class name, i.e. "Question.TooShort"
or "Question.TooLong".  How do I get the outer class name?

Thanks,

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

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


Re: pickle question: sequencing of operations

2012-05-08 Thread Ian Kelly
On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen  wrote:
> In article ,
>  "Russell E. Owen"  wrote:
>
>> What is the sequence of calls when unpickling a class with __setstate__?

I believe it just calls object.__new__ followed by
yourclass.__setstate__.  So at the point __setstate__ is called, you
have a pristine instance of whatever class you're unpickling.

> The following seems to work, but I don't know why:
> def __getstate__(self):
>   ...return the argument dict needed for __init__
>
> def __setstate__(self, argdict):
>   self.__init__(**argdict)

That seems like it should be fine as long as all your initialization
code is in __init__ and not in __new__.

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


Re: pickle question: sequencing of operations

2012-05-08 Thread Russell E. Owen
In article ,
 "Russell E. Owen"  wrote:

> What is the sequence of calls when unpickling a class with __setstate__?
> 
> >From experimentation I see that __setstate__ is called and __init__ is 
> not, but I think I need more info.
> 
> I'm trying to pickle an instance of a class that is a subclass of 
> another class that contains unpickleable objects.
> 
> What I'd like to do is basically just pickle the constructor parameters 
> and then use those to reconstruct the object on unpickle, but I'm not 
> sure how to go about this. Or an example if anyone has one.

The following seems to work, but I don't know why:
def __getstate__(self):
   ...return the argument dict needed for __init__

def __setstate__(self, argdict):
   self.__init__(**argdict)

-- Russell

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


Using modules from Debian "python3-..." packages with locally compiled Python 3.3

2012-05-08 Thread Edward C. Jones

I use up-to-date Debian testing (wheezy), amd64 architecture.  I downloaded,
compiled and installed Python 3.3.0 alpha 3 (from python.org) using
"altinstall".  Debian wheezy comes with python3.2 (and 2.6 and 2.7).  I
installed the Debian package "python3-bs4" (BeautifulSoup4 for Python3).
Note: Debian uses eggs.

Python3.3a3 cannot find module bs4. Python3.2 can find the module.  Here is
a session with Python 3.3:

> python3.3
Python 3.3.0a3 (default, May  5 2012, 11:30:48)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1012, in _find_and_load
ImportError: No module named 'bs4'
>>>

Here is what I have tried:

1. Put bs4.pth in /usr/local/lib/python3.3/site-packages.  This file should
contain the line:
  /usr/lib/python3/dist-packages
This works.

2. At the start of each Python program using bs4:
 import sys
 sys.path.append('/usr/lib/python3/dist-packages')
 import bs4
This works.

3. In the Python 3.3 source code, do ".configure" then edit Modules/Setup to
contain
SITEPATH=:/usr/lib/python3/dist-packages
Finish compiling and altinstalling python.  "import bs4" works.

The last is the best because I only have to do it once.

Next I tried numpy.  It is installed from Debian package "python3-numpy".
If I compile Python 3.3 _without_ the change in (3) above, I get:

> python3.3
Python 3.3.0a3 (default, May  8 2012, 14:30:18)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1012, in _find_and_load
ImportError: No module named 'numpy'
>>>

which is not a surprise. If I compile and install Python 3.3 _with_ the
change in (3) above, I get:

> python3.3
Python 3.3.0a3 (default, May  8 2012, 14:43:28)
[GCC 4.6.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1015, in _find_and_load
  File "", line 634, in load_module
  File "", line 294, in
  module_for_loader_wrapper
  File "", line 522, in _load_module
  File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 137, in

from . import add_newdocs
ImportError: cannot import name add_newdocs
>>>

"add_newdocs.py" is present in the numpy directory.

The "import numpy" works for the Debian python 3.2.

What is the problem?

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


Retrieving result from embedded execution

2012-05-08 Thread F L




Hello everyone,
We are trying to implement our own interactive interpreter in our 
applicationusing an embedded Python interpreter.
I was wondering what would be the best way to retreive as text the result of  
executing Python code. The text must be exactly the same as it would be in 
thestandalone interpreter.
We used to do this by changing the embedded interpreter's sys.stdout and 
sys.stderrwith a FILE created in C++. We could then execute code using the 
PyRun_InteractiveOnefunction and easily retrieve the result from the FILE. The 
problem is, our applicationshouldn't create any files if possible.
We also tried replacing sys.stdout and sys.stderr with a custom made Python 
objectwhich could be more easily read from C++. We then used the function 
PyRun_Stringto execute the code. The problem here is that using the 
Py_file_input start tokendoesn't write everything we need to sys.stdout. (i.e. 
executing 2+2 does not write 4).It also doesn't print a traceback to sys.stderr 
when there is an exception. Using theother two start tokens is impossible since 
we need to be able to execute more than one instruction at once. We also tried 
using the function PyRun_SimpleString but weencounter the same problems.
We are using python 2.7. 
Any suggestions? 
Thank you for your time.
Also, I'm new to mailling lists, what is the proper way to reply to someone? 
Should Ireply directly to someone's email adress or is there a way to answer 
trough the server.
F. Lab
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: which book?

2012-05-08 Thread Alec Taylor
plot issues?

On Wed, May 9, 2012 at 4:16 AM,   wrote:
> folks
> hi,
> I am going to learn python for some plot issues. which book or sources, do 
> you recommend please?
> Cheers,
> Dave
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


which book?

2012-05-08 Thread d . poreh
folks 
hi, 
I am going to learn python for some plot issues. which book or sources, do you 
recommend please?
Cheers,
Dave
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: indexed property? Can it be done?

2012-05-08 Thread Ian Kelly
On Tue, May 8, 2012 at 10:30 AM, Charles Hixson
 wrote:
> That depends on what you're doing.  For many, perhaps most, purposes I would
> agree.  Not for this one.  And I couldn't use an internal dict, as the order
> in which the items of the sub-lists occur is significant.  The sub-lists
> need to be lists, though they could be separated out as named variables
> (which would be lists).

It sounds like a collections.OrderedDict should do what you need.  In
the cases where you really need to have a list of keys or values, you
can just use the .keys() and .values() methods.

> The ActiveState recipe *might* do what I want.  I honestly can't tell after
> a brief study.  But it's much too complex to be a worthwhile choice.  I was
> hoping that I'd just overlooked one of the standard features of Python.

What do you find complex about it?  The two class definitions are
something you would put in a library module to be imported.  The rest
is just example / test code.  The actual usage is no more complex than
a regular property:

class Node(object):

   def__init__(self, nodeId, key, value, downRight, downLeft, parent):
   dirty=True
   dlu=utcnow()
   self.node=[nodeId, downLeft, [key], [value],
[downRight], parent, dirty, dlu]

@itemproperty
def key(self, index):
return self.node[2][index]

@itemproperty
def value(self, index):
return self.node[3][index]

And of course you could also add setters and/or deleters if desired.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-08 Thread Chris Angelico
On Wed, May 9, 2012 at 2:12 AM, Terry Reedy  wrote:
> On 5/8/2012 9:47 AM, Chris Angelico wrote:
>>
>> On Tue, May 8, 2012 at 11:43 PM, Devin Jeanpierre
>>   wrote:
>>>
>>> There is no "both projects". there was Luke's project, and then
>>> Risinger stole it and it's Risinger's project. There is only that one
>>> thing -- Luke has no """fork""" of his own codebase.
>>
>>
>> Presumably Luke could fork his own project, though. I haven't checked,
>> but presumably the source is properly managed, so it can be forked as
>> of any point in time.
>>
>> But it's pretty nasty to have to fork your own project.
>
>
> You still have it backwards. Risinger forked the project with a new code
> host and mailing list, but stole the name and and some data in the process
> and made the false claim that his fork was the original. It is not clear if
> he damaged anything in the process.

Yes, but now that it's happened, the most obvious way forward is to
fork the hijacked project back to the original, given that the
hijacked one is being posted as the original.

> If Luke continues his original project, it would still be the true pyjamas
> project, not a fork.

Yeah, but if he doesn't have command of the domain any more, then
he'll likely be spawning it under a new name somewhere.

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


Re: indexed property? Can it be done?

2012-05-08 Thread Charles Hixson

On 05/08/2012 12:50 AM, Peter Otten wrote:

Charles Hixson wrote:

   

class Node:

  def__init__(self, nodeId, key, value, downRight, downLeft,
  parent):
  dirty=True
  dlu=utcnow()
  self.node=[nodeId, downLeft, [key], [value],
[downRight], parent, dirty, dlu]

Note that node[3] is a list of keys (initially 1) and node[3] is a list
of values, etc.

What I'd like to do is to be able to address them thusly:
k = node.key[2]
v = node.value[2]
but if there's a way to do this, I haven't been able to figure it out.
Any suggestions?
 

I don't see the problem:

   

class Node(object):
 

... def __init__(self, key):
... self.node = ["foo", "bar", [key], "baz"]
... @property
... def key(self):
... return self.node[2]
...
   

node = Node(42)
node.key
 

[42]
   

node.key[0]
 

42
   

node.key.append(7)
node.key
 

[42, 7]
   

del node.key[0]
node.key[:] = [3, 2, 1]
node.key
 

[3, 2, 1]
   

node.key = "foo"
 

Traceback (most recent call last):
   File "", line 1, in
AttributeError: can't set attribute

But the design proposed by Dan Sommers really is the way to go...

   
That depends on what you're doing.  For many, perhaps most, purposes I 
would agree.  Not for this one.  And I couldn't use an internal dict, as 
the order in which the items of the sub-lists occur is significant.  The 
sub-lists need to be lists, though they could be separated out as named 
variables (which would be lists).


The approach of returning the entire list would, indeed, work, but it 
exposes things that I would prefer to keep internal to the class (i.e., 
all the, e.g., keys that aren't currently being addressed).  I suppose 
it isn't too inefficient, as IIUC, all you're really passing back and 
forth are pointers, but it doesn't *feel* like the right answer.  So I 
can handle it by using getter and setter functions that recognize 
indicies, but it's less elegant than using indexing to access them.  So 
I thought I'd ask.


The ActiveState recipe *might* do what I want.  I honestly can't tell 
after a brief study.  But it's much too complex to be a worthwhile 
choice.  I was hoping that I'd just overlooked one of the standard 
features of Python.


To be truthful, the main benefit I see from using a class rather than a 
naked list structure is that I can readily test the type of the data.  A 
secondary benefit would be the nicer syntax, as with the list all 
manipulation would be done via specialized functions, and for some of 
the terms indexed access would be syntactically nicer.  But it looks 
like that isn't one of the possibilities.  Using a native list structure 
and manipulatory functions is nicer except in two ways:
1) There's no data hiding, so discipline must substitute for language 
structure.
2) There's excess names apparent at an upper level.  I wouldn't exactly 
call it namespace pollution, but it's certainly an increase in the 
higher-level namespace background noise level, even though it's all 
functional.


--
Charles Hixson

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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-08 Thread Terry Reedy

On 5/8/2012 9:47 AM, Chris Angelico wrote:

On Tue, May 8, 2012 at 11:43 PM, Devin Jeanpierre
  wrote:

There is no "both projects". there was Luke's project, and then
Risinger stole it and it's Risinger's project. There is only that one
thing -- Luke has no """fork""" of his own codebase.


Presumably Luke could fork his own project, though. I haven't checked,
but presumably the source is properly managed, so it can be forked as
of any point in time.

But it's pretty nasty to have to fork your own project.


You still have it backwards. Risinger forked the project with a new code 
host and mailing list, but stole the name and and some data in the 
process and made the false claim that his fork was the original. It is 
not clear if he damaged anything in the process.


If Luke continues his original project, it would still be the true 
pyjamas project, not a fork.


--
Terry Jan Reedy

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


Re: Problem with time.time() standing still

2012-05-08 Thread Bob Cowdery
Hopefully somebody can add the last piece of this puzzle. My code didn't 
work because I did make a silly mistake. The number of seconds since 
EPOC is a large number but it also needs a high precision. Attempting to 
put this value into a 32 bit float corrupts the least significant part 
because 24 bits  cannot hold that precision. Now Python floats are C 
doubles and the calculation in timemodule.c is in doubles right back to 
Python. Normally this retains the precision. For some inexplicable 
reason when I make certain calls into this vendors SDK, ftime()  is 
getting precision problems and appears to be frozen as a result.


C, only supporting early binding cannot change the function referenced 
at runtime so how the devil is it managing to do this.


On 08/05/2012 12:17, Bob Cowdery wrote:

Can anyone make sense of this.

I've looked over the Python timemodule.c again and it uses one of 
gettimeofday(), ftime() or time(). The gettimeofday() is not available 
on Windows so its going to use ftime() or time(). As time() only has a 
resolution of 1 second and returns a long and I know Python 
time.time() has a ms resolution it must be using ftime().


After going round the houses - a lot. I've made a trivially simple 
extension that goes wrong. I can only think I must be doing something 
incredibly stupid. Perhaps someone can put me out of my misery.


In the full app what happens is that it reports the correct time as 
given by time() by gets the ms from somewhere also. When it goes wrong 
it reports the same time as ftime().


Bob

>>> import mytime
>>> mytime.doTime()
TIME : 1336474857
FTIME secs 1336474880.00
FTIME ms 0.601000
FTIME secs+ms 1336474880.601000
0
>>> mytime.doTime()
TIME : 1336474871
FTIME secs 1336474880.00
FTIME ms 0.548000
FTIME secs+ms 1336474880.548000
0
>>> mytime.doTime()
TIME : 1336474897
FTIME secs 1336474880.00
FTIME ms 0.007000
FTIME secs+ms 1336474880.007000
0

The extension just prints out the time as got from time() and ftime(). 
For a start the two do not agree on what the time is. Secondly ftime() 
stops incrementing while the python session is running. If I start a 
new session it will have incremented.


>>> import mytime
>>> mytime.doTime()
TIME : 1336475029
FTIME secs 1336475008.00
FTIME ms 0.265000
FTIME secs+ms 1336475008.265000
0

Code and build file


#include "Python.h"
#include 
#include 
#include 
#include 

static struct timeb t;
static float secs = 0.0;
static float ms = 0.0;
static float both = 0.0;

static PyObject *doTime(
PyObject *self,
PyObject *args) {
time_t seconds;
seconds = time (NULL);
printf ("TIME : %ld\n", seconds);
ftime(&t);
secs = (float)t.time;
ms = (float)((float)t.millitm * 0.001);
printf("FTIME secs+ms %f\n",  secs + ms);

return PyInt_FromLong((long)0);
}

static PyMethodDef pyInst_Methods[] = {

{"doTime",
doTime,
METH_VARARGS},
{NULL, NULL, 0, NULL}
};

#ifndef PyMODINIT_FUNC
#define PyMODINIT_FUNC void
#endif /* PyMODINIT_FUNC */

PyMODINIT_FUNC initmytime(void)
{
PyObject *module;
module = Py_InitModule3("mytime", pyInst_Methods,"Time module");
if (!module) return;
}

Build file

import os
from distutils.core import setup
from distutils.extension import Extension

if os.path.exists('C:\\Program Files (x86)'):
# 64 bit
ProgramFiles = 'Program Files (x86)'
else:
# 32 bit
ProgramFiles = 'Program Files'

setup(
name='Time Test',
author='Bob Cowdery',
ext_modules = [
Extension('mytime',
['pytime.cpp'],
include_dirs = ['C:\\' + ProgramFiles + 
'\\Microsoft SDKs\\Windows\\v7.0A\\Include', 'C:\\Python26\\include'],

#define_macros = [("_AFXDLL", None)],
library_dirs = ['C:\\' + ProgramFiles + 
'\\Microsoft SDKs\\Windows\\v7.0A\\Lib', 'C:\\Python26\\libs'],
libraries = ['User32', 'Gdi32', 'python26', 
'odbc32', 'odbccp32']

)
]
)

On 06/05/2012 10:19, Bob Cowdery wrote:

On 06/05/2012 09:49, Cameron Simpson wrote:

On 06May2012 09:18, Bob Cowdery  wrote:
| On 05/05/2012 23:05, Cameron Simpson wrote:
|>  On 05May2012 20:33, Bob Cowdery  wrote:
|>  | [...] calls to time.time() always return the same
|>  | time which is usually several seconds in the past or future 
and always

|>  | has no fractional part.
|>
|>  Thought #1: you are calling time.time() and haven't unfortunately
|>  renamed it? (I doubt this scenario, though the lack of 
fractional part

|>  is interesting.)
|
| Not sure what you mean by renamed it.

Like this:

   from time import time
   [...]
   time = some_unfortunate_other_function
   [...]
   now = time()  # calls wrong function

It seems unlikely, but possible.

| I also tried datetime and that had
| the same behaviour.

Makes my suggestion even less likely unless the time module itself gets
monkeypatch

Re: Expand RFC-2445 (iCalendar) recurrence rule?

2012-05-08 Thread Roy Smith
O.B. Murithi suggested I look at http://labix.org/python-dateutil, which turns 
out to have exactly what I'm looking for.  Thanks!

from dateutil.rrule import rrulestr
from dateutil.parser import parse

rule = rrulestr("FREQ=WEEKLY;COUNT=6;INTERVAL=2;BYDAY=FR",
dtstart=parse("2012-06-15"))
for date in rule:
print date

./rrule.py
2012-06-15 00:00:00
2012-06-29 00:00:00
2012-07-13 00:00:00
2012-07-27 00:00:00
2012-08-10 00:00:00
2012-08-24 00:00:00
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-08 Thread Chris Angelico
On Tue, May 8, 2012 at 11:43 PM, Devin Jeanpierre
 wrote:
> There is no "both projects". there was Luke's project, and then
> Risinger stole it and it's Risinger's project. There is only that one
> thing -- Luke has no """fork""" of his own codebase.

Presumably Luke could fork his own project, though. I haven't checked,
but presumably the source is properly managed, so it can be forked as
of any point in time.

But it's pretty nasty to have to fork your own project.

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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-08 Thread Devin Jeanpierre
On Tue, May 8, 2012 at 1:20 AM, Chris Angelico  wrote:
> I hope that pyjamas can be restored at some point to a single live
> project. Whether that's headed by Luke Leighton or C Anthony Risinger
> (neither of whom I know at all and thus I can't speak to either's
> merits) or someone else, I don't particularly care, but frankly, I
> don't think there's need in the world for a fork of such a project.
> Aside from philosophical disagreements, what would be the differences
> between the Luke fork and the Anthony fork? Could anyone explain, to a
> prospective user, why s/he should pick one or the other? If not, the
> projects need to merge, or else one will die a sad death of
> stagnation.

There is no "both projects". there was Luke's project, and then
Risinger stole it and it's Risinger's project. There is only that one
thing -- Luke has no """fork""" of his own codebase.

I guess it won't die of stagnation, eh? It'll be a perfectly usable,
stable project, led by a thief.

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


Re: How do I run a python program from an internet address?

2012-05-08 Thread james hedley

> What would be the best way to figure out how to do this?  I looked at
> Google app engine tutorial, but can't figure out how that will help we
> get the code into the cloud so I can access it from any browser.

GAE is quite a good option, since it includes free hosting. You should be able 
to get started just by downloading the SDK and making your app work locally. It 
includes a little development server so you can see what your users will see in 
your own browser. In this way, you don't have to do anything with the web until 
everything is ready, then you just press a button (windows) or run a script 
(nix) and yor app appears on the web. The datastore is quite complicated though!

If you rig up your own host though, you have a lot more freedom with what 
software you get to use. A very simple way is to plug mod_wsgi into apache (a 
common web server) and then write your app as a wsgi script; this usually just 
entails adding a couple of necessary methods to your script. In my case, I have 
a buddy with a web host set up so I can get things up on there very easily and 
for free.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for proven Python code for Line Simplication such as Douglas-Peucker

2012-05-08 Thread Robert Kern

On 5/8/12 10:38 AM, David Shi wrote:

Dear All,

I am looking for proven Python code for Line Simplication such as 
Douglas-Peucker.


https://svn.enthought.com/svn/enthought/EnthoughtBase/trunk/enthought/util/dp.py

--
Robert Kern

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

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


Expand RFC-2445 (iCalendar) recurrence rule?

2012-05-08 Thread Roy Smith
Does there exist a stand-alone module to expand RFC-2445 recurrence 
rule?  The idea is to start with a string like:

"RRULE:FREQ=WEEKLY;COUNT=6;INTERVAL=2;BYDAY=FR"

and derive a list of dates on which that event occurs.

I'm aware of http://codespeak.net/icalendar/, but that solves a much 
larger problem (parsing ics files) and I can't see how to tease out just 
this one function from that module.
-- 
http://mail.python.org/mailman/listinfo/python-list


Looking for proven Python code for Line Simplication such as Douglas-Peucker

2012-05-08 Thread David Shi
Dear All,

I am looking for  proven Python code for Line Simplication such as 
Douglas-Peucker.

Regards.

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


Re: Problem with time.time() standing still

2012-05-08 Thread Bob Cowdery

Can anyone make sense of this.

I've looked over the Python timemodule.c again and it uses one of 
gettimeofday(), ftime() or time(). The gettimeofday() is not available 
on Windows so its going to use ftime() or time(). As time() only has a 
resolution of 1 second and returns a long and I know Python time.time() 
has a ms resolution it must be using ftime().


After going round the houses - a lot. I've made a trivially simple 
extension that goes wrong. I can only think I must be doing something 
incredibly stupid. Perhaps someone can put me out of my misery.


In the full app what happens is that it reports the correct time as 
given by time() by gets the ms from somewhere also. When it goes wrong 
it reports the same time as ftime().


Bob

>>> import mytime
>>> mytime.doTime()
TIME : 1336474857
FTIME secs 1336474880.00
FTIME ms 0.601000
FTIME secs+ms 1336474880.601000
0
>>> mytime.doTime()
TIME : 1336474871
FTIME secs 1336474880.00
FTIME ms 0.548000
FTIME secs+ms 1336474880.548000
0
>>> mytime.doTime()
TIME : 1336474897
FTIME secs 1336474880.00
FTIME ms 0.007000
FTIME secs+ms 1336474880.007000
0

The extension just prints out the time as got from time() and ftime(). 
For a start the two do not agree on what the time is. Secondly ftime() 
stops incrementing while the python session is running. If I start a new 
session it will have incremented.


>>> import mytime
>>> mytime.doTime()
TIME : 1336475029
FTIME secs 1336475008.00
FTIME ms 0.265000
FTIME secs+ms 1336475008.265000
0

Code and build file


#include "Python.h"
#include 
#include 
#include 
#include 

static struct timeb t;
static float secs = 0.0;
static float ms = 0.0;
static float both = 0.0;

static PyObject *doTime(
PyObject *self,
PyObject *args) {
time_t seconds;
seconds = time (NULL);
printf ("TIME : %ld\n", seconds);
ftime(&t);
secs = (float)t.time;
ms = (float)((float)t.millitm * 0.001);
printf("FTIME secs+ms %f\n",  secs + ms);

return PyInt_FromLong((long)0);
}

static PyMethodDef pyInst_Methods[] = {

{"doTime",
doTime,
METH_VARARGS},
{NULL, NULL, 0, NULL}
};

#ifndef PyMODINIT_FUNC
#define PyMODINIT_FUNC void
#endif /* PyMODINIT_FUNC */

PyMODINIT_FUNC initmytime(void)
{
PyObject *module;
module = Py_InitModule3("mytime", pyInst_Methods,"Time module");
if (!module) return;
}

Build file

import os
from distutils.core import setup
from distutils.extension import Extension

if os.path.exists('C:\\Program Files (x86)'):
# 64 bit
ProgramFiles = 'Program Files (x86)'
else:
# 32 bit
ProgramFiles = 'Program Files'

setup(
name='Time Test',
author='Bob Cowdery',
ext_modules = [
Extension('mytime',
['pytime.cpp'],
include_dirs = ['C:\\' + ProgramFiles + 
'\\Microsoft SDKs\\Windows\\v7.0A\\Include', 'C:\\Python26\\include'],

#define_macros = [("_AFXDLL", None)],
library_dirs = ['C:\\' + ProgramFiles + 
'\\Microsoft SDKs\\Windows\\v7.0A\\Lib', 'C:\\Python26\\libs'],
libraries = ['User32', 'Gdi32', 'python26', 
'odbc32', 'odbccp32']

)
]
)

On 06/05/2012 10:19, Bob Cowdery wrote:

On 06/05/2012 09:49, Cameron Simpson wrote:

On 06May2012 09:18, Bob Cowdery  wrote:
| On 05/05/2012 23:05, Cameron Simpson wrote:
|>  On 05May2012 20:33, Bob Cowdery  wrote:
|>  | [...] calls to time.time() always return the same
|>  | time which is usually several seconds in the past or future and always
|>  | has no fractional part.
|>
|>  Thought #1: you are calling time.time() and haven't unfortunately
|>  renamed it? (I doubt this scenario, though the lack of fractional part
|>  is interesting.)
|
| Not sure what you mean by renamed it.

Like this:

   from time import time
   [...]
   time = some_unfortunate_other_function
   [...]
   now = time()  # calls wrong function

It seems unlikely, but possible.

| I also tried datetime and that had
| the same behaviour.

Makes my suggestion even less likely unless the time module itself gets
monkeypatched (i.e. "time.time = bad_function" somewhere).

I don't think the function is subverted unless there is some way inside
the vendor SDK or even DirectShow (the SDK uses this as a COM object)
which can somehow hijack it. It does catch up every few minutes so there
has to be a clue there.

|>  | If I leave it long enough time will suddently
|>  | jump forward after a few minutes, then again after a few minutes more.
|>  |
|>  | I've never encountered this behaviour before and can't understand what
|>  | on earth is going on. If I call the 'C' time() function just the other
|>  | side of my call to the extension the time is ticking along fine. It's
|>  | just the one Python thread that is affected.
|>  [...]
|>
|>  Thought #2: On a UNIX system I'd be running the process under strace (or
|>  dtrace or k

Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-08 Thread Tim Wintle
On Tue, 2012-05-08 at 15:20 +1000, Chris Angelico wrote:
> I hope that pyjamas can be restored at some point to a single live
> project. Whether that's headed by Luke Leighton or C Anthony Risinger
> (neither of whom I know at all and thus I can't speak to either's
> merits) or someone else, I don't particularly care

I have met Luke (At Europython), and honestly it was his enthusiasm that
got me to look at pyjamas in the first place. To be fair I still haven't
used it in anger, but I've poked around a lot, it's been under
consideration for several bits of work.

Although I don't think I've met C Anthony Risinger, his behaviour has
seriously put me off the project - and if I consider using it in the
future I'm going to be "pricing in" the cost of maintaining a complete
local fork as part of the decision.

Tim

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


Re: Open Source: you're doing it wrong - the Pyjamas hijack

2012-05-08 Thread james hedley
Agreed with pretty much all of that. It's third-world politics, lurching from 
one dictator to another. Risinger seems to have banned all discussion of the 
subject from the list too, I'm not posting anymore because I don't want to give 
him an excuse to wield his newly found banhammer.

But yeah, a lot of the commentary from the pro-rebel side ( not that any of 
them admit they had anything to do with it ) really does come across as being 
ill-informed and childish.

This story is on reddit, if anyone is that way inclined:

http://www.reddit.com/r/opensource/comments/t5acr/project_hijacked_advice_from_experience_foss/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: indexed property? Can it be done?

2012-05-08 Thread Peter Otten
Charles Hixson wrote:

> class Node:
> 
>  def__init__(self, nodeId, key, value, downRight, downLeft,
>  parent):
>  dirty=True
>  dlu=utcnow()
>  self.node=[nodeId, downLeft, [key], [value],
> [downRight], parent, dirty, dlu]
> 
> Note that node[3] is a list of keys (initially 1) and node[3] is a list
> of values, etc.
> 
> What I'd like to do is to be able to address them thusly:
> k = node.key[2]
> v = node.value[2]
> but if there's a way to do this, I haven't been able to figure it out.
> Any suggestions?

I don't see the problem: 

>>> class Node(object):
... def __init__(self, key):
... self.node = ["foo", "bar", [key], "baz"]
... @property
... def key(self):
... return self.node[2]
... 
>>> node = Node(42)
>>> node.key
[42]
>>> node.key[0]
42
>>> node.key.append(7)
>>> node.key
[42, 7]
>>> del node.key[0]
>>> node.key[:] = [3, 2, 1]
>>> node.key
[3, 2, 1]
>>> node.key = "foo"
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: can't set attribute

But the design proposed by Dan Sommers really is the way to go...

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