Thursday, April 8, 2010

comp.lang.python - 25 new messages in 12 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* Simple Cookie Script: Not recognising Cookie - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/dbd9af9a7a4cbd3f?hl=en
* pass object or use self.object? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/6f51302327b58aac?hl=en
* Translation docstrings with gettext - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/5e5a245d71348c9a?hl=en
* Python and Regular Expressions - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/888b3fe934e2c5e2?hl=en
* Performance of list vs. set equality operations - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/818d143c7e9550bc?hl=en
* Loading an imported module (C API) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/cb1123d4f13f5bc2?hl=en
* python grep - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/885c99df7e00afec?hl=en
* daemon.DaemonContext - 8 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/89daec0325dde0d2?hl=en
* Profiling: Interpreting tottime - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/31995629b8111cd0?hl=en
* get objects from image - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/58af59ec2669975d?hl=en
* ftp and python - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/6183a96d88f4420b?hl=en
* Regex driving me crazy... - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/6511effbbbfc5584?hl=en

==============================================================================
TOPIC: Simple Cookie Script: Not recognising Cookie
http://groups.google.com/group/comp.lang.python/t/dbd9af9a7a4cbd3f?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 12:34 am
From: Pierre Quentel


On 8 avr, 07:03, Jimbo <nill...@yahoo.com> wrote:
> Hi I have a simple Python program that assigns a cookie to a web user
> when they open the script the 1st time(in an internet browser). If
> they open the script a second time the script should display the line
> " You have been here 2 times." , if they open the script agai it
> should show on the webpage "You have been here 3 times" and so on.
>
> But for some reason, my program is not assigning or recognising an
> assigned cookie & outputing the line "You have been here x times". I
> have gone over my code for like 2 hours now I cant figure out what is
> going wrong??
>
> Can you help me figure out whats wrong? I have my own cgi server that
> just runs on my machine so its not that its the code to recognise/
> assign a cookie
>
> [code]#!/usr/bin/env python
>
> import Cookie
> import cgi
> import os
>
> HTML_template = """
> <html>
>   <head>
>
>   </head>
>   <body>
>     <p> %s </p>
>   </body>
> </html>
> """
>
> def main():
>
>     # Web Client is new to the site so we need to assign a cookie to
> them
>     cookie = Cookie.SimpleCookie()
>     cookie['SESSIONID'] = '1'
>     code = "No cookie exists. Welcome, this is your first visit."
>
>     if 'HTTP_COOKIE' in os.environ:
>         cookie = Cookie.SimpleCookie(os.environ['HTTP_COOKIE'])
>         # If Web client has been here before
>         if cookie.has_key('SESSIONID'):
>             cookie['SESSIONID'].value = int(cookie['SESSIONID'].value)
> +1
>             code = "You have been here %s times." %
> cookie['SESSIONID'].value
>         else:
>             cookie = Cookie.SimpleCookie()
>             cookie['SESSIONID'] = '1'
>             code = "I Have a cookie, but SESSIONID does not exist"
>
>     print "Content-Type: text/html\n"
>     print HTML_template % code
>
> if __name__ == "__main__":
>     main()
> [/code]

Hi,

You are confusing the cookie sent by the browser to the server - you
get it by os.environ['HTTP_COOKIE'] - and the one sent by the server
to the browser : it it sent in the response headers

You can change method main() like this :

def main():

# defaut cookie to send if web Client is new to the site
set_cookie = Cookie.SimpleCookie()
set_cookie['SESSIONID'] = 1
code = "No cookie exists. Welcome, this is your first visit."

if 'HTTP_COOKIE' in os.environ:
cookie = Cookie.SimpleCookie(os.environ['HTTP_COOKIE'])
if cookie.has_key('SESSIONID'):
# web client has been here before : increment number of
visits
set_cookie['SESSIONID'] = int(cookie['SESSIONID'].value)
+1
code = "You have been here %s times." %
cookie['SESSIONID'].value
else:
code = "I Have a cookie, but SESSIONID does not exist"

print "Content-Type: text/html"
print set_cookie.output() # send cookie to web client
print
print HTML_template % code

- Pierre

