Re: QWebView: notify python when I clicked on a certain web eleemnt

2011-02-21 Thread Дамјан Георгиевски
 I have a web page (existing page, can't modify it) and I would like
 to browse it in a QtWebview. (This is already working)
 
 Now I Wonder how I could achieve following behaviour:
 
 When I click on a certain element e.g. span id=clickme/a
 I would like to notify my python script.
 
 What is important:
 I don't want to change anything else in the web pages behaviour (This
 means if clicking on this element will call some java script
 functions, load a pag, then this should still happen.


You can inject JavaScript using the method 
QWebElement::evaluateJavaScript()

Also you can insert a Python object in the JS runtime with 
QWebFrame::addToJavaScriptWindowObject()
see here:
http://pysnippet.blogspot.com/2010/01/calling-python-from-javascript-in-
pyqts.html


so make a Python object with some methods you'd wish to call, then 
evaluate some small JS that will bind the click event on your element to 
the method of the Python object.


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Teaching a pig to sing wastes your time  annoys the pig.

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


Re: ANN: PyQt v4.8.1 Released

2010-11-07 Thread Дамјан Георгиевски
 Given the context, PyQt is available under the GPL and a commercial
 license, the commercial license Phil is talking about is not the
 GPL.
 
 Which is a wrong interpretation of “commercial”.

But he is not interpreting either “commercial” or GPL.

What he says is: here's the code for free (gratis, no price) under the 
GPL, but if you don't like it, I also offer it commercially (under an 
undisclosed license, maybe a custom one as required by the client).

He is NOT offering the GPL version commercially, even if that's allowed 
by the GPL. 

For ex. You are free to do it, it's that he is not doing it (or just not 
advertising it - I'm sure he wouldn't mind someone paying for the GPL 
version either).


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it. - Brian W. Kernighan

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


Re: ANN: PyQt v4.8.1 Released

2010-11-02 Thread Дамјан Георгиевски
 PyQt is available under the GPL and a commercial license.
 
 Surely you mean “proprietary” rather than “commercial”. There is
 nothing about the GPL that prevents “commercial” use.

I think he means a license that *he* sells comercially :)



-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Religion ends and philosophy begins, 
just as alchemy ends and chemistry begins 
and astrology ends, and astronomy begins.

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


Re: Py3: Import relative path module

2010-10-31 Thread Дамјан Георгиевски


 I am loathe to duplicate programming in files that should just load a
 copy from a module. I tried all kinds of tricks to import a module
 from one level up. What's the secret?
 
 It works if I say:
 
 from Data import DumpHT
 
 but ONLY if the search path in sys.path. I want a relative path import
 independent from  sys.path.
 
 How to? This is Python 3.1.1

from .. import Data.DumpHT as DumpHT


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Hi! I'm a .signature virus! copy me into your .signature file to help me 
spread!

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


Re: Print to an IPP printer (pkipplib?)

2010-10-19 Thread Дамјан Георгиевски
 I've found the module pkipplib which seems to work well for things
 like
 interrogating an IPP (CUPS) server.  But is there a way to send a
 print job to an IPP print queue? [and no, the local system knows
 nothing about
 the print architecture so popenlp is not an option].  I just want
 to send the data from a file handle to a remote IPP queue as a print
 job.

Isn't IPP based on HTTP?
I think you just need a HTTP POST or PUT to send the print job

-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it. - Brian W. Kernighan

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


Re: Pydev 1.6.0 Released

2010-07-21 Thread Дамјан Георгиевски
 Pydev 1.6.0 has been released
 
 Details on Pydev: http://pydev.org
 Details on its development: http://pydev.blogspot.com

The supposed feature to start a console in which the contents of the 
current editor window are automatically execed /available still 
doesn't work for me.

I'm talking about this:
http://www.pydev.org/manual_adv_interactive_console.html

Pressing Ctrl-Alt-Enter, a interactive console opens but my class 
defined in the editor window is not available.




-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Perfection is achieved, not when there is nothing more to add, but
when there is nothing left to take away. - Antoine de Saint-Exupéry

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


Re: simples setup for an wsgi https server in python

2010-07-13 Thread Дамјан Георгиевски
 It seems, that wsgiref.simple_server.make_server can only create an
 http server.
 
 What I wondered would be how to easiest create an https server, that
 supports wsgi modules

PythonPaste has a WSGI server that supports https
http://pythonpaste.org/modules/httpserver.html#module-paste.httpserver

Werkzeug too
http://werkzeug.pocoo.org/documentation/0.6.2/serving.html#ssl


I'd strongly suggest you to have both of those libraries installed, they 
have a lot of WSGI goodies :)

-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Scarlett Johansson: You always see the glass half-empty.
Woody Allen: No. I see the glass half-full... but of poison.

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


Re: Lua is faster than Fortran???

2010-07-12 Thread Дамјан Георгиевски

On the positive side, Lua supports tail call optimization and coroutines 
are built in by default.


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Education is one of the prices of freedom that some are unwilling to 
pay. 

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


Re: A question about the posibility of raise-yield in Python

2010-07-06 Thread Дамјан Георгиевски
  I'm writing this as a complete newbie (on the issue), so don't be
  surprised if it's the stupidest idea ever.

  I was wondering if there was ever a discusision in the python
  community on a 'raise-yield' kind-of combined expression. I'd like
  to know if it was proposed/rejected/discussed/not-decided yet??

 Recently (ok, several hours ago) I've come up to Greenlets [1] and it
 seems they implement exactly what I was asking for, in a C
 extension!!

 It's too bad that Python doesn't support this by default and many
 libraries won't make use of it by default. Gevent [2] for example,
 has to monkey-patch Python's socket, time.sleep and other modules so
 that things like urllib work with it.

 I'll continue to read now.
 
 Ah, if I had seen your original post I probably could have pointed you
 to some good reading right away.  What you've described is called a
 continuation, and is natively supported by some languages (like
 Scheme).  It's usually not done with exceptions, though.  In Scheme
 it's a special form that looks like an ordinary function call, but you
 can return from the call any number of times.

I thought they were called coroutines?

Anyway, here's the Lua implementation of coroutines. It's basically a 
yield but it will return back several frames.

http://lua-users.org/wiki/CoroutinesTutorial


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Today we create the legacy of tomorrow.

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


Re: A question about the posibility of raise-yield in Python

2010-06-30 Thread Дамјан Георгиевски


 I'm writing this as a complete newbie (on the issue), so don't be
 surprised if it's the stupidest idea ever.
 
 I was wondering if there was ever a discusision in the python
 community on a 'raise-yield' kind-of combined expression. I'd like to
 know if it was proposed/rejected/discussed/not-decided yet??


Recently (ok, several hours ago) I've come up to Greenlets [1] and it 
seems they implement exactly what I was asking for, in a C extension!!

It's too bad that Python doesn't support this by default and many 
libraries won't make use of it by default. Gevent [2] for example, has 
to monkey-patch Python's socket, time.sleep and other modules so that 
things like urllib work with it.

I'll continue to read now.


