functools.wraps does not play nice with doc tests?

2015-05-29 Thread Vlad
Hello,

So, I know this topic comes up a lot, but I haven't been able to find any 
discussion on this particular twist on the topic. Perhaps someone has some 
insight.

So, I have a function, which is decorated. In order for the doctest test finder 
to find the doc tests in the decorated function, my wrapper needs to use the 
functools.wraps decorator inside it. So far so good. *However*, the issue is 
that if the decorator and the decorated function are defined in different 
modules, and the decorator is defined at a greater line number in its module 
than the decorated function in its module, and the doc test fails, the test 
report lists the failure as occurring at an "unknown line number". This is a 
problem if you have additional logic built on top of the reporting that relies 
on line numbers of test failures (and even more fundamentally, it's a pain to 
manually find which test actually failed). 

Here is a specific example, this is running Python 2.7.9, in case that matters.

File decorator.py
 1  import functools
 2
 3
 4
 5
 6
 7
 8
 9  # The decorator has to be defined at a line number greater than the
10  # decorated function in order to trigger the bug.
11  def decorator(func):
12  @functools.wraps(func)
13  def wrapper(*args, **kwargs):
14  print('In Wrapper!')
15  return func(*args, **kwargs)
16  return wrapper


File decorated.py
 1  from . import decorator
 2
 3
 4  @decorator.decorator
 5  def my_func():
 6  '''
 7  >>> my_func()
 8  '''
 9  print('my_func!')
10
11
12  if __name__ == '__main__':
13  import doctest
14  doctest.testmod()


Now, let's try to run the tests:
> python -m decorated
**
File ".../decorated.py", line ?, in __main__.my_func
Failed example:
my_func()
Expected nothing
Got:
In Wrapper!
my_func!
**
1 items had failures:
   1 of   1 in __main__.my_func
***Test Failed*** 1 failures.


So, the test ran, and failed as we wanted, but the line number was not detected 
correctly. Has anyone run into this issue, and/or know a workaround? Or perhaps 
I am missing something obvious here?
-- 
https://mail.python.org/mailman/listinfo/python-list


SQLite or files?

2009-09-17 Thread vlad
Hello,

I'm a novice in Python and got one question related to the information
storage for my application.

I'm currently working on rewriting my own the program that stores
everyday information sitting in the system tray. It was written in
Delphi some time ago and proved to be durable and fast enough. All the
info was stored in the simple RTF files.

However now I'd like to rewrite this program in Python (using PyQt) as
I want to make it cross-platform and add/remove some features. Now I'm
thinking about where to store my information. Would it be better to
use files as I used to do or use the database, SQLite in particular?
What will be faster and more flexible in the long run? This
application will be in the memory most of the time so I'm also
concerned about memory usage.

If anyone has any experience of comparison these two approaches please
help.

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


sys.tracebacklimit

2011-07-13 Thread Vlad Didenko
Colleagues,

Per documentation at 
http://docs.python.org/py3k/library/sys.html#sys.tracebacklimit :

 When [sys.tracebacklimit] set to 0 or less, all traceback information is 
suppressed and only the exception type and value are printed

So, I expect to be able to have a program like:

import sys
sys.tracebacklimit=0
print(1/0)

And see it's result as:

 ZeroDivisionError: division by zero

However, the actual result is:

 Traceback (most recent call last):
   File "tbt.py", line 3, in 
 print(1/0)
 ZeroDivisionError: division by zero

Do I misunderstand the docs?

Thank you!
Vlad


This e-mail and its attachments are intended only for the individual or entity 
to whom it is addressed and may contain information that is confidential, 
privileged, inside information, or subject to other restrictions on use or 
disclosure. Any unauthorized use, dissemination or copying of this transmission 
or the information in it is prohibited and may be unlawful. If you have 
received this transmission in error, please notify the sender immediately by 
return e-mail, and permanently delete or destroy this e-mail, any attachments, 
and all copies (digital or paper). Unless expressly stated in this e-mail, 
nothing in this message should be construed as a digital or electronic 
signature.
-- 
http://mail.python.org/mailman/listinfo/python-list


Getting and Setting Cookies

2006-07-18 Thread Vlad Dogaru
Hello,

I am trying to use cookies and Python to create a simple login example.
But I am very disoriented at the existence of two cookie libraries,
namely Cookie and cookielib. I have seen examples of setting cookies
(although I am still not sure about timestamps and cookie lifespan),
but no reference to getting the currently set cookies. For instance, I
want to see if there is any 'user' value, to check whether the user has
logged in. Please, enlighten me.