==============================================================================
TOPIC: pass object or use self.object?
http://groups.google.com/group/comp.lang.python/t/6f51302327b58aac?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 1:20 am
From: Bruno Desthuilliers


Lie Ryan a écrit :
> On 04/07/10 18:34, Bruno Desthuilliers wrote:
>> Lie Ryan a écrit :
>> (snip)
>>
>>> Since in function in python is a first-class object, you can instead do
>>> something like:
>>>
>>> def process(document):
>>> # note: document should encapsulate its own logic
>>> document.do_one_thing()
>> Obvious case of encapsulation abuse here. Should a file object
>> encapsulate all the csv parsing logic ? (and the html parsing, xml
>> parsing, image manipulation etc...) ? Should a "model" object
>> encapsulate the presentation logic ? I could go on for hours here...
>
> Yes, but no; you're taking it out of context. Is {csv|html|xml|image}
> parsing logic a document's logic? Is presentation a document's logic? If
> they're not, then they do not belong in document.

Is len() a list logic ? If yes, it should belong to list !-)

There are two points here : the first is that we (that is, at least, you
and me) just don't know enough about the OP's project to tell whether
something should belong to the document or not. period. The second point
is that objects don't live in a splendid isolation, and it's perfectly
ok to have code outside an object's method working on the object.

wrt/ these two points, your "document should encapsulate its own logic"
note seems a bit dogmatic (and not necessarily right) to me - hence my
answer.


==============================================================================
TOPIC: Translation docstrings with gettext
http://groups.google.com/group/comp.lang.python/t/5e5a245d71348c9a?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Apr 8 2010 3:08 am
From: sapient


Thank you for your help.

Solution with decorators looks well, will try it in near future.
I will report here if I solve this problem.


== 2 of 2 ==
Date: Thurs, Apr 8 2010 4:26 am
From: Peter Otten <__peter__@web.de>


sapient wrote:

> I found several discussions where this question was asked, but was not
> answered.
>
> Now I am creating Python-API for my application, and want create it
> with translation support, including documentation strings for modules,
> classes, methods etc.
>
> It is simple to translate special-marked strings with gettext, but it
> is problem with docstrings: if I mark them for translation like
> _("""Some documentation string""") then it is not recognized as
> docstring. If I omit _() markup, then string is not translated.
>
> Script pygettext.py has key --docstrings that forces extraction
> docstrings from module, so I suppose, that it must be way to use thier
> translations.

> So, question is: How to translate docstrings in my example?

You could leave the docstrings alone and monkey-patch inspect.getdoc() to do
the translation when help() is invoked:

#! /usr/bin/python2.6
# -*- coding: utf-8 -*-
import os, gettext

localedir = os.path.join( os.path.dirname(__file__), "locale/" )

t = gettext.translation( 'testmodule', localedir=localedir,
languages=['ru'], codeset="utf-8" )
t.install()

import testmodule

import inspect
def getdoc(object):
try:
doc = object.__doc__
except AttributeError:
return None
if not isinstance(doc, basestring):
return None

return inspect.cleandoc(_(doc))

inspect.getdoc = getdoc


help( testmodule )
testmodule.TestClass().testClassMethod()

Peter

==============================================================================
TOPIC: Python and Regular Expressions
http://groups.google.com/group/comp.lang.python/t/888b3fe934e2c5e2?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Apr 8 2010 3:13 am
From: Nobody


On Wed, 07 Apr 2010 18:25:36 -0700, Patrick Maupin wrote:

>> Regular expressions != Parsers
>
> True, but lots of parsers *use* regular expressions in their
> tokenizers. In fact, if you have a pure Python parser, you can often
> get huge performance gains by rearranging your code slightly so that
> you can use regular expressions in your tokenizer, because that
> effectively gives you access to a fast, specialized C library that is
> built into practically every Python interpreter on the planet.