[1] http://codespeak.net/py/0.9.2/greenlet.html
[2] http://www.gevent.org/




 A 'raise-yield' expression would break the flow of a program just like
 an exception, going up the call stack until it would be handled, but
 also like yield it would be possible to continue the flow of the
 program from where it was raise-yield-ed.
 
 This would be usefull for example in event based frameworks, they
 could just replace socket.* and similar, normally blocking,
 modules/functions with it's own 'raise-yield' enabled ones.
 
 Then you could just take any normal imperative code that calls normal
 library networking code (say smtplib, poplib or httplib) nad run it in
 a event framework.
 The normal xxxlib calls at some point would get to the now
 non-blocking, event based socket write/read, break the flow back to
 the event framework, and when it finishes the event framework would
 continue the normal flow of the program past the raise-yield.


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Please remember 43% of statistics are made on the spot.

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


Re: Readability (html purifier) in Python

2010-06-16 Thread Дамјан Георгиевски
 http://lab.arc90.com/experiments/readability/

 Readability is a javascript bookmarklet that makes reading on the
 Web more enjoyable by removing the clutter around what you're
 reading.

 Does anyone know of something similar in Python?
 
 Well, that sounds like a browser tool.

yes, it's a bookmarklet, a tiny javascript code that when clicked runs 
on the current document in the browser.

 Could you be a bit more specific about what kind of similar 
 functionality you would expect from a similar Python tool? 
 How would you tell it what you're reading, for example?

I'm not sure I understand your question corectly, but anyway. 

What I need is a package that given a random html document (a page from 
any random website) would extract the meaningful content, and filter the 
junk (advertisments, non-content elements, any other UI etc.)


Readability seems to do some herustictical manipulation of the DOM, but 
I'm not that good at reading/understanding it's source-code. Of course 
it can't be 100% correct, but it's good enough in many cases.

http://code.google.com/p/arc90labs-
readability/source/browse/trunk/js/readability.js