Thanks in advance,
Vlad

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


Re: Getting and Setting Cookies

2006-07-19 Thread Vlad Dogaru

John J. Lee wrote:
> "Vlad Dogaru" <[EMAIL PROTECTED]> writes:
>
> > I am trying to use cookies and Python to create a simple login example.
> > But I am very disoriented at the existence of two cookie libraries,
> > namely Cookie and cookielib. I have seen examples of setting cookies
> [...]
>
> From the cookielib docs:
>
> http://docs.python.org/lib/module-cookielib.html
>
> | The cookielib module defines classes for automatic handling of HTTP
> | cookies. It is useful for accessing web sites that require small
> | pieces of data - cookies - to be set on the client machine by an HTTP
> | response from a web server, and then returned to the server in later
> | HTTP requests.
>
> (note the *accessing* there)
>
> [...]
>
> | Module Cookie: HTTP cookie classes, principally useful for server-side
> | code. The cookielib and Cookie modules do not depend on each
> | other.
>
>
> Module cookielib is for web client code (writing code that works like
> a browser).  Module Cookie is for server-side code (writing code to
> make a web site work).  You don't make it entirely clear which you're
> doing, but it sounds like the latter.

I am trying to write a simple login script. I understand (or rather I
think I understand) how to set a cookie with the Cookie module. My
problem is getting the cookies that are currently set. How can I do
that?

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


Re: Getting and Setting Cookies

2006-07-20 Thread Vlad Dogaru
John J. Lee wrote:
> "Vlad Dogaru" <[EMAIL PROTECTED]> writes:
> [...]
> > I am trying to write a simple login script. I understand (or rather I
> > think I understand) how to set a cookie with the Cookie module. My
> > problem is getting the cookies that are currently set. How can I do
> > that?
>
> You still haven't explicitly said that you're writing server-side
> code.  If you are:
>
> IIRC, you .load() it from the HTTP header value, then you use it as a
> mapping (though, oddly, that seems undocumented, except in the
> "Example" section of the docs).  A working CGI-based example (written
> in a rather retro style for ease of deployment):
>
> http://codespeak.net/svn/wwwsearch/ClientCookie/trunk/cookietest.cgi
>
>
> If you want to iterate over all cookies using module Cookie (that
> script does not), use .keys(), .values() or .items() on your
> SimpleCookie instance (it's also a little odd that instances of class
> SimpleCookie do not represent a single cookie, but a collection of
> cookies).

That's pretty much what I was trying to find out. Thanks for the
pointer.

Vlad

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


Session implementation for Python

2006-08-09 Thread Vlad Dogaru
Hello,

is there any PHP-like implementation for sessions in Python? I fear 
that writing my own would be seriously insecure, besides I could 
actually learn a lot by inspecting the code.

The reason I am asking is that I would like to implement simple scripts 
which require login with CGI (no mod_python or Django -- I want to 
learn CGI first).

Thanks in advance,
Vlad

-- 
There is nothing more dangerous than an idea when it is the only one 
you have.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Session implementation for Python

2006-08-10 Thread Vlad Dogaru

Bruno Desthuilliers wrote:
> Vlad Dogaru wrote:
> > Hello,
> >
> > is there any PHP-like implementation for sessions in Python? I fear
> > that writing my own would be seriously insecure, besides I could
> > actually learn a lot by inspecting the code.
> >
> > The reason I am asking is that I would like to implement simple scripts
> > which require login with CGI (no mod_python or Django -- I want to
> > learn CGI first).
>
> http://jonpy.sourceforge.net/

Exactly what I was looking for. Thanks a bunch.
Vlad

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


BaseHTTPServer - getting POST parameters

2006-11-14 Thread Vlad Dogaru
Hello,

After experimenting for a while, I am still not able to find where the
POST data is in the BaseHTTPRequestHandler class. I am trying to write
a very simple HTTP server for a project of mine and I need to get the
POST data. Certainly I am missing something, as it is a comon task.

Thanks in advance, 
Vlad

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


Using Python as a web scripting language

2006-06-22 Thread Vlad Dogaru
Hello everyone,I am learning Python and have heard it can be used similarly to PHP for web scripting. Because I find the latter not entirely to my liking, I would like to use Python. How should I configure my web server, what do I need, where should I start at, etc. I realise this sort of question pops up regularly, so just give me a starting point and I'll work my way from there (hopefully).
Thanks in advance,Vlad Dogaru--If I have somehow managed to break some sort of rules, either etiquette or English, by all means educate me.
-- 
http://mail.python.org/mailman/listinfo/python-list