Unfortunately, a typical regexp library (including Python's) doesn't allow
you to match against a set of regexps, returning the index of which one
matched. Which is what you really want for a tokeniser.

>> Every time someone tries to parse nested structures using regular
>> expressions, Jamie Zawinski kills a puppy.
>
> And yet, if you are parsing stuff in Python, and your parser doesn't
> use some specialized C code for tokenization (which will probably be
> regular expressions unless you are using mxtexttools or some other
> specialized C tokenizer code), your nested structure parser will be
> dog slow.

The point is that you *cannot* match arbitrarily-nested expressions using
regexps. You could, in theory, write a regexp which will match any valid
syntax up to N levels of nesting, for any finite N. But in practice, the
regexp is going to look horrible (and is probably going to be quite
inefficient if the regexp library uses backtracking rather than a DFA).

Even tokenising with Python's regexp interface is inefficient if the
number of token types is large, as you have to test against each regexp
sequentially.

Ultimately, if you want an efficient parser, you need something with a C
component, e.g. Plex.

== 2 of 3 ==
Date: Thurs, Apr 8 2010 4:56 am
From: Richard Lamboj

At the moment i have less time, so its painful to read about parsing, but it
is quite interessting.

I have taken a look at the different Parsing Modules and i'am reading the
Source Code to understand how they Work. Since Yesterday i'am writing on my
own small Engine - Just for Fun and understanding how i can get what i need.

It seems that this is hard to code, becouse the logic is complex and sometimes
confussing. Its not easy to find a "perfect" solution.

If someone knows good links to this thema, or can explain how parsers
should/could work, please post it, or explain it.

Thanks for the Informations and the Help!

Kind Regards

Richi


== 3 of 3 ==
Date: Thurs, Apr 8 2010 5:02 am
From: "Charles"

"Nobody" <nobody@nowhere.com> wrote in message
news:pan.2010.04.08.10.12.59.594000@nowhere.com...
> On Wed, 07 Apr 2010 18:25:36 -0700, Patrick Maupin wrote:
>
>>> Regular expressions != Parsers
>>
>> True, but lots of parsers *use* regular expressions in their
>> tokenizers. In fact, if you have a pure Python parser, you can often
>> get huge performance gains by rearranging your code slightly so that
>> you can use regular expressions in your tokenizer, because that
>> effectively gives you access to a fast, specialized C library that is
>> built into practically every Python interpreter on the planet.
>
> Unfortunately, a typical regexp library (including Python's) doesn't allow
> you to match against a set of regexps, returning the index of which one
> matched. Which is what you really want for a tokeniser.
>
[snip]

Really !,
I am only a python newbie, but what about ...

import re
rr = [
( "id", '([a-zA-Z][a-zA-Z0-9]*)' ),
( "int", '([+-]?[0-9]+)' ),
( "float", '([+-]?[0-9]+\.[0-9]*)' ),
( "float", '([+-]?[0-9]+\.[0-9]*[eE][+-]?[0-9]+)' )
]
tlist = [ t[0] for t in rr ]
pat = '^ *(' + '|'.join([ t[1] for t in rr ]) + ') *$'
p = re.compile(pat)

ss = [ ' annc', '1234', 'abcd', ' 234sz ', '-1.24e3', '5.' ]
for s in ss:
m = p.match(s)
if m:
ix = [ i-2 for i in range(2,6) if m.group(i) ]
print "'"+s+"' matches and has type", tlist[ix[0]]
else:
print "'"+s+"' does not match"

output:
' annc' matches and has type id
'1234' matches and has type int
'abcd' matches and has type id
' 234sz ' does not match
'-1.24e3' matches and has type float
'5.' matches and has type float

seems to me to match a (small) set of regular expressions and
indirectly return the index of the matched expression, without
doing a sequential loop over the regular expressions.

Of course there is a loop over the reults of the match to determine
which sub-expression matched, but a good regexp library (which
I presume Python has) should match the sub-expressions without
looping over them. The techniques to do this were well known in
the 1970's when the first versons of lex were written.

Not that I would recommend tricks like this. The regular
expression would quickly get out of hand for any non-trivial
list of regular expresssions to match.

Charles


==============================================================================
TOPIC: Performance of list vs. set equality operations
http://groups.google.com/group/comp.lang.python/t/818d143c7e9550bc?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 3:26 am
From: Terry Reedy


On 4/8/2010 3:07 AM, Steven D'Aprano wrote:
> On Wed, 07 Apr 2010 20:14:23 -0700, Raymond Hettinger wrote:
>
>> [Raymond Hettinger]
>>>> If the two collections have unequal sizes, then both ways immediately
>>>> return unequal.
>>
>> [Steven D'Aprano]
>>> Perhaps I'm misinterpreting what you are saying, but I can't confirm
>>> that behaviour, at least not for subclasses of list:
>>
>> For doubters, see list_richcompare() in
>> http://svn.python.org/view/python/trunk/Objects/listobject.c?
> revision=78522&view=markup
>
> So what happens in my example with a subclass that (falsely) reports a
> different length even when the lists are the same?
>
> I can guess that perhaps Py_SIZE does not call the subclass __len__
> method, and therefore is not fooled by it lying. Is that the case?

Adding a print call within __len__ should determine that.


==============================================================================
TOPIC: Loading an imported module (C API)
http://groups.google.com/group/comp.lang.python/t/cb1123d4f13f5bc2?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 3:26 am
From: Christian Heimes


On 06.04.2010 15:58, booncw wrote:
> Hi,
>
> I am running a simulation where the python module has already been
> imported. Could you please tell me how to load it?
>
> I've been doing this (importing everytime), but it is too slow:
> pModule = PyImport_Import(pName);

You can cache the module object in a static variable:

static PyObject *module = NULL;
if (module == NULL && (module = PyImport_ImportModuleNoBlock("module"))
== NULL) {
return NULL;
}
}

Christian


==============================================================================
TOPIC: python grep
http://groups.google.com/group/comp.lang.python/t/885c99df7e00afec?hl=en
==============================================================================

== 1 of 3 ==
Date: Thurs, Apr 8 2010 4:21 am
From: Mag Gam


I am in the process of reading a zipped file which is about 6gb.

I would like to know if there is a command similar to grep in python
because I would like to emulate, -A -B option of GNU grep.

Lets say I have this,

083828.441,AA
093828.441,AA
094028.441,AA
094058.441,CC
094828.441,AA
103828.441,AA
123828.441,AA


if I do grep -A2 -B2 "CC"

I get 2 lines before and 2 lines after "C"

Is there an easy way to do this in python?

TIA


== 2 of 3 ==
Date: Thurs, Apr 8 2010 4:31 am
From: Stefan Behnel


Mag Gam, 08.04.2010 13:21:
> I am in the process of reading a zipped file which is about 6gb.
>
> I would like to know if there is a command similar to grep in python
> because I would like to emulate, -A -B option of GNU grep.
>
> Lets say I have this,
>
> 083828.441,AA
> 093828.441,AA
> 094028.441,AA
> 094058.441,CC
> 094828.441,AA
> 103828.441,AA
> 123828.441,AA
>
>
> if I do grep -A2 -B2 "CC"
>
> I get 2 lines before and 2 lines after "C"
>
> Is there an easy way to do this in python?

Sure, just use a sliding window.

However, for a 6BG file, you won't really like the performance. It's
basically impossible to beat the speed of (f)grep.

I'd use the subprocess module to run zfgrep over the file and parse the
output in Python.

Stefan

== 3 of 3 ==
Date: Thurs, Apr 8 2010 5:21 am
From: Mag Gam


Oh, thats nice to know!

But I use the CSV module with gzip module. Is it still possible to do
it with the subprocess?

On Thu, Apr 8, 2010 at 7:31 AM, Stefan Behnel <stefan_ml@behnel.de> wrote:
> Mag Gam, 08.04.2010 13:21:
>>
>> I am in the process of reading a zipped file which is about 6gb.
>>
>> I would like to know if there is a command similar to grep in python
>> because I would like to emulate, -A -B option of GNU grep.
>>
>> Lets say I have this,
>>
>> 083828.441,AA
>> 093828.441,AA
>> 094028.441,AA
>> 094058.441,CC
>> 094828.441,AA
>> 103828.441,AA
>> 123828.441,AA
>>
>>
>> if I do grep -A2 -B2 "CC"
>>
>> I get 2 lines before and 2 lines after "C"
>>
>> Is there an easy way to do this in python?
>
> Sure, just use a sliding window.
>
> However, for a 6BG file, you won't really like the performance. It's
> basically impossible to beat the speed of (f)grep.
>
> I'd use the subprocess module to run zfgrep over the file and parse the
> output in Python.
>
> Stefan
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

==============================================================================
TOPIC: daemon.DaemonContext
http://groups.google.com/group/comp.lang.python/t/89daec0325dde0d2?hl=en
==============================================================================

== 1 of 8 ==
Date: Thurs, Apr 8 2010 5:14 am
From: Rebelo


i get : IOError: [Errno 9] Bad file descriptor
when i have logging and using daemon.DaemonContext()
i tried passing :
fh = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME, 'midnight',
encoding='utf-8')
with :
context = daemon.DaemonContext()
context.files_preserve=[fh]

but no good
what am i doing wrong?


== 2 of 8 ==
Date: Thurs, Apr 8 2010 5:28 am
From: Rebelo


when i use this :
context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout,
files_preserve=[fh], signal_map = {signal.SIGTERM:
'terminate',signal.SIGHUP: 'terminate'})