-- 
дамјан ((( http://damjan.softver.org.mk/ )))

war is peace
freedom is slavery
restrictions are enablement

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


Readability (html purifier) in Python

2010-06-15 Thread Дамјан Георгиевски
http://lab.arc90.com/experiments/readability/ 

Readability is a javascript bookmarklet that makes reading on the Web 
more enjoyable by removing the clutter around what you're reading.


Does anyone know of something similar in Python?




-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it. - Brian W. Kernighan

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


Re: python glibc crypt() function

2010-04-20 Thread Дамјан Георгиевски
 Hello i have to do this :
 glibc crypt() function, using salt $1$abcdefgh$
 
 cryptPw = crypt(plainPw, $1$abcdefgh$)
 
 I can do it in python, with package i need?
 Thanks
 
 import ctypes
 lib = ctypes.CDLL(libcrypt.so.1)
 crypt = lib.crypt
 crypt.restype = ctypes.c_char_p
 crypt(password, $1$abcdefgh$)
 '$1$abcdefgh$G//4keteveJp0qb8z2DxG/'
 
 Is that what it's supposed to return?

seeing this I thought about using ctypes for AES (or similar) crypto 
function. A bit of google searching I've come to 
http://code.google.com/p/ctypescrypto/

just FYI


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

... knowledge is exactly like power - something 
to be distributed as widely as humanly possible,
for the betterment of all. -- jd

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


Re: Building a GUI Toolkit

2010-04-20 Thread Дамјан Георгиевски
 Rather than writing a windowing toolkit from the low-level, I would
 rather like to see some wrapper for existing windowing toolkit which
 uses more pythonic idioms.

Isn't PyGUI exactly that?
http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Spammers scratch here with a diamond to find my address:
|||

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


A question about the posibility of raise-yield in Python

2010-04-15 Thread Дамјан Георгиевски
I'm writing this as a complete newbie (on the issue), so don't be 
surprised if it's the stupidest idea ever.

I was wondering if there was ever a discusision in the python community 
on a 'raise-yield' kind-of combined expression. I'd like to know if it 
was proposed/rejected/discussed/not-decided yet??


A 'raise-yield' expression would break the flow of a program just like 
an exception, going up the call stack until it would be handled, but 
also like yield it would be possible to continue the flow of the program 
from where it was raise-yield-ed.

This would be usefull for example in event based frameworks, they could 
just replace socket.* and similar, normally blocking, modules/functions 
with it's own 'raise-yield' enabled ones.

Then you could just take any normal imperative code that calls normal 
library networking code (say smtplib, poplib or httplib) nad run it in a 
event framework.
The normal xxxlib calls at some point would get to the now non-blocking, 
event based socket write/read, break the flow back to the event 
framework, and when it finishes the event framework would continue the 
normal flow of the program past the raise-yield.





-- 
дамјан ((( http://damjan.softver.org.mk/ )))

When you do things right, people won't be sure if you did anything at 
all.

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


Re: Pydev 1.5.6 Released (Django Integration)

2010-04-09 Thread Дамјан Георгиевски
 Hi All,
 
 Pydev 1.5.6 has been released
 
 Details on Pydev: http://pydev.org
 Details on its development: http://pydev.blogspot.com

Question,
Does it have a feature to evaluate the current edit buffer and continue 
with an interactive prompt?



-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Hi! I'm a .signature virus! copy me into your .signature file to help me 
spread!

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


Re: staticmethod and namespaces

2010-04-07 Thread Дамјан Георгиевски


 Having an odd problem that I solved, but wondering if its the best
 solution (seems like a bit of a hack).
 
 First off, I'm using an external DLL that requires static callbacks,
 but because of this, I'm losing instance info. It could be import
 related? It will make more sense after I diagram it:

 -
 So basically I added a list of instances to the base class so I can
 get at them from the staticmethod.

Have you tried using a closure, something like this:

class A:
def call(self, args):
def callback(a, b): # normal function
# but I can access self here too
call_the_dll_function(callback, args1, args2...)


 What's bothering me the most is I can't use the global app instance in
 the A.py module.
 
 How can I get at the app instance (currently I'm storing that along
 with the class instance in the constructor)?
 Is there another way to do this that's not such a hack?
 
 Sorry for the double / partial post :(

-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Q: What's tiny and yellow and very, very, dangerous?
A: A canary with the super-user password.

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


Re: Python for newbies (Pythno users group in Macedonia)

2010-03-15 Thread Дамјан Георгиевски
 If you are all English-speakers then perhaps you could consider
 showing a PyCon video - see
 
   http://pycon.blip.tv

That's certainly something I'm considering for the more advanced users

 Good luck with the group. I hope to see PyCon Macedonia emerging
 before too long!

Thanks :)
I guess we'd have to wait a decade or so for a PyCon here 

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


Re: Python for newbies (Pythno users group in Macedonia)

2010-03-15 Thread Дамјан Георгиевски
 we are starting with bi-monthly Python User Group meetings in Skopje,
 Macedonia. The meetings are targeted for both beginners and more
 experienced users.
   
 ...
 http://us.pycon.org/2010/conference/schedule/event/108/

Great resource, exactly what I needed.

So, they use this book http://www.greenteapress.com/thinkpython/ as a 
guide, seems like a good choice.

I also learned about the tutor mail list:
http://mail.python.org/mailman/listinfo/tutor


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


Python for newbies (Pythno users group in Macedonia)

2010-03-13 Thread Дамјан Георгиевски
Hi all,
we are starting with bi-monthly Python User Group meetings in Skopje, 
Macedonia. The meetings are targeted for both beginners and more 
experienced users.

The basic idea is to have an 1 hour presentation at the start for the 
beginners and an 1 hour ad-hoc discussion about projects, applications, 
interesting stuff etc.

I'd like to gather some guidance/experince/thoughts about some beginner 
oriented python lectures we could use?

My first idea was to do something like the Python module of the Week, 
but maybe there's a better approach?

thanks

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


Re: SCGIServer and unusal termination

2009-11-20 Thread Дамјан Георгиевски
 everything works just fine, but one thing bothers me. All prints after
 try-except block are executed twice after the Ctrl+C is pressed!
 
 test.py:
 #-
 from scgi.scgi_server import SCGIServer
 
 n = 0
 print Starting server.
 
 try:
  SCGIServer().serve()
 except (KeyboardInterrupt, SystemExit):
  print Exception!
 
 # print lines are executed twice (?!)
 n += 1
 print Terminating server, attempt %d. % n
 n += 1
 print Check n: %d. % n
 #-

SCGIServer().serve() forks, so it seems that there are 2 python 
processes continuing to run after SCGIServer().serve()


-- 
дамјан ((( http://damjan.softver.org.mk/ )))

Spammers scratch here with a diamond to find my address:
|||
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: iterate over list while changing it

2009-09-30 Thread Дамјан Георгиевски

 a = [1, 2, 3, 4, 5, 6]
 
 for i, x in enumerate(a):
 
 If you change a list while iterating over, start at the tail.
 
 ...reversed(enumerate(a))

Python 2.6.2 (r262:71600, Jul 20 2009, 02:19:59) 
 a = [1, 2, 3, 4, 5, 6]
 reversed(enumerate(a))
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: argument to reversed() must be a sequence


 no such list method, which mean you did not run the above before
 posting. Boo!



-- 
дамјан ( http://softver.org.mk/damjan/ )

Teaching a pig to sing wastes your time  annoys the pig.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is this whiff/wsgi claim true?

2009-09-27 Thread Дамјан Георгиевски


 Hi folks.  I just modified the WHIFF concepts index page
 
 http://aaron.oirt.rutgers.edu/myapp/docs/W1000.concepts
 
 To include the following paragraph with a startling and arrogant
 claim in the final sentence :)

mod_wsgi (the apache module) can be configured to automatically run any 
.wsgi file dropped in a folder just like CGI ... see here 
http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIScriptAlias

-- 
дамјан ( http://softver.org.mk/damjan/ )

Today we create the legacy of tomorrow.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What python can NOT do?

2009-09-08 Thread Дамјан Георгиевски
 Boot loaders are another type of software which would be impractical
 to write in existing Python implementations.

I wonder if TinyPy (http://www.tinypy.org/) could be used to write a 
boot loader. It would probably need some more code to replace the 
services it uses from an OS, and perhaps it would need to work in 16bit 
program mode on x86 - but maybe it's doable?

tinypy is a minimalist implementation of python in 64k of code

-- 
дамјан ( http://softver.org.mk/damjan/ )

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it. - Brian W. Kernighan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: String to valid Python identifier

2009-08-08 Thread Дамјан Георгиевски


 Is there any easy function in the stdlib to convert any random string
 in a valid Python identifier .. possibly by replacing non-valid
 characters with _ ?
 
 I think this is fairly underspecified as a problem statement. A
 solution that would meet your specification would be

True, I was thinking that if there was an obvious solution I'd get the 
answer right away.. so it seems there's not.

I did try the string.maketrans way... it was a bit ugly so I decided to 
ask here if I'm missing something... maybe I'll try maketrans again.


ps.
by convert I didn't mean a full transformation... I was more hoping 
for the least intrusive transformation that would still leave 
discernible resemblance of the original string. 



-- 
дамјан ( http://softver.org.mk/damjan/ )

When you do things right, people won't be sure if you did anything at 
all.
-- 
http://mail.python.org/mailman/listinfo/python-list


String to valid Python identifier

2009-08-05 Thread Дамјан Георгиевски
Is there any easy function in the stdlib to convert any random string in 
a valid Python identifier .. possibly by replacing non-valid characters 
with _ ?

Python 2.x only, so no need to do Unicode.


-- 
дамјан ( http://softver.org.mk/damjan/ )

Religion ends and philosophy begins, 
just as alchemy ends and chemistry begins 
and astrology ends, and astronomy begins.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem in installing PyGreSQL

2009-08-04 Thread Дамјан Георгиевски
  By the way, you don't have to be super user to install PyGreSQL. 
  You just need SU if you want to install it system wide.  PyGreSQL
  doesn't require any special privileges to run.
 
 Right, but the packages install system-wide. That's why he could
 compile it himself but not use the package.
 
 Exactly so don't install the package.  Do python setup.py build and
 put the three files that are built (_pg.so, pg.py and pgdb.py) into
 any directory and point PYTHONPATH to it.

Or.. with Python 2.6 and up, you can do:
   python setup.py install --user
and it will install the package in users own 
~/.local/lib/python2.6/site-packages/

BTW that path is configurable with the PYTHONUSERBASE environment 
variable.

see: http://www.python.org/dev/peps/pep-0370/

-- 
дамјан ( http://softver.org.mk/damjan/ )

Spammers scratch here with a diamond to find my address:
|||
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] pyKook 0.0.2 - a simple build tool similar to Make or Ant

2009-07-30 Thread Дамјан Георгиевски
 I have released pyKook 0.0.2.
 http://pypi.python.org/pypi/Kook/0.0.2
 http://www.kuwata-lab.com/kook/
 http://www.kuwata-lab.com/kook/pykook-users-guide.html

How does it compare to http://code.google.com/p/fabricate/

and why is this problem (solution) reoccurring all the time


-- 
дамјан ( http://softver.org.mk/damjan/ )

Teaching a pig to sing wastes your time  annoys the pig.

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


Re: If Scheme is so good why MIT drops it?

2009-07-28 Thread Дамјан Георгиевски
 So do all these OSes have some kind of __mega_unifying_poll system
 call that works for anything that might possibly block, that you can
 exploit from a user process?

On Linux at least, the select/poll/epoll is that system, the trick is to 
use eventfd, timerfd and signalfd which are Linux specific system calls.

I think that covers everything needed. (eventfd is used for semaphores)


-- 
дамјан ( http://softver.org.mk/damjan/ )

Give me the knowledge to change the code I do not accept, 
the wisdom not to accept the code I cannot change, 
and the freedom to choose my preference.

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


Re: locale doesn' format

2009-07-20 Thread Дамјан Георгиевски
 I want to format values to the german form eg. 1.034,56 but
 locale.format() doesn't work for me.

seems to work here


 import decimal, locale
 locale.setlocale(locale.LC_ALL, 'mk_MK.UTF-8')
'mk_MK.UTF-8'
 locale.localeconv()['grouping']
[3, 3, 0]
 locale.localeconv()['thousands_sep']
' '
 locale.localeconv()['decimal_point']
','
 locale.format('%f', 1034.56,True)
'1 034,56'
 locale.format('%d', 1034.56,True)
'1 034'



ps.
you can copy/paste the above in .txt file and then run/test it with:
python -m doctest -v  check.txt


-- 
дамјан ( http://softver.org.mk/damjan/ )

  Begin...the rest is easy.

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


Re: locale doesn' format

2009-07-20 Thread Дамјан Георгиевски


 I want to format values to the german form eg. 1.034,56 but
 locale.format() doesn't work for me.
 
 seems to work here

In 2.6 this is good too:

 import decimal, locale
 locale.setlocale(locale.LC_ALL, 'mk_MK.UTF-8')
 '{0:n}'.format(1234.56)
'1 234,56'


-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it reverses the logical flow of conversation.
Q: Why is top posting frowned upon?

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


Best way to enumerate classes in a module

2009-06-23 Thread Дамјан Георгиевски
I need to programmaticaly enumerate all the classes in a given module. 
Currently I'm using dir(module) but the Notice on the documentation page 
[1]  says dir() is supplied primarily as a convenience for use at an 
interactive prompt so that kind of scares me.

Is there a better approach?

If there is, how do I get all the classes of the current module?


[1] http://docs.python.org/library/functions.html#dir

-- 
дамјан ( http://softver.org.mk/damjan/ )

Q: What's tiny and yellow and very, very, dangerous?
A: A canary with the super-user password.

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


Re: Uppercase/Lowercase on unicode

2009-06-05 Thread Дамјан Георгиевски
 I just to check it in the python shell and it's correct.
 Then the problem is by iPython that I was testing it from there.

yes, iPython has a bug like that
https://bugs.launchpad.net/ipython/+bug/339642



-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it reverses the logical flow of conversation.
Q: Why is top posting frowned upon?

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


Re: How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-25 Thread Дамјан Георгиевски


 I have written a socket server and some arbitrary clients. When I
 shutdown the server, and do socket.close(), I cannot immediately start
 it again cause it has some open sockets in TIME_WAIT state. It throws
 address already in use exception at me. I have searched for that in
 google but haven't found a way to solve that.
 
 Tried
 setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 but that does not help.

This should work, AFAIK you only need to do it before you call .bind(..) 
on the accept-ing socket



-- 
дамјан ( http://softver.org.mk/damjan/ )

Give me the knowledge to change the code I do not accept, 
the wisdom not to accept the code I cannot change, 
and the freedom to choose my preference.

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


Re: html ui + py background? any tut?

2009-05-23 Thread Дамјан Георгиевски


 I have read for many times that the modern appliaction (not a web one,
 but desktop on) uses html + js for its UI, and python code is for the
 background work
 but I have never found event a simple (yet completed) article on how
 to develop such a thing from scrach in these advocacy thing.
 
 Can anyone point out some simple, can-be-followed tutorial on such
 thing especially for windows os?

That's very very simple to do with PyQt and Qts Webkit. You can export 
Python objects to the HTML/JS application running in Webkit.

You'll just need to read the Qt Webkit documentation to see how it's all 
done.

This is actually a very good strategy for new apps, you can easily make 
them skinable with  html/js skins for ex.



-- 
дамјан ( http://softver.org.mk/damjan/ )

Well when _I_ was in school, I had to run Netscape on HP/UX, displayed 
on my local X Server running on a Windows 3.1 box. Displayed over a 2400 
baud modem. Uphill. Both ways. In the rain. With NOBODY to hold my 
hands. Because the life of the geek is a lonely life.
- aclarke on /.

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


Re: how to consume .NET webservice

2009-05-14 Thread Дамјан Георгиевски
 OpenOfficeXML document format AKA ODF? ;)
 
 No...Office Open XML, which is used in Microsoft Office 2007 and which
 Microsoft rammed through the ISO:
 http://en.wikipedia.org/wiki/Office_Open_XML

Even worse, Microsoft Office 2007 doesn't even implement the ISO 
standard for Open XML.

-- 
дамјан ( http://softver.org.mk/damjan/ )

Our national drug is alcohol,
we tend to regard the use any other drug with special horror.
-- William S. Burroughs


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


Re: Fill Javascript form

2009-05-12 Thread Дамјан Георгиевски


 On 11 Mag, 23:06, Shawn Milochik sh...@milochik.com wrote:
 How is the form written in JavaScript? Is it dynamically generated?

 In any case, can you just send a POST request if you know the values
 required?
 
 The problem is indeed that the form is dynamically generated.
 That's the .js file:


This seems to be generated by ChiliSpot (the most recent code is from 
http://coova.org/wiki/index.php/CoovaChilli), which also has a 
non-interactive or non-browser-based API/Interface. 

They even have custom application for mobile phones, and a 
Firefox extension for using that API.


 if (navigator.appVersion.indexOf(MSIE)!=-1)
 document.write(script type='text/javascript'
 id='chillicontroller'/ script);
 
 if (!window.queryObj) {
 window.queryObj = new Object();
 window.location.search.replace(new RegExp(([^?=]+)(=([^]
 *))?,g), function($0,$1,$2,$3) { queryObj[$1] = $3; });
 if (queryObj['uamip'] == null  queryObj['uamport'] == null)
 {queryObj['uamip']='10.192.0.1';queryObj['uamport']='3990';}
 }
 
 if (queryObj['uamip'] != null  queryObj['uamport'] != null) {
 var script = document.getElementById('chillicontroller');
 if (script == null) {
   //  document.write('manutenzione');
 script = document.createElement('script');
 script.id = 'chillicontroller';
 script.type = 'text/javascript';
 script.src = 'http://'+queryObj['uamip']+':3990/www/
 chillijs.chi';
 
 var head = document.getElementsByTagName(head)[0];
 if (head == null) head = document.body;
 head.appendChild(script);
}
script=document.getElementById('chillicontroller');
if(script==null)document.write('manutenzione');
 script.src = 'http://'+queryObj['uamip']+':3990/www/chillijs.chi';
 
 } else {
 //document.write('manutenzione');
 var noLocation = document.getElementById(noLocation);
 if (noLocation != null  noLocation.style) {
noLocation.style.display = 'inline';
 }
 }

-- 
дамјан ( http://softver.org.mk/damjan/ )

Well when _I_ was in school, I had to run Netscape on HP/UX, displayed on my 
local X Server running on a Windows 3.1 box. Displayed over a 2400 baud 
modem. Uphill. Both ways. In the rain. With NOBODY to hold my hands. Because 
the life of the geek is a lonely life.
- aclarke on /.

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


Re: [Python-Dev] .pth files are evil

2009-05-09 Thread Дамјан Георгиевски
 Ah, ok. Is there also an easy_install invocation that unpacks the zip
 file into some location of sys.path (which then wouldn't require
 editing sys.path)?

You have pip that does that :)


-- 
дамјан ( http://softver.org.mk/damjan/ )

... knowledge is exactly like power - something 
to be distributed as widely as humanly possible,
for the betterment of all. -- jd

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


How can I dynamically insert a base class in a given class

2009-05-09 Thread Дамјан Георгиевски
How can I dynamically insert a base class in a given class? Yeah, I'm 
writing a class decorator that needs to manipulate the class by 
inserting another base class in it.


Something like:

class ReallyBase(object):
   def someimportantmethod(self):
 return 'really really'

@expose(args)
class Unsuspecting(object):
   def stuff(self):
 return ok

I've come up with this ... but I'm sure it has some shortcomings 

def expose(args):
def wrap(cls):
   # do stuff with args and cls
   return type(cls.__name__, cls.__bases__ + (ReallyBase,), 
dict(cls.__dict__))
return wrap



-- 
дамјан ( http://softver.org.mk/damjan/ )

war is peace
freedom is slavery
restrictions are enablement

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


Re: return functions

2009-05-03 Thread Дамјан Георгиевски
 You seem to have finally discovered that when using Apache/mod_wsgi,
 Apache does a level of URL matching to filesystem based resources.

didn't Paste include something like that ...

 This isn't automatic in normal WSGI servers unless you use a WSGI
 middleware that does the mapping for you. :-)

finally found it  http://pythonpaste.org/modules/urlparser.html


-- 
дамјан ( http://softver.org.mk/damjan/ )

  Begin...the rest is easy.

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


Re: Doc strings in descriptors

2009-05-03 Thread Дамјан Георгиевски
 I have a simple descriptor to create a cached property as shown below.
...
 The problem is that when I use the help() function on them, I don't
 get the doc string from the function that is being wrapped. 
...
 What do I need to do to get the doc string of the wrapped function to
 apper when using help()?

take a look at
http://pypi.python.org/pypi/decorator
and possibly 
http://docs.python.org/library/functools.html#functools.update_wrapper


-- 
дамјан ( http://softver.org.mk/damjan/ )

Real men don't use backups, they post their stuff on a public ftp server 
and let the rest of the world make copies.
   -- Linus Torvalds

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


Re: eval(WsgiApplication)

2009-05-02 Thread Дамјан Георгиевски
  How do I do this in python3?

 What's wrong with importing it?
 
 The problem is that my wsgi files have a wsgi extention for mod_wsgi
 use
..
 mod_wsgi has a .wsgi handler because it is recommended to rename the
 wsgi file with wsgi extensions to avoid double imports
 cherrypy server has a dispatcher class


You can either use .py extension for the wsgi files OR use a custom 
importer that can import your .wsgi files
http://docs.python.org/library/modules.html



-- 
дамјан ( http://softver.org.mk/damjan/ )

Scarlett Johansson: You always see the glass half-empty.
Woody Allen: No. I see the glass half-full, but of poison.

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


Re: Replacing files in a zip archive

2009-05-01 Thread Дамјан Георгиевски
 Which will produce the same output as the original, confounding
 your user.  You could just write the new values out, since .read
 picks the last entry (as I believe it should).  Alternatively, if
 you want to replace it in place, you'll need a bit more smarts
 when there is more than one copy of a file in the archive (when
 z.namelist.count(filename)  1).

I think I'll just hope that there will never be an ODF file like that, 
and if there is, then it's not my problem :)


-- 
дамјан ( http://softver.org.mk/damjan/ )

Give me the knowledge to change the code I do not accept, 
the wisdom not to accept the code I cannot change, 
and the freedom to choose my preference.

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


Replacing files in a zip archive

2009-04-30 Thread Дамјан Георгиевски
I'm writing a script that should modify ODF files. ODF files are just 
.zip archives with some .xml files, images etc. 

So far I open the zip file and play with the xml with lxml.etree, but I 
can't replace the files in it.

Is there some recipe that does this ?




-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

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


Re: Replacing files in a zip archive

2009-04-30 Thread Дамјан Георгиевски
 I'm writing a script that should modify ODF files. ODF files are just
 .zip archives with some .xml files, images etc.
 
 So far I open the zip file and play with the xml with lxml.etree, but
 I can't replace the files in it.
 
 Is there some recipe that does this ?

I ended writing this, pretty specific subclass of ZipFile.
I've added 3 methods, one for getting the .xml content from the document, the 
other for setting (notifying) back the 
changes, and the third to save a copy of the ZipFile to another file (or in 
memory/StringIO).


class ODFFile(ZipFile):
def __init__(self, file, mode='r', compression=0, allowZip64=False):
ZipFile.__init__(self, file, mode='r', compression=0, allowZip64=False)
self.__unchanged = self.namelist()
self.__updated = {}

def get_xml(self, name):
fp  = self.open('%s.xml' % name)
return lxml.etree.parse(fp)

def set_xml(self, name, tree):
name = '%s.xml' % name
if name in self.__unchanged:
self.__unchanged.remove(name)
if tree is not None:
self.__updated[name] = tree

def save_changes(self, fp=None):
if fp is None:
fp = StringIO()
zo = ZipFile(fp, mode='w')
updated = dict(self.__updated)
for zinfo in self.infolist():
name = zinfo.filename
# just copy the unchanged
if name in self.__unchanged:
zo.writestr(zinfo, self.read(zinfo))
# write the changed in the same order
elif name in updated:
s = lxml.etree.tostring(updated.pop(name))
zo.writestr(name, s)
# append the possible remaining (new?)
for name, tree in updated.items():
s = lxml.etree.tostring(tree)
zo.writestr(name, s)
zo.close()
return fp



-- 
дамјан ( http://softver.org.mk/damjan/ )

Religion ends and philosophy begins, 
just as alchemy ends and chemistry begins 
and astrology ends, and astronomy begins.

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


Re: Screenshot of a web page

2009-04-29 Thread Дамјан Георгиевски
 Are you aware of any python module that automatically gives you a
 screenshot of a web page?

PyQt then use it's WebKit based component, load the web page, then 
render it into an image.


-- 
дамјан ( http://softver.org.mk/damjan/ )

Give me the knowledge to change the code I do not accept, 
the wisdom not to accept the code I cannot change, 
and the freedom to choose my preference.

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


AtrributeDict

2009-04-29 Thread Дамјан Георгиевски
I've needed an attribute accessible dict, so I created this.
Are there any obviously stupid shortcomings?

class AttrDict(dict):
   def __getattr__(self, name):
   try:
   return self[name]
   except KeyError, e:
   raise AttributeError(e)


-- 
дамјан ( http://softver.org.mk/damjan/ )

Our national drug is alcohol,
we tend to regard the use any other drug with special horror.
-- William S. Burroughs

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


Re: stuck with PyOBEX

2009-04-29 Thread Дамјан Георгиевски
 This module asks the socket module for AF_BLUETOOTH... in the socket
 module there is no such thing as AF_BLUETOOTH. Could it be that the
 person that made PyOBEX modified his socket module and forgot to give
 his socket module? Or am I missing something? Maybe AF_BLUETOOTH
 stands for something that a programmer would know but I am a beginner
 so...
 
 Is there a OBEX module for Python on windows?


You could try lightblue http://lightblue.sourceforge.net/

and next time don't use windows 
/kidding


-- 
дамјан ( http://softver.org.mk/damjan/ )

We think it's a great consumer win, and it's a great industry win, 
to be able to ensure that with good copy protection, 
you can have so much functionality for the user, 
Jordi Rivas, Microsoft Director of Technology

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


Re: AtrributeDict

2009-04-29 Thread Дамјан Георгиевски
 I've needed an attribute accessible dict, so I created this.
 Are there any obviously stupid shortcomings?
 
 If you know the attribute names ahead of time, you might consider
 using a namedtuple instead.
 See
 http://docs.python.org/library/collections.html#collections.namedtuple

I do use it, even when I don't know the attribute names, see how:

from collections import namedtuple
def build_namespace_tuple(nsmap):
nsmap is a dictionary of XML namespaces (from lxml)
namespaces = namedtuple('namespaces', ' '.join(nsmap.keys()))
return namespaces(*['{%s}' % x for x in nsmap.values()])

If I didn't need the dict values wrapped in {} I could've just used:
return namespaces(*nsmap.values())


and it's all fine, just completely immutable, which is not always 
desirable.

-- 
дамјан ( http://softver.org.mk/damjan/ )

Real men don't use backups, they post their stuff on a public ftp server 
and let the rest of the world make copies.
   -- Linus Torvalds

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


Re: JSON and Firefox sessionstore.js

2009-04-24 Thread Дамјан Георгиевски
 Unless I'm badly mistaken, the Firefox sessionstore.js file is
 supposed to be JSON.
...
 If it matters, I'm using Firefox 2.0.0.5 under Linux.

maybe it can be parsed with PyYAML?


-- 
дамјан ( http://softver.org.mk/damjan/ )

Well when _I_ was in school, I had to run Netscape on HP/UX, displayed on my 
local X Server running on a Windows 3.1 box. Displayed over a 2400 baud 
modem. Uphill. Both ways. In the rain. With NOBODY to hold my hands. Because 
the life of the geek is a lonely life.
- aclarke on /.

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


Re: QT , Wxwidgets are not just UI framework ?

2009-04-17 Thread Дамјан Георгиевски
 However, mostly people agree that Qt is the most powerful, but often
 was debunked because of it's licensing. This has changed to the much
 more liberal LGPL for Qt4.5.

 Now it might be though that you'd still need to buy a license from
 Phil Thompson for his excellent PyQt-wrapping - but I'd personally
 say it's more worth than it actually costs given the power of Qt.

 considering that wxwidget is open source and free do you think that QT
 lisencing is worth it ?

Both Qt and PyQt *ARE* open-source AND free (libre) software.
Qt is GPL and LGPL (you choose) and PyQt is GPL only.

http://www.qtsoftware.com/products/licensing
http://www.riverbankcomputing.co.uk/software/pyqt/license

If you don't like GPL or LGPL (why wouldn't you ?!?) then you can also 
get a commercial license too.



-- 
дамјан ( http://softver.org.mk/damjan/ )

Our national drug is alcohol,
we tend to regard the use any other drug with special horror.
-- William S. Burroughs

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


Re: Get the ipv6 address from a interface

2009-04-10 Thread Дамјан Георгиевски
 In Linux, you can only have one IPv4 address per interface (and you
 have to use alias interfaces, such as eth0:0, to assign multiple
 addresses to a physical link).

that's actually not correct, use the ip tool (iproute2 package) to see 
how easily you can have several addresses to a single interface.
  ip addr add 1.1.1.1/24 dev eth0
  ip addr add 2.2.2.1/24 dev eth0

the need for alias interfaces has been removed, a long time ago (AFAIK 
even before the 2.4 kernel).

-- 
дамјан ( http://softver.org.mk/damjan/ )

In theory, there is no difference between theory and practice.
 But, in practice, there is.

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


Re: ~/.local not in sys.path?

2009-03-28 Thread Дамјан Георгиевски
 I don't see ~/.local in sys.path.  Is this some feature which needs to
 be enabled?  I was kind of unclear after reading the section on it in
 the 2.6 What's New document.

Here it is,
/home/damjan/.local/lib/python2.6/site-packages
by default no special settings (on ArchLinux if it matters).


This is unless I set PYTHONUSERBASE=~/my-python



-- 
дамјан ( http://softver.org.mk/damjan/ )

When you do things right, people won't be sure if you did anything at 
all.

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


Re: Python3.0 has more duplication in source code than Python2.5

2009-02-10 Thread Дамјан Георгиевски
 I have made the same analysis to some commercial source code, the
 dup60 rate is quite often significantly larger than 15%.

commercial code sucks often .. that's why they hide it :)


-- 
дамјан ( http://softver.org.mk/damjan/ )

Scarlett Johansson: You always see the glass half-empty.
Woody Allen: No. I see the glass half-full, but of poison.

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


Re: is python Object oriented??

2009-02-03 Thread Дамјан Георгиевски
 Why?  - Python is object oriented, but I can write whole systems
 without defining a single class.
 By analogy, if data hiding is added to language, I could write a
 whole system without hiding a single item.

I guess the problem is that you would not be able to use some libraries 
because their author thought that it would be wise to hide everything (a 
behavior fairly popular in the Java world).

Let take some http library as an example, the author would certainly 
think that hiding the socket object is the only sane thing to do.
But what if you just *have* to call that special ioctl on the socket 
object before it can work in your scenario...

In python you can easily go under the hood if you need to do it.



-- 
дамјан ( http://softver.org.mk/damjan/ )

We think it's a great consumer win, and it's a great industry win, 
to be able to ensure that with good copy protection, 
you can have so much functionality for the user, 
Jordi Rivas, Microsoft Director of Technology

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


Using lxml to screen scrap a site, problem with charset

2009-02-01 Thread Дамјан Георгиевски
So, I'm using lxml to screen scrap a site that uses the cyrillic 
alphabet (windows-1251 encoding). The sites HTML doesn't have the META 
..content-type.. charset=.. header, but does have a HTTP header that 
specifies the charset... so they are standards compliant enough.

Now when I run this code:

from lxml import html
doc = html.parse('http://a1.com.mk/')
root = doc.getroot()
title = root.cssselect(('head title'))[0]
print title.text

the title.text is а unicode string, but it has been wrongly decoded as 
latin1 - unicode

So.. is this a deficiency/bug in lxml or I'm doing something wrong.
Also, what are my other options here?


I'm running Python 2.6.1 and python-lxml 2.1.4 on Linux if matters.

-- 
дамјан ( http://softver.org.mk/damjan/ )

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it. - Brian W. Kernighan


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


Completer with history for Python 3 ?

2009-02-01 Thread Дамјан Георгиевски
I've been long using this recipe [1] „Completer with history viewer 
support and more features“ with the interactive prompt of python 2.x
But it's not compatible with Python 3.0

Anyone know of a similar functionality for Python 3.0 or I should try to 
port this script?

[1]
http://code.activestate.com/recipes/496822/

-- 
дамјан ( http://softver.org.mk/damjan/ )

Spammers scratch here with a diamond to find my address:
|||

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


Re: Completer with history for Python 3 ?

2009-02-01 Thread Дамјан Георгиевски
 I've been long using this recipe [1] „Completer with history viewer
 support and more features“ with the interactive prompt of python 2.x
 But it's not compatible with Python 3.0
 
 Anyone know of a similar functionality for Python 3.0 or I should try
 to port this script?
 
 [1]
 http://code.activestate.com/recipes/496822/
 
Well, I've made a patch that makes it kinda work
http://paste.lisp.org/display/74707

it does work except that the irlcompleter doesn't complete filenames or 
usernames... any idea why?


-- 
дамјан ( http://softver.org.mk/damjan/ )

Give me the knowledge to change the code I do not accept, 
the wisdom not to accept the code I cannot change, 
and the freedom to choose my preference.

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


Re: Reuse of DB-API 2.0 cursors for multiple queries?

2009-01-28 Thread Дамјан Георгиевски


 Today, I used the adodbapi module against an SQL Server Express
 database. I was surprised to get an exception, when I attempted to
 submit a second query with my cursor object. The full session is
 below.

 curs.execute('select * from localview_roles')
 curs.execute('select * from localview_roles')

have you tried to curs.fetch() or fetchall() before the second execute?



-- 
дамјан ( http://softver.org.mk/damjan/ )

Scarlett Johansson: You always see the glass half-empty.
Woody Allen: No. I see the glass half-full, but of poison.

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


Re: small python-cgi wiki?

2009-01-28 Thread Дамјан Георгиевски
 I'm looking to set up a small private wiki, and am looking for
 recommendations.
 
 Some sort of CGI based package that I could just untar somewhere web
 accessable via Apache would be great.

http://hatta.sheep.art.pl/About
· single file
· stores stuff in mercurial.
· it's WSGI, so yes you can run it as CGI too 
(wsgiref.handlers.CGIHandler)
http://hatta.sheep.art.pl/Features

-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it reverses the logical flow of converstion.
Q: Why is top posting frowned upon?

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


Re: USB in python

2009-01-26 Thread Дамјан Георгиевски
 Sorry, by USB device, I meant a device that is powered/activated by a
 bunch of wires that I want to control using a computer and since I
 had a spare USB jack lying around, I used that instead. But so far I
 haven't tried it, nor will try it if it wont work properly. Yes, it
 is not a proper USB device, because I didnt build it to specifically
 interface with the USB port; but I had to start somewhere. Also, the
 device requires more power than the standard parallel port can give.
 Anyway, it looks like the easiest solution for my case is a
 microcontroller
 
 In which case the Arduino may be a good place to start. The recent
 duemilanove boards use USB to communicate with the host, and so the
 USB port should be available to the microcontroller. We areg etting
 some way away from Python now, of course ...

I second that. 
Arduino to microcontrolers, is what Linux was to kernels back in the 
90ties (now it's mainstream), or maybe what python is/was to Java.

-- 
дамјан ( http://softver.org.mk/damjan/ )

 ()   ASCII Ribbon Campaign
 /\   Keep it simple! 

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


Re: v = json.loads({'test':'test'})

2009-01-25 Thread Дамјан Георгиевски
 raise ValueError(errmsg(Expecting property name, s, end))
 http://docs.python.org/library/json.html
 What am I doing wrong ?
try this
v = json.loads('{test:test}')

JSON doesn't support single quotes, only double quotes.


-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it reverses the logical flow of converstion.
Q: Why is top posting frowned upon?

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


Re: A different kind of interface

2009-01-25 Thread Дамјан Георгиевски
 I don't know what an IBQ is.
 
 +IBQ- seems to be the way your newsreader displays the dashes that
 where in Ben's posting.  I see em dash characters there:

I see IBQ too ... also weird is that he has 
Content-Type: text/plain; charset=utf-7

-- 
дамјан ( http://softver.org.mk/damjan/ )

Give me the knowledge to change the code I do not accept, 
the wisdom not to accept the code I cannot change, 
and the freedom to choose my preference.


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


Re: wsgi silently swallows errors

2009-01-19 Thread Дамјан Георгиевски


 Consider the following wsgi app:
 
 def application(env, start_response):
   start_response('200 OK',[('Content-type','text/plain')])
   yield hello
   x=1/0
   yield world
 
 The result of this is that the web browser displays hello and an
 error
 message ends up in the web log.  But there is no other indication that
 an error has occurred.
 
 Is there any way to get WSGI to not silently swallow errors that occur
 after start_response has been called?

yes, you can wrap your app in a WebError middleware
http://pypi.python.org/pypi/WebError

from weberror.evalexception import EvalException
application = EvalException(application)


-- 
дамјан ( http://softver.org.mk/damjan/ )

In theory, there is no difference between theory and practice.
 But, in practice, there is.
--
http://mail.python.org/mailman/listinfo/python-list


Re: ifconfig in python

2009-01-19 Thread Дамјан Георгиевски
Something *like*  this could work:

myip = urllib2.urlopen('http://whatismyip.org/').read()

of course then you are depending on an external service, not a very 
reliable one even. But then again, you might create an internal service
like that yourself.

This cgi-bin shell code like this for ex:

#! /bin/sh
echo Content-type: text/plain
echo
echo ${REMOTE_ADDR}


-- 
дамјан ( http://softver.org.mk/damjan/ )

Spammers scratch here with a diamond to find my address:
|||
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with -3 switch

2009-01-12 Thread Дамјан Георгиевски
 Perhaps you also like to hear from a developer who has worked on
 Python 3.0 itself and who has done lots of work with internationalized
 applications. If you want to get it right you must
 
 * decode incoming text data to unicode as early as possible
 * use unicode for all internal text data
 * encode outgoing unicode as late as possible.
 
 where incoming data is read from the file system, database, network
 etc.

amen to that... I hate all those apps/libs that only work with ASCII.





-- 
дамјан ( http://softver.org.mk/damjan/ )

Spammers scratch here with a diamond to find my address:
|||
--
http://mail.python.org/mailman/listinfo/python-list


Re: redirecting stderr back..

2009-01-12 Thread Дамјан Георгиевски


 Hi All,
 
 Can someone tell me how to redirect stderr back to the console once
 you've moved it?
 
 import os,sys
 se = os.open(/tmp/mod.log, os.O_WRONLY|os.O_APPEND|os.O_CREAT)
 sys.stderr.write(Foobar\n)
 Foobar
 os.dup2(se, 2)

why not os.dup2(2, 10) and then later os.dup2(10, 2)

-- 
дамјан ( http://softver.org.mk/damjan/ )

  Begin...the rest is easy.

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


Re: State of the art: Tkinter, Tk 8.5, Tix?

2009-01-10 Thread Дамјан Георгиевски
 The themed Tk widgets (ttk) that come with Tk 8.5 add a lot of the
 same things that Tix does, but they do so in a more modern way,
 hooking into platform-specific themes and API's wherever possible (XP,
 Vista, Mac) and updating the generic X11 look as well. As such, they
 are more appropriate for modern development. Tix is more of a legacy
 toolkit.

Interesting... so to summarize, what do I get from Python/TK on *Linux* 
with tkinter beeing dynamically linked to the system tk 8.5.6 ?

Especially I'd like to know if it will support fontconfig/TTF/antialiased fonts?


-- 
дамјан ( http://softver.org.mk/damjan/ )

When you do things right, people won't be sure if you did anything at all.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python is great

2009-01-06 Thread Дамјан Георгиевски
 And there are
 some things (such as Flash-style web applets) that you still can't do
 at all in Python, even after all these years.
 
 You're looking for Silverlight:
 
 http://www.voidspace.org.uk/ironpython/silverlight/index.shtml

or clutter which has Python bindings http://www.clutter-project.org/


-- 
дамјан ( http://softver.org.mk/damjan/ )

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
--
http://mail.python.org/mailman/listinfo/python-list


Re: ethical questions about global variables

2008-12-16 Thread Дамјан Георгиевски
 By per-class-instance variables, you are talking
 about instance attributes?  I.e. self.use_gmt_times?
 I don't see much difference between global variables
 and instance attributes.  

using global variable in modules makes the module not Thread-safe
Using a instance attribute allows more threads to each have a separate instance 
with it's own config.


-- 
дамјан ( http://softver.org.mk/damjan/ )

Today we create the legacy of tomorrow.
--
http://mail.python.org/mailman/listinfo/python-list


Re: mod_python resources

2008-12-16 Thread Дамјан Георгиевски


 I'm trying again because I'm stubborn. Maybe the fourth time will be
 the charm...
 
 Are there any good tutorials out there for setting up Apache with
 mod_python?

mod_python is depreceated, nobody uses it. use mod_wsgi http://www.modwsgi.org/


-- 
дамјан ( http://softver.org.mk/damjan/ )

Today we create the legacy of tomorrow.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Structure using whitespace vs logical whitespace

2008-12-15 Thread Дамјан Георгиевски
 In most languages, I'll do something like this
 
 xmlWriter.BeginElement(parent);
 xmlWriter.BeginElement(child);
 --xml.Writer.Characters(subtext);
 xmlWriter.EndElement();
 xmlWriter.EndElement();
 
 Where the dashes are indentation (since some newsgroup handlers don't
 do tabs well).  XML writing is just an example.

Well, XML beeing just an example.. but still for XML in Python you
probably want to use some XML templating library like Genshi. And for
other stuff there are probably similar sollutions.


-- 
дамјан ( http://softver.org.mk/damjan/ )

war is peace
freedom is slavery
restrictions are enablement
--
http://mail.python.org/mailman/listinfo/python-list


Re: File names, character sets and Unicode

2008-12-13 Thread Дамјан Георгиевски

 In a nutshell, this is likely to cause pain until all file systems are
 standardized on a particular encoding of Unicode. Probably only about
 another fifteen years to go ...

well, most Linux distros are defaulting to a UTF-8 locale now, the
exception beeing Gentoosimilar that expect the user to know what to
configure - which he often doesn't :) 

but, yes, there's no way of enforcing that.

-- 
дамјан ( http://softver.org.mk/damjan/ )

... knowledge is exactly like power - something 
to be distributed as widely as humanly possible,
for the betterment of all. -- jd
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3 read() function

2008-12-04 Thread Дамјан Георгиевски

 I don't think it matters.  Here's a quick comparison between 2.5 and
 3.0 on a relatively small 17 meg file:
 
 C:\c:\Python30\python -m timeit -n 1
 open('C:\\work\\temp\\bppd_vsub.csv', 'rb').read()
 1 loops, best of 3: 36.8 sec per loop
 
 C:\c:\Python25\python -m timeit -n 1
 open('C:\\work\\temp\\bppd_vsub.csv', 'rb').read()
 1 loops, best of 3: 33 msec per loop
 
 That's 3 orders of magnitude slower on python3.0!

Isn't this because you have the file cached in memory on the second run? 

-- 
дамјан ( http://softver.org.mk/damjan/ )

The moment you commit and quit holding back, all sorts of unforseen
incidents, meetings and material assistance will rise up to help you.
The simple act of commitment is a powerful magnet for help. -- Napoleon
--
http://mail.python.org/mailman/listinfo/python-list


Re: Switching windows in PyQT

2008-12-03 Thread Дамјан Георгиевски

 I am new to PyQT and GUI programming in general. What tutorials I have
 found are relatively clear on standard operations within a single
 window (QtGui.QWidget or QtGui.QMainWindow). Exiting this window exits
 the overall application.
 
 How would I switch between windows, that is close one and open
 another, within a running application. I would imagine this to be a
 standard feature often coded.

most often you don't close windows but hide them.

Still, the app object has a property quitOnLastWindowClosed that you can
set to false.


-- 
дамјан ( http://softver.org.mk/damjan/ )

Q: What's tiny and yellow and very, very, dangerous?
A: A canary with the super-user password.
--
http://mail.python.org/mailman/listinfo/python-list


Re: HELP!...Google SketchUp needs a Python API

2008-11-29 Thread Дамјан Георгиевски
 Fight with me for Glory not riches. Fight with me and
 you shall be free. FREDOM!

SketchUp is not free


-- 
дамјан ( http://softver.org.mk/damjan/ )

war is peace
freedom is slavery
restrictions are enablement
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tools for using virtual environments and PEP 370

2008-11-28 Thread Дамјан Георгиевски
 Python 2.6 implemented PEP 370: Per-user site-packages Directory

Ok, you can completelly replace virtualenv with 
a) setting PYTHONUSERBASE=something
b) Editing ~/.pydistutils.cfg  to be like:
[install]
user=True

After this, installing new packages go to 
$PYTHONUSERBASE/lib/python2.6/site-packages/.

I've also tried pip.py and it mostly works fine with this setup except for one 
bug where
it tries to write a install-record-%s.txt file in /usr/lib/.../ 

I've hacked it with this crude patch (which is not correct always).

@@ -1388,7 +1389,8 @@
 if sys.platform == 'win32':
 install_location = os.path.join(sys.prefix, 'Lib')
 else:
-install_location = os.path.join(sys.prefix, 'lib', 'python%s' % 
sys.version[:3])
+import site
+install_location = os.path.join(site.USER_BASE, 'lib', 'python%s' 
% sys.version[:3])
 record_filename = os.path.join(install_location, 
'install-record-%s.txt' % self.name)
 ## FIXME: I'm not sure if this is a reasonable location; probably not


-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it reverses the logical flow of converstion.
Q: Why is top posting frowned upon?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tools for using virtual environments and PEP 370

2008-11-27 Thread Дамјан Георгиевски
 Python 2.6 implemented PEP 370: Per-user site-packages Directory[1]
 
 Now, are there any tools I could use to create and activate virtual
 environments like workingenv, virtualenv etc. but that will use
 PYTHONUSERBASE instead of hard-linking the python program.
 
 
 [1]
 http://docs.python.org/dev/whatsnew/2.6.html#pep-370-per-user-site-packages-directory

I tested again and setting PYTHONUSERBASE=dir where dir was created with 
virtualenv works just fine. 
Now, it would be interesting to see if all those hacks that virtualenv does are 
neccesseary or not.

ps.
Of course I did try this before writing the original post, but it seems I was 
bitten by a bug in my own code.



-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
--
http://mail.python.org/mailman/listinfo/python-list


Tools for using virtual environments and PEP 370

2008-11-20 Thread Дамјан Георгиевски
Python 2.6 implemented PEP 370: Per-user site-packages Directory[1]

Now, are there any tools I could use to create and activate virtual 
environments like workingenv, virtualenv etc. but that will use 
PYTHONUSERBASE instead of hard-linking the python program.


[1]
http://docs.python.org/dev/whatsnew/2.6.html#pep-370-per-user-site-packages-directory


-- 
дамјан ( http://softver.org.mk/damjan/ )

When you do things right, people won't be sure if you did anything at all.
--
http://mail.python.org/mailman/listinfo/python-list


Re: end child process when parent dies (on Unix)

2008-11-17 Thread Дамјан Георгиевски
 I'm starting a Unix tool with subprocess.Popen() from a python script
 and I want the child to be killed when the parent (my script) ends
 for whatever reason *including* if it gets killed by SIGKILL.
 
 A Linux-specific solution is prctl(2).

I've tried this in a test C program... exactly what I need. Now if I 
could slip this between the fork and exec in subprocess.Popen()


-- 
дамјан ( http://softver.org.mk/damjan/ )

In theory, there is no difference between theory and practice.
 But, in practice, there is.
--
http://mail.python.org/mailman/listinfo/python-list


end child process when parent dies (on Unix)

2008-11-16 Thread Дамјан Георгиевски
Hi all,
I'm starting a Unix tool with subprocess.Popen() from a python script 
and I want the child to be killed when the parent (my script) ends for 
whatever reason *including* if it gets killed by SIGKILL.

For normal situations I can send a signal to the pid of the Popen object.
But not if the script ends abnormally (SIGKILL etc).

AFAIK there were some tricks with process leaders and stuff like that so if 
someone remembers the exact semantics of that could refresh my memory.



-- 
дамјан ( http://softver.org.mk/damjan/ )

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Single-instance daemons

2008-11-16 Thread Дамјан Георгиевски


 As per Stevens/Rago, file and record locking provides a convenient
 mutual-exclusion mechanism.  

On linux (at least) there's one nice trick to get a single-instance
program. Create a unix domain socket, and bind it to an address that
begins with the null character '\0'. You can bind the same address a
second time, and if the process dies the socket is automatically
destroyed. It will not leave anything on the filesystem.

def single_instance(id):
import socket
s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
s.bind('\0' + id)
return s


-- 
дамјан ( http://softver.org.mk/damjan/ )

When you do things right, people won't be sure if you did anything at all.
--
http://mail.python.org/mailman/listinfo/python-list