Utility to locate errors in regular expressions
Finding out why a regular expression does not match a given string can very tedious. I would like to write a utility that identifies the sub-expression causing the non-match. My idea is to use a parser to create a tree representing the complete regular expression. Then I could simplify the expression by dropping sub-expressions one by one from right to left and from bottom to top until the remaining regex matches. The last sub-expression dropped should be (part of) the problem. As a first step, I am looking for a parser for Python regular expressions, or a Python regex grammar to create a parser from. But may be my idea is flawed? Or a similar (or better) tools already exists? Any advice will be highly appreciated! Malte -- http://mail.python.org/mailman/listinfo/python-list
Re-using copyrighted code
Hello, I have written a small utility to locate errors in regular expressions that I want to upload to PyPI. Before I do that, I would like to learn a litte more about the legal aspects of open-source software. What would be a good introductory reading? Plus, I have one very specific question: In my package, I use modified code from sre_parse.py, which is part of the Python release. That file has the following header: # # Secret Labs' Regular Expression Engine # # convert re-style regular expression to sre pattern # # Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved. # # See the sre.py file for information on usage and redistribution. # The referenced information is missing in the version of sre.py that comes with current versions of Python, but I found it in the archive http://effbot.org/media/downloads/sre-2.2.1.zip. It reads: # # Secret Labs' Regular Expression Engine # # re-compatible interface for the sre matching engine # # Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved. # # This version of the SRE library can be redistributed under CNRI's # Python 1.6 license. For any other use, please contact Secret Labs # AB (i...@pythonware.com). # # Portions of this engine have been developed in cooperation with # CNRI. Hewlett-Packard provided funding for 1.6 integration and # other compatibility work. # Now, how am I supposed to deal with that? Ask Secret Labs for some kind of permission? Leave it as it is and add my own copyright line? Malte -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-using copyrighted code
I have asked the PSF for help regarding the implications of the license status of code from sre_parse.py and the missing license statement in sre.py. I'll happily report their answer to the list I they don't reply in this thread. At least partially, my confusion seems to be caused by the dichotomy of the concepts of copyright and license. How do these relate to each other? I understand that I have to pick a license for my package. And may be I'm not free to pick any open source license due the license used by Secret Labs AB. But how does that relate to the copyright statements? Should I put my own copyright line in every source file in the package? How about the file that re-uses portions of sre_parse.py? Can there or should there be two copyright lines in that file, one from Secret Labs, one my own? Malte -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-using copyrighted code
Am 10.06.2013 07:31, schrieb Steven D'Aprano: > > But bringing it back to the original topic, I believe that the philosophy > of FOSS is that we should try our best to honour the intentions of the > writer, not to find some legal loophole that permits us to copy his or > her work against their wishes. > Woh! I didn't expect my naive question to trigger that kind of discussion. Thanks to all of you. While I'm grateful for all the input, I have to admit I still don't really know what to do yet. In addition to asking the PSF, I've written to PythonWare (formerly Secret Labs) about their point of view. I'll report their responses. Had I known in the beginning how convoluted things would become, I might have considered two other options: Just publish or keep the code to myself. But I still think, first understanding the legal aspects and then publishing (to give back at least a little) is the way to go. I certainly hope that there is no software out thre that didn't get released to the public because its author found the legal implications to difficult to handle. So there should exist some simple guidelines to help people like me to prepare themselves and their code for that step. Unfortenately, I just haven't discovered them. At least for the Python universe, PyPI would be a good place to setup a page or link to that kind of information. Or is it there already and I have simply overlooked it? Malte -- http://mail.python.org/mailman/listinfo/python-list
How to determine whether client and server are on the same host
Hi, I have a Python application that communicates with a server via telnet. Host and port of the server are supplied by the user when the application is started. How can I determine from within the application whether the server's host actually is the local host? (In that case I could implement an operation not available in the telnet-based protocol by directly accessing the local filesystem.) Sounds like there should be an obvious solution. Unfortunately, I haven't found it yet :-) Malte -- https://mail.python.org/mailman/listinfo/python-list
Re: How to determine whether client and server are on the same host
Am 26.11.2013 00:07, schrieb Chris Angelico: > > Two easy ways you could do this. I would be inclined to do what > PostgreSQL and others do, and have an explicit indication that you > want to use a local method: for instance, the name "localhost". Use of > anything else (including "127.0.0.1") means you use TCP/IP as normal, > but the strict word "localhost", which is normally equivalent to the > address 127.0.0.1, would signal your app to use the direct method (for > PostgreSQL, that's a Unix socket rather than a TCP one). This means > you can still force telnet to be used even if you're working locally - > good for debugging. > Unfortunately, I can't rely on the user to use a specific way to specify the (local) host. > Alternatively, you can simply query the current network interfaces for > their IPs, and see if the IP you were given is in that list. I don't > know of a way to do that in core Python, but the C function you need > is getifaddrs(), and this claims to wrap all that up nicely: > > https://pypi.python.org/pypi/netifaces > > This method would detect, for instance, that calling up 192.168.0.19 > port 12345 is a local lookup, because eth0 has address 192.168.0.19, > and that 192.168.2.2 port 54321 is local too, because wlan0 has > address 192.168.2.2. > That's a very nice module which I wasn't aware of. But if possible I wouldn't want to force the user to install a (binary) extension module. Finding the right module for his platform and version of Python might be too difficult. > If you aren't too concerned with running this on multiple platforms > (which seems likely - working with the local filesystem implies you > know a lot about what the server and client are doing), you could > simply parse the output of 'ip addr', 'ipconfig', 'ifconfig', or some > equivalent network utility for your platform. That might be easier > than playing with the package, depending on environment. > The application is run under Windows as well. So I'd have to parse the output of other network utilities as well, possibly in a variety of languages. Thanks for your suggestions! I'm sorry I'm so picky. May be there just is no easy solution. Malte -- https://mail.python.org/mailman/listinfo/python-list
Re: How to determine whether client and server are on the same host
Am 26.11.2013 00:41, schrieb Ben Finney: > > On Unix, this is up to the person invoking the program: the “sockets > facility allows for a host-local connection to appear as though it's > going over a network. > > https://en.wikipedia.org/wiki/Localhost> > https://en.wikipedia.org/wiki/Unix_domain_socket> > > In other words: Your program shouldn't go snooping around to > second-guess the connection type; if the user asked for a TCP/IP > connection, that's what they should get. If they want to take advantage > of a local connection, they can use a Unix domain socket. > Unfortunately, I can't rely on the user to use a specific way to specify the (local) host. Therefor, the application has to detect if it is run on the same host as the server. May be my description was incomplete and somewhat misleading. Let me try to provide more information. The server is running on a Linux host. The application might be run on any Windows or Linux host in the (local) network. When starting the application, the user can specify the server by host and and a port. If no host is specified, it defaults to localhost. If no port is specified, a couple of well known ports are tried. The application establishes the connection to the server using telnetlib. Most of the application's functionality uses the telnet connection to communicate with the server. One special operation is not available in the protocol, but can be implemented by a direct file-based operation if the application is run on the server itself. I would like to use that option if technically feasible. Malte -- https://mail.python.org/mailman/listinfo/python-list
Re: How to determine whether client and server are on the same host
Am 26.11.2013 12:38, schrieb Chris Angelico: > There is another way you might be able to do this. The server could > simply create a cookie in the file system - say, a file in /tmp with a > randomly-generated name - and it can announce that to the client. If > the client sees the same file in what it sees as /tmp, then it can > assume that it's running on the server. Obviously there's a miniscule > probability of an accidental collision, and someone could deliberately > fool it, but for a simple check, that might work. > That is a clever idea. While I can't modify the server, I could look at the files on the host running the application and try to determine if they fit to information from the server about its files. If both match, I could then conclude that application host and server host probably are the same. But, I still couldn't be sure. Isn't there anything in telnetlib that can differentiate between a local connection and a remote connection? Or may be some unique property of each host that I could use? Malte -- https://mail.python.org/mailman/listinfo/python-list
Re: How to determine whether client and server are on the same host
Am 26.11.2013 13:26, schrieb Chris Angelico: > If you deliberately create a file with a random name, the chances of > one existing with the same name on the client are infinitesimal unless > someone's deliberately trying to confuse things... in which case I > wouldn't worry about it. > I wouldn't, either. But the server is an existing application that I can't extend. It does not support creating a file with a random name. > No, because there's no such thing as a "local connection". For > instance, I have two internet connections at my house, and I can > telnet out on one of them and back in on the other - but both > connections are NATted, so the machine itself doesn't have an IP that > matches what I'm talking about here. I could have a socket connection > from w.x.y.z port 12345 to a.b.c.d port 80, and there's no way > telnetlib would recognize that as coming back to the same computer, > because this computer's IP addresses are all RFC 1918 ones (127.0.0.1, > 192.168.0.19, 192.168.2.2). > Thanks for the explanation. I guess I was hoping that I could use some property of a connection created with telnetlib or its socket to find out whether it was actually a host-local connection (i.e. a connection to 'localhost', '127.xx.xx.xx' or ''). So its either your initial suggestion of taking a hint from the user or comparing files on the server and the client. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to determine whether client and server are on the same host
Am 27.11.2013 00:37, schrieb Gregory Ewing: > > What would happen if you tried the file-based method when > it wasn't a local connection? Is there a danger of it > "succeeding" on the wrong machine and damaging something? > I have been thinking about that. There is a slight risk that the client might be talking to a server on a remote host while there is a similar server running on the local machine. That (local) server then might use a file by the same name as the file on the remote server the client wants to operate on. In that (unlikely) case I would mix up things big time... -- https://mail.python.org/mailman/listinfo/python-list
Re: How to determine whether client and server are on the same host
Am 27.11.2013 01:14, schrieb Michael Torrie: > > I believe socket.getsockname() can return the IP address of the > connecting client if you're using standard tcp/ip sockets. > The way you describe it, it sounds like it would require a change to the server. I can only modify the client. I'll try to find out how I could use that on the client. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to determine whether client and server are on the same host
Am 27.11.2013 00:15, schrieb Chris Angelico: > Since the server runs Linux, inability to run /sbin/ifconfig could > safely be interpreted as "we're not running on the server". But I > think this actually gains little over "is there a file called > /tmp/_this_is_malte_forkel_on_his_server_9515343_", which would be > fairly safe. > The server runs Linux, the client might be used under Windows as well. I can't modify the server. So there is no way to create a file /tmp/_this_is_malte_forkel_on_his_server_9515343 or to check whether it exists on the server side. -- https://mail.python.org/mailman/listinfo/python-list
Python for embedded devices?
I would like to use Python on a router, an Edimax BR-6104K, running OpenWrt (http://www.openwrt.org). While I probably won't need most of the fancier stuff in Python, serial I/O and threads should be supported. The router is based on the ADM5120P, has 2MB of flash and 16MB of RAM, so the version of Python 2.5.1 that is part of OpenWrt is probably a litte to big. Any suggestions? Thanks in advance, Malte -- http://mail.python.org/mailman/listinfo/python-list
Best practices interfacing to device with Python's asyncio and pyserial-asyncio
Hello, I have written a Python package to read from and write to a serial device that uses short telegrams to communicate with sensors and actuators. My classes include one to model the transceiver (it establishes the serial connection using serial.aio.create_serial_connection) and one for the telegram protocol based on asyncio.Protocol. I also have a bunch of classes for the different types of telegrams and devices. While this all works, the device model and the protocol don't look very pythonic to me. Are there any tutorials or examples demonstrating best practices of how to do something like this? Thanks, Malte -- https://mail.python.org/mailman/listinfo/python-list