Python CGI Scripting Documentation

2006-07-02 Thread Vlad Dogaru
Hello,

I would like to learn web scripting with Python (sure, everyone uses
PHP, but I don't like the syntax and Python is more general-purpose
and... well, I guess you people know the advantages better than me).
Where can I get a thorough introduction to both CGI and using Python
for CGI? That includes installing my own web server (at home, for
testing) and starting from scratch (by that I mean I have near null
experience with CGI).

I have tried looking through the source code of MoinMoin, but it's just
too advanced for me -- I simply don't know where to start. Right now,
I'll take any and all suggestions. However, please suggest books or
articles that are up-to-date on Python programming; I'd hate to see
that I'm studying obsolete texts or the like.

Thanks in advance,
Vlad

--
If I make any mistake, be it regarding English or Usenet, do point it
out to me. Thank you.

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


Python CGI Scripting Documentation

2006-07-02 Thread Vlad Dogaru
Hello,

I would like to learn web scripting with Python (sure, everyone uses
PHP, but I don't like the syntax and Python is more general-purpose
and... well, I guess you people know the advantages better than me).
Where can I get a thorough introduction to both CGI and using Python
for CGI? That includes installing my own web server (at home, for
testing) and starting from scratch (by that I mean I have near null
experience with CGI).

I have tried looking through the source code of MoinMoin, but it's just
too advanced for me -- I simply don't know where to start. Right now,
I'll take any and all suggestions. However, please suggest books or
articles that are up-to-date on Python programming; I'd hate to see
that I'm studying obsolete texts or the like.

Thanks in advance,
Vlad

--
If I make any mistake, be it regarding English or Usenet, do point it
out to me. Thank you.

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


Re: Python CGI Scripting Documentation

2006-07-03 Thread Vlad Dogaru
Alex Martelli wrote:


Wow, I'm new in the field, but even I know your name. It's truly
inspiring to be aswered to by you. Thank you, all of you, for your
suggestions. I will try to look into the matter using the starting
points you've given me, as well as read more about Django.

Thanks,
Vlad.

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


Control-C alternative in Windows

2006-12-17 Thread Vlad Dogaru
Hello,

I've written a simple, standalone wiki server in Python. It runs a
BaseHTTPServer's serve_forever() method until a KeyboardInterrupt is
caught, at which point it writes changes to a file and exits. This
works as expected in Linux. However, in Windows I cannot stop the
script with Control-C. I've only been able to stop it with Ctrl-Break,
which does not send KeyboardInterrupt. This means no saving to the file
and effectively a useless script. Any ideas as to how I might make this
work in Windows?

Thanks in advance,
Vlad

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


Re: Convert String to list of chars

2007-01-27 Thread Vlad Dogaru
On Jan 27, 9:18 am, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> On 2007-01-27, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > How can I convert a string to a char list?
> > for example
>
> > "hello" --> ['h','e','l','l','o']
>
> > I have been searching but I can't find my answers
> list("hello")

Wow, I've been using [c for c in 'hello'] for as long as I can remember
needing it. Thanks!

Vlad

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


Graphical Engine

2007-11-09 Thread Vlad Dogaru
Hi,

A few friends and myself were thinking of writing a graphical engine 
based on OpenGL. Does Python have the required speed for that task? Are 
there any examples out there of open-source engines which we can look 
at? A Google search yielded no interesting results, but then again I'm 
probably missing something.

Vlad
-- 
Lisp is to emacs what sex is to STDs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Graphical Engine

2007-11-09 Thread Vlad Dogaru
Karlo Lozovina wrote:
> Vlad Dogaru wrote:
> 
>> A few friends and myself were thinking of writing a graphical engine
>> based on OpenGL. Does Python have the required speed for that task? Are
>> there any examples out there of open-source engines which we can look
>> at? A Google search yielded no interesting results, but then again I'm
>> probably missing something.
> 
> http://www.ogre3d.org/wiki/index.php/PyOgre
> 

Ogre is nice at a glance, but we are looking to write our own engine. I 
realise it's deplicating effort, but we're looking to learn.

Vlad

-- 
Lisp is to emacs what sex is to STDs.
-- 
http://mail.python.org/mailman/listinfo/python-list