i don't get error but i still can't write to log file
what am i doing wrong?


== 3 of 8 ==
Date: Thurs, Apr 8 2010 5:45 am
From: Vinay Sajip


On Apr 8, 1:28 pm, Rebelo <puntabl...@gmail.com> wrote:
> when i use this :
>  context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout,
> files_preserve=[fh], signal_map = {signal.SIGTERM:
> 'terminate',signal.SIGHUP: 'terminate'})
>
> i don't get error but i still can't write to log file
> what am i doing wrong?

Not sure, offhand.

Change to a script which just writes to the file (rather than going
via logging) - does that work? What platform are you on, what version
etc?

It's unlikely to be a logging-related problem: more likely it's to do
with file descriptors.

Regards,

Vinay Sajip


== 4 of 8 ==
Date: Thurs, Apr 8 2010 5:50 am
From: Vinay Sajip


On Apr 8, 1:28 pm, Rebelo <puntabl...@gmail.com> wrote:
> when i use this :
>  context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout,
> files_preserve=[fh], signal_map = {signal.SIGTERM:
> 'terminate',signal.SIGHUP: 'terminate'})
>
> i don't get error but i still can't write to log file
> what am i doing wrong?

My guess is - files_preserve needs to be passed a file handle and not
a logging handler.

Regards,

