LFS 0.6 beta 1 released
Hi, I'm happy to announce the release of LFS 0.6 beta 1. LFS is an online shop based on Django and jQuery. If you want to read more information please refer to: http://www.getlfs.com/released-06-beta-1 Thanks Kai -- http://mail.python.org/mailman/listinfo/python-list
[ConfigParser] value with ; and the value blank
Hello, how can I use/save/read values with ";" (start comment) and the value blank? When I write (set) my config file often the part behind the ";" disappears. e.g. myKey = startMyValue ; endMyValue Thank's for your hints, Kai -- http://mail.python.org/mailman/listinfo/python-list
ConfigParser: values with ";" and the value blank
Hello, I use the ConfigPaserver from Python. how can I use/save/read values with ";" (start comment) and the value blank? When I write (set) my config file often the part behind the ";" disappears. e.g. myKey = startMyValue ; endMyValue Thank's for your hints, Kai -- http://mail.python.org/mailman/listinfo/python-list
dircache.listdir() or os.listdir()
Hello, I use dircache.listdir(myDir) in my module repeatedly. On OS WIN 2000 listdir() will re-read the directory structure! But on AIX, listdir() will not re-read the directory structure (see Python Library Reference). I work with python version 2.2. Now my 2 questions: Why does dircache.listdir() work different? Can I change in my modules dircache.listdir() with os.listdir() without problems. I want to use the re-read functionality. Thanks for your hints, Kai. -- http://mail.python.org/mailman/listinfo/python-list
dircache.listdir() or os.listdir()
Hello, I use dircache.listdir(myDir) in my module repeatedly. On OS WIN 2000 listdir() will re-read the directory structure! But on AIX, listdir() will not re-read the directory structure (see Python Library Reference). I work with python version 2.2. Now my 2 questions: Why does dircache.listdir() work different? Can I change in my modules dircache.listdir() with os.listdir() without problems. I want to use the re-read functionality. Thanks for your hints, Kai. -- http://mail.python.org/mailman/listinfo/python-list
dircache.listdir() or os.listdir()
Hello, I use dircache.listdir(myDir) in my module repeatedly. On OS WIN 2000 listdir() will re-read the directory structure! But on AIX, listdir() will not re-read the directory structure (see Python Library Reference). I work with python version 2.2. Now my 2 questions: Why does dircache.listdir() work different? Can I change in my modules dircache.listdir() with os.listdir() without problems. I want to use the re-read functionality. Thanks for your hints, Kai. -- http://mail.python.org/mailman/listinfo/python-list
dircache.listdir() or os.listdir()
Hello, I use dircache.listdir(myDir) in my module repeatedly. On OS WIN 2000 listdir() will re-read the directory structure! But on AIX, listdir() will not re-read the directory structure (see Python Library Reference). I work with python version 2.2. Now my 2 questions: Why does dircache.listdir() work different? Can I change in my modules dircache.listdir() with os.listdir() without problems. I want to use the re-read functionality. Thanks for your hints, Kai. -- http://mail.python.org/mailman/listinfo/python-list
Re: dircache.listdir() or os.listdir()
sorry, my posting was crazy -- http://mail.python.org/mailman/listinfo/python-list
Build problem on Solaris 9
Hi All, When I run make after successively running ./configure, I got the following Error message: ./Parser/asdl_c.py -c ./Python ./Parser/Python.asdl /usr/bin/env: No such file or directory make: *** [Python/Python-ast.c] Error 127 /usr/bin/env deos exist Can anyone help me with this? Kai -- http://mail.python.org/mailman/listinfo/python-list
Re: Build problem on Solaris 9
On Jun 16, 12:15 am, "Martin v. Löwis" wrote: > > When I run make after successively running ./configure, I got the > > following Error message: > > ./Parser/asdl_c.py -c ./Python ./Parser/Python.asdl > > /usr/bin/env: No such file or directory > > make: *** [Python/Python-ast.c] Error 127 Thank you so much!!! It compiles now. Kai > > > /usr/bin/env deos exist > > > Can anyone help me with this? > > It's probably rather that "python" does not exist on the path, > which asdl_c.py requires. > > touch Include/Python-ast.h Python/Python-ast.c > > should work around. > > Regards, > Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Installing MySQL-Python
Cathy Hui wrote: > Do u know why do i get the following message error: command 'gcc' failed with exit status 1 yes: error: command 'gcc' failed with exit status 1 means: there's no compiler gcc ... kai when trying to build the > MySql-Python (1.2.0) on my Solaris 8 system? (with mysql 4.0.21 and > python 2.4). thanks! > > error mesg: > ld: fatal: relocations remain against allocatable but non-writable > sections > collect2: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 > > > see below for the log > = > > > # python setup.py build > > unknown> 0x5c8 > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0x840 > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0x84c > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0x9b4 > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0x9bc > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0x9f8 > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0xa04 > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0xa98 > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0xaac > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0xad0 > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0xae0 > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) >0xb0c > /usr/local/mysql/lib/mysql/libmysqlclient_r.a(default.o) > . > . > . > > ld: fatal: relocations remain against allocatable but non-writable > sections > collect2: ld returned 1 exit status > error: command 'gcc' failed with exit status 1 > -- http://mail.python.org/mailman/listinfo/python-list
Noob Parsing question
Given
data = '{[][]}'
How can I efficiently get dictionaries for each of the data blocks framed by <>
?
Thanks for any help
KP
--
https://mail.python.org/mailman/listinfo/python-list
Re: Noob Parsing question
> > Given
> >
> > data =
> > '{[][]}'
> >
> > How can I efficiently get dictionaries for each of the data blocks framed
> > by <> ?
> >
> > Thanks for any help
>
> The question here is: What _can't_ happen? For instance, what happens
> if Fred's name contains a greater-than symbol, or a caret?
>
> If those absolutely cannot happen, your parser can be fairly
> straight-forward. Just put together some basic splitting (maybe a
> regex), and then split on the caret inside that. Otherwise, you may
> need a more stateful parser.
>
> ChrisA
The data string is guaranteed to be clean - no such irregularities occur.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Noob Parsing question
> >> > Given
> >> >
> >> > data =
> >> > '{[][]}'
> >> >
> >> > How can I efficiently get dictionaries for each of the data blocks
> >> > framed by <> ?
> >> >
> >> > Thanks for any help
> >>
> >> The question here is: What _can't_ happen? For instance, what happens
> >> if Fred's name contains a greater-than symbol, or a caret?
> >>
> >> If those absolutely cannot happen, your parser can be fairly
> >> straight-forward. Just put together some basic splitting (maybe a
> >> regex), and then split on the caret inside that. Otherwise, you may
> >> need a more stateful parser.
> >>
> >> ChrisA
> >
> > The data string is guaranteed to be clean - no such irregularities occur.
>
> Okay!
>
> (Side point: You've stripped off all citations, here, so it's not
> clear who said what. My shorthand signature isn't as useful as the
> full line identifying date, time, and person. It's polite to keep
> those lines, at least for the first level of quoting.)
>
> What you want can be done with a regular expression. (Yes, yes, I
> know; now you have two problems.)
>
> >>> data =
> >>> '{[][]}'
> >>> re.findall("<.*?>",data)
> ['', '', '',
> '']
>
> >From there, you can crack open the different pieces:
>
> >>> for piece in re.findall("<.*?>",data):
> ... d = {}
> ... for elem in piece[1:-2].split("^"):
> ... key, value = elem.split("=",1)
> ... d[key] = value
> ... print(d)
> ...
> {'c': '45.22', 'b': 'Fred', 'a': '14'}
> {'b': 'Joe', 'a': '22'}
> {'c': '3.20', 'a': '17'}
> {'b': 'Soup', 'a': '72'}
>
> If you need some of those to be integers or floats, you'll need to do
> some post-processing on it, but this guarantees that you get the data
> out reliably. It depends on not having any of the special characters
> "=^<>" inside the elements, but other than that, it should be safe.
>
> ChrisA
Thanks for your help - much appreciated!
KP
--
https://mail.python.org/mailman/listinfo/python-list
tkinter errors out without clear message
Dear Python community, I have been trying to make Tkinter work on my Scientific Linux 6 (SL6) system. The python version is the SL6 default Python/2.6.6, and the tkinter is also from SL6 repository, "tkinter-2.6.6-51.el6.x86_64". I was able to import _tkinter and Tkinter, and the _test() will bring up an empty window, but it will then fail without any actual error message. I think it's when it tries to create buttons. I tried to use python gdb to debug through the code, but It's hard to pin point the problem. Here is the output: [kai@localhost ~ ]$ python Python 2.6.6 (r266:84292, Nov 21 2013, 12:39:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import _tkinter >>> import Tkinter >>> Tkinter._test() Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 3757, in _test label = Label(root, text=text) File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 2466, in __init__ Widget.__init__(self, master, 'label', cnf, kw) File "/usr/lib64/python2.6/lib-tk/Tkinter.py", line 1932, in __init__ (widgetName, self._w) + extra + self._options(cnf)) _tkinter.TclError >>> I also tried to build python/2.7.5 from scratch, and this problem still there. So, I suspect it could be due to system configuration, but without actual error message, I don't know how to fix this. Did any of you come across similar issues for Tkinter? Any advice would be greatly appreciated! Thanks in advance! Kai -- Kai Song 1.510.495.2180 1 Cyclotron Rd. Berkeley, CA94720, MS-50B 3209 High Performance Computing Services (HPCS) Lawrence Berkeley National Laboratory - http://scs.lbl.gov -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter errors out without clear message
Hi Terry, Thanks for your reply! > Nasty. I have seen TclErrors, but with a message. > > Here is a simple test I just ran (from within Idle) on Win7, 2.7.6. > > >>> import Tkinter as tk > >>> root = tk.Tk() > >>> tk.Label(root, text = 'label text').pack() > >>> tk.mainloop() > > and I see a window with label with text. > > tk._test() works too, with slightly more involved window. > I tried this, but it panics in the same way when running tk.Label(). Again, I can see an empty window after "root=tk.Tk()". > > You said you tried 2.7.5. I believe 2.7.6 has some tkinter bug fixes. > There is also the issue that TkVersion == 8.5 is underspecied -- there are > multiple bugfix releases. The 2.7 Windows installer has been installing > 8.5.2, which has some bugs, but 2.7.7 will install 8.5.13, which is much > better. Sure, I can try with some other combinations of python/tk versions. However, I tried on other SL6 machines, they have the same version (SL6.5), and same tests work on those systems. So, the python/2.6.6 and tk-6.5.7 should work... I can't recall how I set up these systems differently, but I am worried that there are other non-tk/python related issues... I am just curious if there are other ways to debug this other than python gdb? Thanks again for your help! Kai -- Kai Song 1.510.495.2180 1 Cyclotron Rd. Berkeley, CA94720, MS-50B 3209 High Performance Computing Services (HPCS) Lawrence Berkeley National Laboratory - http://scs.lbl.gov -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter errors out without clear message
Hi Terry, I managed to find the problem! As you suggested, I installed newer version of tk/8.5.15. Then, the same test will still fail, but the error message has content now. It complains about missing font. I did some google, then fix it by installing "dejavu-sans-fonts". I laughed when I found the problem, and indeed, this small bug has bothered me for a whole day. Thanks again for your help. I would probably spend hours and days before even think about trying newer version tk. :) Best, Kai On Wed, May 21, 2014 at 1:55 PM, Kai Song wrote: > Hi Terry, > > Thanks for your reply! > > >> Nasty. I have seen TclErrors, but with a message. >> >> Here is a simple test I just ran (from within Idle) on Win7, 2.7.6. >> >> >>> import Tkinter as tk >> >>> root = tk.Tk() >> >>> tk.Label(root, text = 'label text').pack() >> >>> tk.mainloop() >> >> and I see a window with label with text. >> >> tk._test() works too, with slightly more involved window. >> > > I tried this, but it panics in the same way when running tk.Label(). > Again, I can see an empty window after "root=tk.Tk()". > > >> >> You said you tried 2.7.5. I believe 2.7.6 has some tkinter bug fixes. >> There is also the issue that TkVersion == 8.5 is underspecied -- there >> are multiple bugfix releases. The 2.7 Windows installer has been installing >> 8.5.2, which has some bugs, but 2.7.7 will install 8.5.13, which is much >> better. > > > Sure, I can try with some other combinations of python/tk versions. > However, I tried on other SL6 machines, they have the same version (SL6.5), > and same tests work on those systems. So, the python/2.6.6 and tk-6.5.7 > should work... > > I can't recall how I set up these systems differently, but I am worried > that there are other non-tk/python related issues... I am just curious if > there are other ways to debug this other than python gdb? > > Thanks again for your help! > > Kai > > > > -- > Kai Song > 1.510.495.2180 > 1 Cyclotron Rd. Berkeley, CA94720, MS-50B 3209 > High Performance Computing Services (HPCS) > Lawrence Berkeley National Laboratory - http://scs.lbl.gov > -- Kai Song 1.510.495.2180 1 Cyclotron Rd. Berkeley, CA94720, MS-50B 3209 High Performance Computing Services (HPCS) Lawrence Berkeley National Laboratory - http://scs.lbl.gov -- https://mail.python.org/mailman/listinfo/python-list
Pillow bug?
Judging from the message archive, the image-sig list is (just about) dead?
Disclaimer: Am a newbie - so anything is possible
using 'RGB' works fine
img = Image.new('RGB', (inktile[0], inktile[1]), bgcolor)
using '1' or 'L' does not (see trace below)
img = Image.new('L', (inktile[0], inktile[1]), bgcolor)
I change nothing else but the first parameter. If I switch the 'L' back to
'RGB' it works again.
img = Image.new('L', (inktile[0], inktile[1]), bgcolor)
File "C:\Python27\lib\site-packages\PIL\Image.py", line 2015, in new
return Image()._new(core.fill(mode, size, color))
TypeError: an integer is required
The docs say that '1' and 'L' are supported - something broken? Something I do
not understand?
Thanks for any pointers,
Kai
--
https://mail.python.org/mailman/listinfo/python-list
Re: Pillow bug?
On Tuesday, 24 March 2015 13:15:42 UTC-7, Ian wrote:
> On Tue, Mar 24, 2015 at 1:52 PM, Kai wrote:
> > Judging from the message archive, the image-sig list is (just about) dead?
> >
> > Disclaimer: Am a newbie - so anything is possible
> >
> >
> > using 'RGB' works fine
> >
> > img = Image.new('RGB', (inktile[0], inktile[1]), bgcolor)
> >
> > using '1' or 'L' does not (see trace below)
> >
> > img = Image.new('L', (inktile[0], inktile[1]), bgcolor)
> >
> >
> > I change nothing else but the first parameter. If I switch the 'L' back to
> > 'RGB' it works again.
> >
> >
> > img = Image.new('L', (inktile[0], inktile[1]), bgcolor)
> > File "C:\Python27\lib\site-packages\PIL\Image.py", line 2015, in new
> > return Image()._new(core.fill(mode, size, color))
> > TypeError: an integer is required
> >
> > The docs say that '1' and 'L' are supported - something broken? Something I
> > do not understand?
>
> What is the value of bgcolor that you're passing in? Per the docs: "If
> given, this should be a single integer or floating point value for
> single-band modes, and a tuple for multi-band modes (one value per
> band)." So if you're changing from a multi-band mode to a single-band
> mode, you would need to change the color argument as well.
Good catch - that was it.
Thanks much!
--
https://mail.python.org/mailman/listinfo/python-list
Re: Newbie looking for elegant solution
On Tuesday, 24 March 2015 21:04:37 UTC-7, Paul Rubin wrote: > nobody writes: > > I have a list containing 9600 integer elements - each integer is > > either 0 or 1. > > Is that a homework problem? This works for me in Python 2.7 but I think > Python 3 gratuitously broke tuple unpacking so it won't work there: > > > > from itertools import count, groupby > old = [0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1] > new = [reduce(lambda x,(y,i):x*2+y, g, 0) >for k,g in groupby(zip(old,count()), lambda (a,b): b//8)] > print new > > >>> [18, 222, 53] > no homework - real life. thanks for your contribution -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie looking for elegant solution
On Tuesday, 24 March 2015 21:20:11 UTC-7, Chris Angelico wrote: > On Wed, Mar 25, 2015 at 3:04 PM, Paul Rubin wrote: > > This works for me in Python 2.7 but I think > > Python 3 gratuitously broke tuple unpacking so it won't work there: > > > > > > > > from itertools import count, groupby > > old = [0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, > > 1] > > new = [reduce(lambda x,(y,i):x*2+y, g, 0) > >for k,g in groupby(zip(old,count()), lambda (a,b): b//8)] > > print new > > > [18, 222, 53] > > > > You don't need tuple unpacking. Here's the Py3 version of the above: > > from functools import reduce > new = [reduce(lambda x,y:x*2+y[0], g, 0) > for k,g in groupby(zip(old,count()), lambda a: a[1]//8)] > > ChrisA Now I have just read the latest spec and speed/memory may become issues: 1 bit images of a size of 1024 x 1280 need to be processed this way, so 1310720 list elements. Also needs to be 2.7 only. Any recommendations? -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie looking for elegant solution
On Tuesday, 24 March 2015 20:14:06 UTC-7, [email protected] wrote: > I have a list containing 9600 integer elements - each integer is either 0 or > 1. > > Starting at the front of the list, I need to combine 8 list elements into 1 > by treating them as if they were bits of one byte with 1 and 0 denoting bit > on/off (the 8th element would be the rightmost bit of the first byte). > > The end result should be a new list that is 8 x shorter than the original > list containing integers between 0 and 255. > > Speed is not of utmost importance - an elegant solution is. Any suggestions? > > Thanks for all input, > Kai The list comes from PILLOW: getdata # im.getdata() => sequence Returns the contents of an image as a sequence object containing pixel values. The sequence object is flattened, so that values for line one follow directly after the values of line zero, and so on. Note that the sequence object returned by this method is an internal PIL data type, which only supports certain sequence operations, including iteration and basic sequence access. To convert it to an ordinary sequence (e.g. for printing), use list(im.getdata()). -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie looking for elegant solution
On Tuesday, 24 March 2015 20:14:06 UTC-7, [email protected] wrote: > I have a list containing 9600 integer elements - each integer is either 0 or > 1. > > Starting at the front of the list, I need to combine 8 list elements into 1 > by treating them as if they were bits of one byte with 1 and 0 denoting bit > on/off (the 8th element would be the rightmost bit of the first byte). > > The end result should be a new list that is 8 x shorter than the original > list containing integers between 0 and 255. > > Speed is not of utmost importance - an elegant solution is. Any suggestions? > > Thanks for all input, > Kai I though that the bytes type is Python 3 only? If so, I cannot use it. Using PILLOW, I am generating images from text and these are then sent to a black & white image rendering device which expects 8 one bit pixels as one byte (as a condensed format I guess). This device then "turns" bits into pixels again and displays the image that way. If that is clear enough for you to suggest a better way to achieve what I am after, I'd like to hear it. Kai -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie looking for elegant solution
On Wednesday, 25 March 2015 18:10:00 UTC-7, Paul Rubin wrote: > nobody writes: > > I though that the bytes type is Python 3 only? If so, I cannot use it. > > In Python 2, the regular string type (str) is a byte vector, though it > is immutable. Do you send one scan line at a time to the rendering > device, or the whole file all at once, or what? Do you want to dump the > output to a disk file and send that to the rendering device as a > separate step? Anyway, use the chr function to turn a number like 65 > into a character like 'A'. The whole file. The device polls a storage area for incoming files and display them. -- https://mail.python.org/mailman/listinfo/python-list
PIL(LOW) - What am I missing?
I create an image as per:
img = Image.new('1', (1024, 1280), 1)
I then draw on it and do:
imagedata = list(img.getdata())
print len(imagedata)
This gives me 1228800 instead of the expected 1310720 (1024 * 1280)
- any ideas what I am missing?
As always, any help much appreciated.
Kai
--
https://mail.python.org/mailman/listinfo/python-list
Re: PIL(LOW) - What am I missing?
On Wednesday, 25 March 2015 20:54:21 UTC-7, [email protected] wrote: > I create an image as per: > > img = Image.new('1', (1024, 1280), 1) > > I then draw on it and do: > > imagedata = list(img.getdata()) > print len(imagedata) > > This gives me 1228800 instead of the expected 1310720 (1024 * 1280) > - any ideas what I am missing? Please disregard - typo after a long night :( > > As always, any help much appreciated. > > Kai -- https://mail.python.org/mailman/listinfo/python-list
Image rotation issue
Last week some readers have kindly supplied ideas and code for a question I had
asked around a form of image data compression required for specialized display
hardware.
I was able to solve my issues for all but one:
The black & white only device (1024 (X) x 1280 (Y)) expects the compressed data
based on portrait mode, i.e. 8 pixels combined into one bytes for 1280 rows of
128 bytes.
This was working well until the desire came up to be able to tilt the display
and use it in landscape mode - now I needed to rotate the text, as Pillow does
not seem to support drawing at angles.
No big deal - or so I thought after discovering rotate:
from PIL import Image, ImageFont, ImageDraw
white = 1
black = 0
img = Image.new('1', (1280, 1024), white) # start in landscape mode since we
need to calc. based on that
draw = ImageDraw.Draw(img)
fontname = 'FreeSansBold.ttf'
# in real life, x and y are calculated to center or align text both vertically
and horizontally
x = 10
y = 500
dfont = ImageFont.truetype(fontname, 96)
draw.text((x, y), 'Hallo world', black, font = dfont)
draw = ImageDraw.Draw(img)
rotimg = img.rotate(270) # rotation is counterclockwise
# i can almost make it work by resizing rotimg here, but the aspect ratio is
then screwed
#rotimg = rotimg.resize((1024, 1280))
rotimg.show()
imagedata = list(rotimg.getdata())
But grabbing data from the rotimg does not work as it does not seem to return
an image with swapped dimensions...
What am I missing?
--
https://mail.python.org/mailman/listinfo/python-list
Code critique please
I just wrote this bit (coming from Pascal) and am wondering how seasoned Python
programmers would have done the same? Anything terribly non-python?
As always, thanks for all input.
K
"""
Creates a PNG image from EPD file
"""
import os, sys
from PIL import Image, ImageFont, ImageDraw
# -
def RenderByte(draw, byte, x, y):
blist = list(bin(byte).lstrip('0b')) # turn byte into list with 8 elements,
c = 0# each representing one bit
for bit in blist:
if bit:
draw.point((x + c, y), fcolor)
c += 1
return
# -
def EPD_2_Image(edpfilename, imagefilename):
# get out of here if EPD file not present
if not os.path.isfile(epdfilename):
print 'file not found: ' + edpfilename
return
# is this a valid EPD file?
filesize = os.path.getsize(epdfilename)
if (((xdim / 8) * ydim) + header) <> filesize:
print 'incorrect file size: ' + edpfilename
return
# blow old destination file away
if os.path.isfile(imagefilename):
print 'deleting old dest. file: ' + imagefilename
os.remove(imagefilename)
print 'processing...'
# set up PIL objects
img = Image.new('1', (xdim, ydim), bcolor) # '1' = Bi-tonal image
draw = ImageDraw.Draw(img)
# read entire EPD file into byte array (without the header)
content = bytearray(open(epdfilename, 'rb').read())[16:]
# image coord origin at top/left according to PIL documentation
pos = 0
for y in range(ydim):
x = 0
for byte in range(xdim / 8): # 8 pixels 'stuffed' into one byte
RenderByte(draw, content[pos], x, y)
pos += 1
x += 8
img.save(imagefilename) # format is inferred from given extension
print 'done.'
return
# -
xdim = 1024
ydim = 1280
header = 16
black = 0
white = 1
bcolor = black
fcolor = white
epdfilename = 'c:\\temp\\drawtest2.epd'
imagefilename = 'c:\\temp\\drawtest2.png'
EPD_2_Image(epdfilename, imagefilename)
--
https://mail.python.org/mailman/listinfo/python-list
Re: Code critique please
On Tuesday, 7 April 2015 15:43:44 UTC-7, [email protected] wrote: > I just wrote this bit (coming from Pascal) and am wondering how seasoned > Python programmers would have done the same? Anything terribly non-python? > > As always, thanks for all input. > > K > > > > """ > Creates a PNG image from EPD file > """ > > import os, sys > from PIL import Image, ImageFont, ImageDraw > > # > - > def RenderByte(draw, byte, x, y): > > blist = list(bin(byte).lstrip('0b')) # turn byte into list with 8 > elements, > c = 0# each representing one bit > for bit in blist: > if bit: > draw.point((x + c, y), fcolor) > > c += 1 > return > > # > - > def EPD_2_Image(edpfilename, imagefilename): > > # get out of here if EPD file not present > if not os.path.isfile(epdfilename): > print 'file not found: ' + edpfilename > return > > # is this a valid EPD file? > filesize = os.path.getsize(epdfilename) > if (((xdim / 8) * ydim) + header) <> filesize: > print 'incorrect file size: ' + edpfilename > return > > # blow old destination file away > if os.path.isfile(imagefilename): > print 'deleting old dest. file: ' + imagefilename > os.remove(imagefilename) > > print 'processing...' > > # set up PIL objects > img = Image.new('1', (xdim, ydim), bcolor) # '1' = Bi-tonal image > draw = ImageDraw.Draw(img) > > # read entire EPD file into byte array (without the header) > content = bytearray(open(epdfilename, 'rb').read())[16:] > > # image coord origin at top/left according to PIL documentation > pos = 0 > for y in range(ydim): > x = 0 > for byte in range(xdim / 8): # 8 pixels 'stuffed' into one byte > RenderByte(draw, content[pos], x, y) > pos += 1 > x += 8 > > img.save(imagefilename) # format is inferred from given extension > print 'done.' > > return > # > - > > xdim = 1024 > ydim = 1280 > header = 16 > black = 0 > white = 1 > bcolor = black > fcolor = white > > epdfilename = 'c:\\temp\\drawtest2.epd' > imagefilename = 'c:\\temp\\drawtest2.png' > > EPD_2_Image(epdfilename, imagefilename) Thanks for taking the time to give such detailed suggestions - very much appreciated! K -- https://mail.python.org/mailman/listinfo/python-list
Re: Spamming PyPI with stupid packages
Hi, On 2012-01-02 11:03:25 +, Felinx Lee said: I am the author of girlfriend module, a serious Python programmer. This project is nothing about sexist or racism, it is just a joke, a famous joke in China, please be cool down. Yeah, quite funny. Why not put this on an own web server? And now, I have removed money, car, house packages from PyPi, and remove their dependences in girlfriend module, the website is also updated. The girlfriend module just depends on workhard module now. I will remove girlfriend module forever if you still think it is a spam or illegal. I think it's fucking spam. Please remove this crap. kthxbye Kai -- http://mail.python.org/mailman/listinfo/python-list
Red Hat Enterprise Edition and Python 2.4 sources
Hello Python Folks, I have a big problem with the red hat enterprise server. The 2.4 sources build without any big problem. But after installation I can't import datetime. I didn't understand how that can be happend. Datetime is a build in package since python 2.3. Can anybody give me some tips how to install the 2.4 sources perfectly that everything is running on a red hat enterprise system?? Best regards Kai Strempel -- DSL-Aktion wegen großer Nachfrage bis 28.2.2006 verlängert: GMX DSL-Flatrate 1 Jahr kostenlos* http://www.gmx.net/de/go/dsl -- http://mail.python.org/mailman/listinfo/python-list
a Pywin Outlook adress Book Question
Hello Ist there a way to search a Adressbook over Python for a special contact. I know how i read and write a contact, but know i have to search over Python for some contacts, because the adress book has know over 1700 entrys, and it tooks a long time to get them all over the Com object to python. Kai Mayfarth -- http://mail.python.org/mailman/listinfo/python-list
Re: a Pywin Outlook adress Book Question
> > Although now I Google a little more, it looks like AddressEntryFilter > might well do what you want. Worth a look, anyway :) > > TJG Big Thx for your answer. I found some infos about the AddressEntryFilter. Its that what i was searching for, BUT its very limited it cant search for the last changed field, it can only search a small number of filds so its seems there is no other solution then searching in Python. -- http://mail.python.org/mailman/listinfo/python-list
os.access(file, os.R_OK) on UNIX and WINDOWS
Hello, on UNIX I changed the permission of a file "myfile" with chmod 000 myfile. Then I got 0 from os.access(myfile, os.R_OK). This is ok. Then I checked the same file on WINDOWS (with samba): I got "True" from os.access(myfile, os.R_OK). I think it is not ok?! In my python script I check the return value of os.access(myfile, os.R_OK) and when it is "True" I copy the file with shutil.copy(myfile, newfile). But on WINDOWS I get the error: IOError: [Errno 13] Permission denied. How can I check the right file access with python on WINDOWS before copying the file? Is it a samba configuration? Thank' for your hints, Kai -- http://mail.python.org/mailman/listinfo/python-list
Overwrite only one function with property()
Hi list! It is possible to overwrite only one function with the property-function? x = property(getx, setx, delx, 'doc') I just want to overwrite setx, but when I set the others to None, I can't read and del the member. Any ideas or is this not possible? Thank you! Kai -- http://mail.python.org/mailman/listinfo/python-list
Windows: get owner and group of a file
Hello,
with ls -l on windows I get
-rw-r--r-- 1 500 everyone 320 Nov 09 09:35 myfile
How can I get on windows with a standard python 2.2 (without windows
extensions) the information "500" and "everyone" (owner and group)?
Also I cannot use popen('ls -l').
With
import stat
stat_info = os.lstat(myfile)
owner = "%-8s" % stat_info.st_uid
group = "%-8s" % stat_info.st_gid
I get 0 for owner and group.
Thanks for your hints, Kai
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyQT: QDialog and QMainWindow interacting with each other
Fabian Steiner schrieb: > MyDialog is closed by calling MyDialog.accept(). What can I do so that > self.showListViewItems() is called after MyDialog has been closed? > > Thank you for any input! Hi Fabian, override the accept() method and call self.showListViewItems() there. But remember to call QDialog.accept() at the end. def accept( self ): self.showListViewItems() QDialog.accept( self ) Kai Teuber -- http://mail.python.org/mailman/listinfo/python-list
determine 32 or 64 bit architecture with python 2.2
Hello, how can I determine the architecture (32 or 64bit) with python 2.2 on Windows or Unix (AIX, Solaris) OS, without the modul platform? Thanks for your hints, Kai -- http://mail.python.org/mailman/listinfo/python-list
delicious.py 0.2.5: Patch to solve the 401 issue
Hi, I just wanted to mention that I wrote a patch for delicious.py 0.2.5 that solves the 401 "bug". The delicious guys changed their api to use ssl and stuff. I already sent the patch to the author, but in case you need the library asap (as I did) you can apply it and it should work. Greetings Kai delicious-0.2.5-401.patch Description: Binary data -- http://mail.python.org/mailman/listinfo/python-list
Keyword argument 'from'; invalid syntax
Hi list!
I'm using pygmalion (magnolia api access lib) and want to
use the following method that it is offering:
magnolia.bookmarks_find(person='user', from=some_datetime)
As you may noticed, from is a keyword argument and so I
get the following error message from python:
File "", line 1
magnolia.bookmarks_find(person='user', from=some_datetime)
^
: invalid syntax
I have tried to prepare a dict and then passing it to the
method afterwards:
>>> d = {'person': 'user', 'from': vorgestern}
>>> magnolia.bookmarks_find(d)
: bookmarks_find() takes exactly 1
argument (2 given)
I'm out of ideas so help is greatly appreciated!
Thanks
Kai
--
http://mail.python.org/mailman/listinfo/python-list
Re: Keyword argument 'from'; invalid syntax
Hi Steven, On 7/26/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Thu, 26 Jul 2007 03:33:20 +0200, Kai Kuehne wrote: > Try this: > > magnolia.bookmarks_find(**d) This works perfectly, thank you guys. Kai -- http://mail.python.org/mailman/listinfo/python-list
com: makepy gencache.EnsureModule
Hello,
I' having a problem with gencache.EnsureModule:
I used win32com\client\makepy.py to successfully generate Python
sources.
Unfortunately, after I call win32com.client.Dispatch(), the object I
get back is of type "COMObject" instead of one of the generated
classes.
In particular, I'm trying to interact with SolidWorks Extensibility
Type Library and the PROGID is "SldWorks.Application".
Using win32com\client\makepy.py -i
SolidWorks Extensibility Type Library
{801A-A66C-11D3-A8BD-861EBBD6}, lcid=0, major=1, minor=0
>>> # Use these commands in Python code to auto generate .py support
>>> from win32com.client import gencache
>>> gencache.EnsureModule('{801A-A66C-11D3-A8BD-861EBBD6}',
0, 1, 0)
Looking in win32com\gen-py, the appropriate file _does_ exist:
801A-A66C-11D3-A8BD-861EBBD6x0x1x0.py
and it does contain the correct class definitions.
Then, in my code:
>>> mod =
>>> win32com.client.gencache.EnsureModule('{801A2001-A66C-11D3-A8BD-861EBBD6}',
>>> 0, 1, 0)
>>> mod
None
>>> ob = win32com.client.Dispatch("SldWorks.Application")
>>> ob
Why are the object mod is None and the object ob is instead >?
Any bright ideas as to what's going wrong here?
Thanks for your hints, Kai
--
http://mail.python.org/mailman/listinfo/python-list
resolve environment variables in string - regular expression
Hello, how can I resolve envionment variables in a string. e.g. strVar = /myVar resolve in str1 = /mytest02/$MYVAR/mytest02 --> /mytest02//myVar/mytest02 (unix) str2 =$MYVAR/mytest03 --> /myVar/mytest03 (unix) str3 =%MYVAR%/mytest03 --> /myVar/mytest03 (windows) I would not set the variables in this time. I think I need a little regular expression code snippet, but I have not work with regular expression before. Thanks for your help, Kai. -- http://mail.python.org/mailman/listinfo/python-list
unittest: How to fail if environment does not allow execution?
I wrote a test case that depends on a certain file existing in the environment. So, I guess I should test that the file exists in the setUp method. But what if it doesn't exist? How do I fail in that case? I would like to emit an error message explaining what is wrong. tia, Kai -- http://mail.python.org/mailman/listinfo/python-list
Re: unittest: How to fail if environment does not allow execution?
Roy Smith wrote:
> Kai Grossjohann <[EMAIL PROTECTED]> wrote:
>> I wrote a test case that depends on a certain file existing in the
>> environment.
>
> In theory, unit tests should not depend on any external factors, but
> we all know the difference between theory and practice, right?
:-) I am trying to figure out whether a message is logged by syslog.
Not sure how I would do that except require the user to configure syslog
to log foo messages to the /var/log/foo file and to then check that
the message is written.
>> So, I guess I should test that the file exists in the
>> setUp method. But what if it doesn't exist? How do I fail in that case?
>
> def setUp (self):
> try:
> open ("myEssentialTestFile")
> except IOError:
> self.fail ("Hey, dummy, myEssentialTestFile is missing!")
Thank you, sir. I didn't realize that I can fail like that from the
setUp method, as well. Works like a charm.
Why did you use the open/IOError combination, instead of
os.stat/OSError? I am using the latter. But I don't know what I'm doing...
Kai
--
http://mail.python.org/mailman/listinfo/python-list
Why threading.Thread has no detach method
Does this mean terminated threads will automatically release all resouce? -- http://mail.python.org/mailman/listinfo/python-list
Get the ipv6 address from a interface
Hello,
i need a function that returns the ipv6 address from a given interface
name. For ipv4 i use this one:
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
which works great. But i am not enough into python to port that to
ipv6. It has to work under linux only. Any help is appreciated.
Greets,
Kai
--
http://mail.python.org/mailman/listinfo/python-list
sending and receiving ipv6 multicasts
I am trying to send and receive packages via an ipv6 multicast. But I can't get it working. What I thought was, that on the listener site, I just need to bind my socket to the interfaces ipv6 local link address and on the sender site, to the multicast address (in my case ff02::). That doesn't work :) I am using this: http://code.activestate.com/recipes/442490/ as an example code, but I do not understand to which ipv6 address the socket must be bind, to get this working on my link local network. To make clear what I want to do: Every node in my ff80:: network should receive a UDP package and answer with something. The sending node then receives all the answers and puts them in some kind of data structure. Can't be to hard to do this, but I am just lost in ipv6 ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: sending and receiving ipv6 multicasts
On 13 Apr., 19:51, "Martin v. Löwis" wrote:
> On the receiving side, you also need to set the IPV6_JOIN_GROUP
> socket option - else your kernel doesn't know you are interested in
> packets for that address. You need to bind to the multicast port,
> and optionally to the multicast address.
If I do the following
s , ifn = createSocket("eth0")
maddr = ("ff02::1", 10101)
maddr = socket.getaddrinfo(maddr[0], maddr[1], socket.AF_INET6,
socket.SOCK_DGRAM)[0][-1]
group = socket.inet_pton(socket.AF_INET6, maddr[0]) + ifn #ifn is the
interface index
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_JOIN_GROUP, group)
s.bind(maddr)
def createSocket(if=""):
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if hasattr(socket, "SO_REUSEPORT"):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_LOOP,
1)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS,
224)
ifn = if_nametoindex(if)
ifn = struct.pack("I", ifn)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_IF,
ifn)
return sock, ifn
I get the following error: "socket.error: [Errno 22] Invalid
argument". So it complains about the multicast address.
--
http://mail.python.org/mailman/listinfo/python-list
ANN: Demo online shop for LFS
Hi, I'm pleased to announce that there is new demo shop for LFS: http://demo.getlfs.com LFS is an online shop based on Django and distributed under the BSD- License For more information please visit http://www.getlfs.com, subscribe to our feed http://www.getlfs.com/feeds/news or follow us on Twitter http://twitter.com/lfsproject. Thanks Kツi -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python installation
The Debian stable package tree has only libapache2-mod-python2.3 (3.1.3-3). You can look at http://packages.debian.org/stable/python/ for a detailed list. If you really want to use python2.4 you can either try to use the ubuntu package (http://packages.ubuntu.org.cn/breezy/python/libapache2-mod-python2.4) but I would not recommend it, since it could break your system. Or you could search a backport, may be there is one. Am Montag, 30. Januar 2006 15:21 schrieb Ravi Teja: > I have Ubuntu which uses the Debian package tree. > I see libapache2-mod-python2.4 with "apt-cache search mod_python" > Perhaps you don't have all the repositories enabled? Ubuntu uses mostly the debian testing/unstable or even experimental package tree plus its own package tree, so there are a few packages only available to Ubuntu. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python "why" questions
Russ P. wrote: >> A simple example: Using zero-based indexing, suppose you want to indent >> the string "spam" so it starts at column 4. How many spaces to you >> prepend? No, you won't want to indent a string so it starts at column 4. You simply want to indent the string by four spaces. Like in PEP 8: /Use 4 spaces per indentation level./ > 0123456789 > spam And of course your text editor will number the columns beginning with one, so the string starts at column 5. 123456789 spam -- Kai Borgolte, Bonn -- http://mail.python.org/mailman/listinfo/python-list
Re: Python "why" questions
Sorry about my previous posting with wrong references, this one should be better. Steven D'Aprano wrote: >A simple example: Using zero-based indexing, suppose you want to indent >the string "spam" so it starts at column 4. How many spaces to you >prepend? No, you won't want to indent a string so it starts at column 4. You simply want to indent the string by four spaces. Like in PEP 8: /Use 4 spaces per indentation level./ >0123456789 >spam And of course your text editor will number the columns beginning with one, so the string starts at column 5. 123456789 spam -- Kai Borgolte, Bonn -- http://mail.python.org/mailman/listinfo/python-list
ANN: LFC 1.0
Hi guys, today we released LFC 1.0. This is the first final release of LFC. LFC is a CMS based on Python, Django and jQuery. You can find the installer here: http://pypi.python.org/pypi/django-lfc/1.0. The installation is described here: http://packages.python.org/django-lfc/introduction/installation.html and should last just a few minutes. Its main features are: - Commenting - Cut/Copy’n Paste - Easy upload of images and files - Flexible Databases - Multilingual content - Pluggable - Role based per-object permissions - RSS Feeds - Search - Tagging - Time based publishing - Variable Templates - Variable Portlets - Variable Workflows - WYSIWYG-Editor You can find more information on following places: - Official Homepage: http://www.lfcproject.com/ - Documentation: http://packages.python.org/django-lfc - Download: http://pypi.python.org/pypi/django-lfc - Source Code: http://bitbucket.org/diefenbach/django-lfc - Google Group: http://groups.google.com/group/django-lfc - Twitter: http://twitter.com/lfcproject - IRC: irc://irc.freenode.net/django-lfc Any suggestions are highly appreciated. Thanks Kai -- http://mail.python.org/mailman/listinfo/python-list
Re: PyCharm
On 2010-10-13 23:36:31 +0200, Robert H said: Since the new IDE from Jetbrains is out I was wondering if "you" are using it and what "you" think about it. It sucks. http://regebro.wordpress.com/2010/10/14/python-ide-code-completion-test Kai -- http://mail.python.org/mailman/listinfo/python-list
Please recommend a open source for Python ACLs function
Hello Dear All: I would like to write some simple python test code with ACL(Access Control List) functions. Now simply I aim to use MAC address as ACL parameters, is there any good ACL open source recommended for using? Simple one is better. Any tips or suggestions welcomed and appreciated. Thank you. Kay -- http://mail.python.org/mailman/listinfo/python-list
Localhost client-server simple ssl socket test program problems
Hello,everyone!!
I am writing a simple ssl client-server test program on my personal laptop.
And I encounter some problems with my simple programs.
Please give me some
helps.
My server code:
import socketimport sslbindsocket =
socket.socket()bindsocket.bind(('127.0.0.1', 1234))bindsocket.listen(5)print
'server is waiting for connection...'newsocket, fromaddr =
bindsocket.accept()print 'start ssl socket...'connstream =
ssl.wrap_socket(newsocket, server_side=True,
certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt",
keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key",
ssl_version=ssl.PROTOCOL_SSLv23)data = connstream.read()print 'connected from
address', fromaddrprint 'received data as', repr(data)connstream.close()
My client code:
import socketimport ssls = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)ssl_sock = ssl.wrap_socket(s,
ca_certs="/home/ckyang/PHA/testsslsocket/myCA.crt",
cert_reqs=ssl.CERT_REQUIRED)ssl_sock.connect(("127.0.0.1",
1234))ssl_sock.write("hello")ssl_sock.close()
---Server
side error:
File "views.py", line 17, in connstream = ssl.wrap_socket(newsocket,
server_side=True, certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt",
keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key",
ssl_version=ssl.PROTOCOL_SSLv23) File "/usr/lib/python2.7/ssl.py", line 344,
in wrap_socketciphers=ciphers) File "/usr/lib/python2.7/ssl.py", line 119,
in __init__ciphers)ssl.SSLError: [Errno 336265218] _ssl.c:347:
error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib
Client side error:
File "client.py", line 10, in ssl_sock.connect(("127.0.0.1", 1234))
File "/usr/lib/python2.7/ssl.py", line 299, in connectself.do_handshake()
File "/usr/lib/python2.7/ssl.py", line 283, in do_handshake
self._sslobj.do_handshake()socket.error: [Errno 104] Connection reset by peer
So
what is wrong with my code?
The codes are so simple and so much like python official site sample
demonstration, but I still cant get it work, so frustrating.
Seems the problem happened on server side then cause client side cant connect
well, is that right?
My platform is ubuntu, with openssl 0.9.8 and python 2.7.
All certificates and keys self-signed by openssl for test convenience.
This is the site for referrence :
http://andyjeffries.co.uk/articles/x509-encrypted-authenticated-socket-ruby-client
Or should I need a real certificate issued by a real CA to let things work?
Any tips or suggestions welcomed, thank you very much~
Good day.
Kay
--
http://mail.python.org/mailman/listinfo/python-list
RE: Localhost client-server simple ssl socket test program problems
Thanks for tips. But I dont understand one thing is if Python's SSL lib doesn't support encrypted private keys for sockets. Then why should we "encrypt" the private key with "openssl rsa -in /etc/home/ckyang/PHA/testsslsocket/mypha.key -out /etc/home/ckyang/PHA/testsslsocket/mypha-nopasswd.key" again? Shouldn't that be decrypted? And also this solution is not the right one, I use mypha-nopasswd.key replace the original one, still not work. So sad. But thanks. ^ ^ Kay > To: [email protected] > From: [email protected] > Subject: Re: Localhost client-server simple ssl socket test program problems > Date: Thu, 15 Dec 2011 20:45:43 +0100 > > Am 15.12.2011 20:09, schrieb Yang Chun-Kai: > > Server side error: > > > > File "views.py", line 17, in > > connstream = ssl.wrap_socket(newsocket, server_side=True, > > certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", > > keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", > > ssl_version=ssl.PROTOCOL_SSLv23) > > File "/usr/lib/python2.7/ssl.py", line 344, in wrap_socket > > ciphers=ciphers) > > File "/usr/lib/python2.7/ssl.py", line 119, in __init__ > > ciphers) > > ssl.SSLError: [Errno 336265218] _ssl..c:347: error:140B0002:SSL > > routines:SSL_CTX_use_PrivateKey_file:system lib > > This error is most likely caused by an encrypted private key. Python's > SSL lib doesn't support encrypted private keys for sockets. You can > encrypt the private key with > >openssl rsa -in /etc/home/ckyang/PHA/testsslsocket/mypha.key -out > /etc/home/ckyang/PHA/testsslsocket/mypha-nopasswd.key > > Christian > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Localhost client-server simple ssl socket test program problems
Hello~ Thanks for your fast reply. No, it doesn't ask for password, just a single line with "writing RSA kay", then mypha-nopasswd.key appeared. If my key is not in PEM Format, can openssl with simple commands to switch it to? Or I should re-do the self-signed process with some certain key-words / parameters? And what you mean about Python 2.x's SSL module doesn't support cert directories ? Can you be more specific about that ^^. Do you mean parameters with certfile and keyfile those two should put together or CA certificate need to be chained with other CA? Thanks. Kay > To: [email protected] > From: [email protected] > Subject: Re: Localhost client-server simple ssl socket test program problems > Date: Thu, 15 Dec 2011 21:19:14 +0100 > > Am 15.12.2011 21:09, schrieb Yang Chun-Kai: > > Thanks for tips. > > > > But I dont understand one thing is if Python's SSL lib doesn't support > > encrypted private keys for sockets. > > > > Then why should we "encrypt" the private key with "openssl rsa -in > > /etc/home/ckyang/PHA/testsslsocket/mypha.key -out > > > > /etc/home/ckyang/PHA/testsslsocket/mypha-nopasswd.key" again? > > > > Shouldn't that be decrypted? > > > > And also this solution is not the right one , I use mypha-nopasswd.key > > replace the original one, still not work. > > IIRC the command should decrypt the key. Did it prompt for a password? > > The error could be caused by other issues. For example the key and cert > must be in PEM Format. The PKS#12 isn't supported. I'm not sure if > Python's builtin SSL module loads DER certs. > > You may also missing a valid CA cert chain. Python 2.x's SSL module > doesn't support cert directories so you have to provide a chain file. > The certs in the chain file must be in the right order, too. > > Christian > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
RE: Localhost client-server simple ssl socket test program problems
> To: [email protected] > From: [email protected] > Subject: Re: Localhost client-server simple ssl socket test program problems > Date: Thu, 15 Dec 2011 20:45:43 +0100 > > Am 15.12.2011 20:09, schrieb Yang Chun-Kai: > > Server side error: > > > > File "views.py", line 17, in > > connstream = ssl.wrap_socket(newsocket, server_side=True, > > certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", > > keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", > > ssl_version=ssl.PROTOCOL_SSLv23) > > File "/usr/lib/python2.7/ssl.py", line 344, in wrap_socket > > ciphers=ciphers) > > File "/usr/lib/python2.7/ssl.py", line 119, in __init__ > > ciphers) > > ssl.SSLError: [Errno 336265218] _ssl..c:347: error:140B0002:SSL > > routines:SSL_CTX_use_PrivateKey_file:system lib > > This error is most likely caused by an encrypted private key. Python's > SSL lib doesn't support encrypted private keys for sockets. You can > encrypt the private key with >>>>>> >>>I generate the server private key with "openssl genrsa -out mypha.key >>>>>> >>>2048".>>>But this seems the standard command to do it.>>>How do I get >>>>>> >>>the private key without encrypted ?>>>Or should I always do this and >>>>>> >>>encrypt it again to get it decrypted ?>>>If I use the encrypted key >>>>>> >>>and .csr to produce my certificate will that be different from >>>>>> >>>decrypted key?>>>Thanks.>>>Kay>>> >openssl rsa -in /etc/home/ckyang/PHA/testsslsocket/mypha.key -out > /etc/home/ckyang/PHA/testsslsocket/mypha-nopasswd.key > > Christian > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
python2.7 kill thread and find thread id
Hello,guys!! I am using python2.7 to write a simple thread program which print the current running thread id and kill it with this id. But I have some questions with this. My code: -from threading import Threadclass t(Thread): def __init__(self): Thread.__init__(self) def run(self): self.tid = Thread.get_ident() print 'thread id is', self.tid def kill(self): *** // how to do this with its own id, for example "exit(self.tid)" ?if __name__ == "__main__" go = t() go.start() go.kill()-First, I can't call get_ident(), seems not supported. Second, how to kill the thread with its own id? I know I can use SystemExit() to shut this down, but I want to kill the certain thread not the whole program. Anyone know how to fix my code to achieve it? Any tips welcomed. Thank you in advance. Kay -- http://mail.python.org/mailman/listinfo/python-list
RE: python2.7 kill thread and find thread id
Sorry for the misarrangement of my code in list, it happens everytime. I apologized. From: [email protected] To: [email protected] Subject: python2.7 kill thread and find thread id Date: Wed, 4 Jan 2012 14:10:46 +0800 Hello,guys!! I am using python2.7 to write a simple thread program which print the current running thread id and kill it with this id. But I have some questions with this. < /div>My code: -from threading import Threadclass t(Thread): def __init__(self): Thread.__init__(self) def run(self): self.tid = Thread.get_ident() print 'thread id is', self.tid def kill(self): *** // how to do this with its own id, for example "exit(self.tid)" ?if __name__ == "__main__" go = t() go.start() go.kill()-First, I can't call get_ident(), seems not supported. Second, how to kill the thread with its own id? I know I can use SystemExit() to shut this down, but I want to kill the certain thread not the whole program. Anyone know how to fix my code to achieve it? Any tips welcomed. Thank you in advance. Kay -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