Vinay Sajip


== 5 of 8 ==
Date: Thurs, Apr 8 2010 5:58 am
From: Rebelo


Vinay Sajip wrote:
> On Apr 8, 1:28 pm, Rebelo <puntabl...@gmail.com> wrote:
>> when i use this :
>> context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout,
>> files_preserve=[fh], signal_map = {signal.SIGTERM:
>> 'terminate',signal.SIGHUP: 'terminate'})
>>
>> i don't get error but i still can't write to log file
>> what am i doing wrong?
>
> My guess is - files_preserve needs to be passed a file handle and not
> a logging handler.
>
> Regards,
>
> Vinay Sajip

thnx for help.
writing to a file works, but i need logging.
do you know where can i find good documnetation for python-daemon?


== 6 of 8 ==
Date: Thurs, Apr 8 2010 6:29 am
From: Vinay Sajip


On Apr 8, 1:58 pm, Rebelo <puntabl...@gmail.com> wrote:
> Vinay Sajip wrote:
> > On Apr 8, 1:28 pm, Rebelo <puntabl...@gmail.com> wrote:
> >> when i use this :
> >>  context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout,
> >> files_preserve=[fh], signal_map = {signal.SIGTERM:
> >> 'terminate',signal.SIGHUP: 'terminate'})
>
> >> i don't get error but i still can't write to log file
> >> what am i doing wrong?
>
> > My guess is - files_preserve needs to be passed a file handle and not
> > alogginghandler.
>
> > Regards,
>
> > Vinay Sajip
>
> thnx for help.
> writing to a file works, but i needlogging.
> do you know where can i find good documnetation for python-daemon?

No,

but see this post:

http://groups.google.com/group/comp.lang.python/msg/851ce78e53812ade

It may lead you to more information. The thread shows that Sean
DiZazzo got logging working with the package.

I think you just have to pass the file object used by the handler
(fh.stream) in the files_preserve array.

Regards,

Vinay Sajip


== 7 of 8 ==
Date: Thurs, Apr 8 2010 6:26 am
From: Rebelo


i found a crude workaround:
i wrote a function in which i start logging after deamon starts


== 8 of 8 ==
Date: Thurs, Apr 8 2010 6:46 am
From: Rebelo


Vinay Sajip wrote:
> On Apr 8, 1:58 pm, Rebelo <puntabl...@gmail.com> wrote:
>> Vinay Sajip wrote:
>>> On Apr 8, 1:28 pm, Rebelo <puntabl...@gmail.com> wrote:
>>>> when i use this :
>>>> context = daemon.DaemonContext(stdin=sys.stdin, stdout=sys.stdout,
>>>> files_preserve=[fh], signal_map = {signal.SIGTERM:
>>>> 'terminate',signal.SIGHUP: 'terminate'})
>>>> i don't get error but i still can't write to log file
>>>> what am i doing wrong?
>>> My guess is - files_preserve needs to be passed a file handle and not
>>> alogginghandler.
>>> Regards,
>>> Vinay Sajip
>> thnx for help.
>> writing to a file works, but i needlogging.
>> do you know where can i find good documnetation for python-daemon?
>
> No,
>
> but see this post:
>
> http://groups.google.com/group/comp.lang.python/msg/851ce78e53812ade
>
> It may lead you to more information. The thread shows that Sean
> DiZazzo got logging working with the package.
>
> I think you just have to pass the file object used by the handler
> (fh.stream) in the files_preserve array.
>
> Regards,
>
> Vinay Sajip
thank you.

==============================================================================
TOPIC: Profiling: Interpreting tottime
http://groups.google.com/group/comp.lang.python/t/31995629b8111cd0?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 6:00 am
From: Nikolaus Rath


"Gabriel Genellina" <gagsl-py2@yahoo.com.ar> writes:
> En Wed, 07 Apr 2010 18:44:39 -0300, Nikolaus Rath <Nikolaus@rath.org>
> escribió:
>
>> def check_s3_refcounts():
>> """Check s3 object reference counts"""
>>
>> global found_errors
>> log.info('Checking S3 object reference counts...')
>>
>> for (key, refcount) in conn.query("SELECT id, refcount FROM
>> s3_objects"):
>>
>> refcount2 = conn.get_val("SELECT COUNT(inode) FROM blocks
>> WHERE s3key=?",
>> (key,))
>> if refcount != refcount2:
>> log_error("S3 object %s has invalid refcount, setting
>> from %d to %d",
>> key, refcount, refcount2)
>> found_errors = True
>> if refcount2 != 0:
>> conn.execute("UPDATE s3_objects SET refcount=? WHERE
>> id=?",
>> (refcount2, key))
>> else:
>> # Orphaned object will be picked up by check_keylist
>> conn.execute('DELETE FROM s3_objects WHERE id=?', (key,))
>>
>> When I ran cProfile.Profile().runcall() on it, I got the following
>> result:
>>
>> ncalls tottime percall cumtime percall filename:lineno(function)
>> 1 7639.962 7639.962 7640.269 7640.269
>> fsck.py:270(check_s3_refcounts)
>>
>> So according to the profiler, the entire 7639 seconds where spent
>> executing the function itself.
>>
>> How is this possible? I really don't see how the above function can
>> consume any CPU time without spending it in one of the called
>> sub-functions.
>
> Is the conn object implemented as a C extension?

No, it's pure Python.

> The profiler does not
> detect calls to C functions, I think.

Hmm. Isn't this a C function?

26 2.317 0.089 2.317 0.089 {method 'execute' of 'apsw.Cursor' objects}

> You may be interested in this package by Robert Kern:
> http://pypi.python.org/pypi/line_profiler
> "Line-by-line profiler.
> line_profiler will profile the time individual lines of code take to
> execute."

That looks interesting nevertheless, thanks!


-Nikolaus

--
»Time flies like an arrow, fruit flies like a Banana.«

PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C

==============================================================================
TOPIC: get objects from image
http://groups.google.com/group/comp.lang.python/t/58af59ec2669975d?hl=en
==============================================================================

== 1 of 2 ==
Date: Thurs, Apr 8 2010 6:17 am
From: Jannis Syntychakis


Hallo Everybody,

Maybe you can help me with this:

i have a picture. The picture is black, with some white objects.

Is there any way i can detect the automatically? Something like:
if there white objects bigger than 3 pixels draw a box there or get
their
position!

getting their position is more important for me.

One more question:"

can i let the user tell the software there the white object is? like a
square
this moves with the mouse and the user will be able to click on the
white objects.

Maybe somebosy could help? with an example maybe?

Thank you very much in advance!!!!

Ioannis


== 2 of 2 ==
Date: Thurs, Apr 8 2010 6:57 am
From: Chris Hulan


On Apr 8, 9:17 am, Jannis Syntychakis <ioan...@live.nl> wrote:
> Hallo Everybody,
>
> Maybe you can help me with this:
>
> i have a picture. The picture is black, with some white objects.
>
> Is there any way i can detect the automatically? Something like:
> if there white objects bigger than 3 pixels draw a box there or get
> their
> position!
>
> getting their position is more important for me.
>
> One more question:"
>
> can i let the user tell the software there the white object is? like a
> square
> this moves with the mouse and the user will be able to click on the
> white objects.
>
> Maybe somebosy could help? with an example maybe?
>
> Thank you very much in advance!!!!
>
> Ioannis

Sounds like a job for an image lib, like say Camellia (http://
camellia.sourceforge.net/index.html)
Their info Mentions a Ruby interface, so a python interface should be
fairly easy

cheers

==============================================================================
TOPIC: ftp and python
http://groups.google.com/group/comp.lang.python/t/6183a96d88f4420b?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 6:49 am
From: Tim Chase


Simon wrote:
> You could user FTP.voidcmd()
> E.G.
> ftp.voidcmd('RNFT filename.txt')ftp.voidcmd('RNTO newdir/filename.txt')
>>From the rfc:
>
> RENAME FROM (RNFR)
>
> This command specifies the old pathname of the file which is
> to be renamed. This command must be immediately followed by
> a "rename to" command specifying the new file pathname.
>
> RENAME TO (RNTO)
>
> This command specifies the new pathname of the file
> specified in the immediately preceding "rename from"
> command. Together the two commands cause a file to be
> renamed.

As mentioned in my original reply, that should be what
ftplib.FTP.rename() does under the covers[1]. However, the OP
was asking about copying a file, not renaming a file.

John mentioned the poorly-supported "server-to-server copy", but
from my understanding, I think that still slurps locally and then
pushes it back up elsewhere.

-tkc

[1]
taken from ftplib.py:

def rename(self, fromname, toname):
'''Rename a file.'''
resp = self.sendcmd('RNFR ' + fromname)
if resp[0] != '3':
raise error_reply, resp
return self.voidcmd('RNTO ' + toname)

==============================================================================
TOPIC: Regex driving me crazy...
http://groups.google.com/group/comp.lang.python/t/6511effbbbfc5584?hl=en
==============================================================================

== 1 of 1 ==
Date: Thurs, Apr 8 2010 6:49 am
From: J


On Thu, Apr 8, 2010 at 01:16, Kushal Kumaran
<kushal.kumaran+python@gmail.com> wrote:
>
> Is there any particular reason you absolutely must extract the status
> message?  If you already have a list of possible status messages, you
> could just test which one of those is present in the line...

Yes and no...

Mostly, it's for the future. Right now, this particular test script
(and I mean test script in the sense it's part of a testing framework,
not in the sense that I'm being tested on it ;-) ) is fully
automated.

Once the self-test on the HDD is complete, the script will return
either a 0 or 1 for PASS or FAIL respectively.

However, in the future, it may need to be changed to or also handled
manually instead of automatically. And if we end up wanting it to be
automatic, then having that phrase would be important for logging or
problem determination. We don't so much care about the rest of the
string I want to parse as the data it gives is mostly meaningless, but
having it pull things like:

Completed: Electrical error

or

Completed: Bad Sectors Found

could as useful as

Completed without error

or

Aborted by user

So that's why I was focusing on just extracting that phrase from the
output. I could just pull the entire string and do a search for the
phrases in question, and that's probably the simplest thing to do:

re.search("Search Phrase",outputString)

but I do have a tendency to overthink things some times and besides
which, having just that phrase for the logs, or for use in a future
change would be cool, and this way, I've already got that much of it
done for later on.


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate