Real Coders Don't Need Drivers

« Return to Article
  • FIRST 2006-02-13 14:25
    FIRST.  wow, im cool
  • Frederik 2006-02-13 14:26
    Well, at least it worked... kind of...
  • Frederik 2006-02-13 14:26
    Anonymous:
    FIRST.  wow, im cool


    No, you have too much free time ;)
  • Meeeee 2006-02-13 14:33
    4th place! not bad...<br>
  • toxik 2006-02-13 14:34
    wow.<br>
    <br>
    that's all I'm going to say.<br>
  • Randolpho 2006-02-13 14:35
    <P>WTF??!?</P>
    <P>This guy is obviously an old-sk00l shell scripter who has just learned python. I've seen stuff like this as a BASH script too many times to count. </P>
  • jart 2006-02-13 14:36
    The sad thing is how often this happens. I was hired once to rewrite the back-end a non-functional adult website (no puns intended). The Perl scripts the last 60-an-hour consultant wrote were littered with backticked calls to MySQL.
  • What the fag 2006-02-13 14:47
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>. The good news is that, since originally posting this way back in July of '04, I have only seen one or two other variations of this driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets students create their own mailinglists, I stumbled over this python script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the author has discovered a way to avoid compiling a MySQL driver for Python - by using the "mysql" shell tool and parsing the output by splitting it by whitespace. (This will of course fail if anything resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="/images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
    Alex Papadimoulis:
    <p>Today feels like a great day to revisit this classic post from <strong>Stian Søiland</strong>.
    The good news is that, since originally posting this way back in July
    of '04, I have only seen one or two other variations of this
    driver-less SQL sent in ...</p>
    <blockquote dir="ltr" style="margin-right: 0px;">
    <p>When asked to fix an application here at the university that lets
    students create their own mailinglists, I stumbled over this python
    script that tries to synchronize database entries with Mailman.</p>
    <p>In addition to exploring how to create ugly code with Python, the
    author has discovered a way to avoid compiling a MySQL driver for
    Python - by using the "mysql" shell tool and parsing the output by
    splitting it by whitespace. (This will of course fail if anything
    resembling a space is present in the database)</p>
    <p>Also notice the creation of mysql_cmds.txt for stuff to be executed by the SQL server.</p>
    <p><img src="../images/9/o_Driverless.gif"></p></blockquote>
    <p dir="ltr">My apologies for the image; they didn’t have HTML syntax highlighting invented back when I originally posted this.</p>
  • R.Flowers 2006-02-13 14:51
    <P>Can someone port this to Windows for me? [:P]</P>
    <P>(I see that one way or another, the forum software is going to have to change...[8-)])</P>
  • Daniel T 2006-02-13 14:57
    This could be a useful trick if you're using an obscure scripting language that really doesn't have MySQL drivers >:-)

    --Daniel T
  • Umm 2006-02-13 15:04
    So I guess reposting old WTF's is a good way to say he's run out of real coding errors?
  • pmagill 2006-02-13 15:06
    Wow, did the author of one of the WTF's get pissed at Alex or something?<br><br>Regretfully changing the software won't keep this from happening.&nbsp; Even if you are required to sign up first this guy can sign up, post get banned and sign up again using yet another msn or hotmail address.<br><br>____________<br>I am that signature virus, propogating in an assited manner.<br>
  • Daniel T 2006-02-13 15:09
    A co-worker pointed out to me... Judging from the setting, it was probably some poor kid fresh out of Programming 101 with no clue about database libraries, getting paid $5/hour to build this script. If it was in an professional/enterprise/production setting, fine, it's a WTF - in this case, it's probably just a clever student.

    --Daniel T
  • Daniel T 2006-02-13 15:10
    One more comment ;-)

    That screenshot is from EditPlus, isn't it? I love it!!!!

    --Daniel T
  • Nate 2006-02-13 15:20
    This guy probably heard that "Python is a scripting language" so he's using it as a replacement for #!/bin/sh instead of the full-featured programming language that it is.
  • R.Flowers 2006-02-13 15:24
    <P>
    Anonymous:
    Wow, did the author of one of the WTF's get pissed at Alex or something?<BR><BR>Regretfully changing the software won't keep this from happening.&nbsp; Even if you are required to sign up first this guy can sign up, post get banned and sign up again using yet another msn or hotmail address.<BR><BR>____________<BR>I am that signature virus, propogating in an assited manner.<BR>
    </P>
    <P>Slightly more sophisticated software could weed out excessive repetitions, maybe. Also, just a line of code could get rid of those Javascript "injections."</P>
  • makomk 2006-02-13 15:30
    Anonymous:
    The sad thing is how often this happens. I was hired once to rewrite the back-end a non-functional adult website (no puns intended). The Perl scripts the last 60-an-hour consultant wrote were littered with backticked calls to MySQL.


    Yes, but that's Perl - backticked calls to external programs are a long-standing tradition (albeit in this case a WTF-worthy one). Python makes you jump through slightly more hoops to do the same thing (and probably with good reason).
  • merreborn 2006-02-13 15:33
    Anonymous:
    <br>Regretfully changing the software won't keep this from happening.&nbsp; Even if you are required to sign up first this guy can sign up, post get banned and sign up again using yet another msn or hotmail address.<br>
    <br><br><br>Slash ( http://en.wikipedia.org/wiki/Slash_%28weblog_system%29 ) does a very good job at filtering out trolls.&nbsp; <br>
  • Pete from Perth 2006-02-13 15:35
    Alex Papadimoulis:
    <br>by using the "mysql" shell tool and parsing the output by splitting it by whitespace. (This will of course fail if anything resembling a space is present in the database)<br>
    <br><br>For what it's worth, the MySQL shell tool outputs tab separated values. So the script won't "fail if anything resembling a space is present in the database", just if there's a tab.
  • makomk 2006-02-13 15:40
    R.Flowers:

    <P>Slightly more sophisticated software could weed out excessive repetitions, maybe. Also, just a line of code could get rid of those Javascript "injections."</P>


    You wish. For example, I took a look at the LiveJournal code, and while the comment-parsing code is fairly secure (due to a paranoid HTML parser and rewriter) it had a number of additional checks required to handle web-browser specific quirks in parsing HTML, which obviously only got added in response to people noticing security holes. Also, anything short of a full parser (ideally whitelisting), preferably rewriting the HTML in an unambiguous fashion, probably won't cut it reliably due to various... interesting tricks involving HTML entities, comments, punctuation and the like.
  • squirrel 2006-02-13 15:43
    Anonymous:
    This could be a useful trick if you're using an obscure scripting language that really doesn't have MySQL drivers &gt;:-)

    --Daniel T
    <br><br>... as opposed to a language whose selling point is integration with the database at the web server.&nbsp; Lets not forget that this code isn't running anywhere near a backend.&nbsp; This code runs where UI is rendered.&nbsp; :)<br><br><br>
  • squirrel 2006-02-13 15:46
    squirrel:
    Anonymous:
    This could be a useful trick if you're using an obscure scripting language that really doesn't have MySQL drivers &gt;:-)

    --Daniel T
    <br><br>... as opposed to a language whose selling point is integration with the database at the web server.&nbsp; Lets not forget that this code isn't running anywhere near a backend.&nbsp; This code runs where UI is rendered.&nbsp; :)<br>
    <br><br>Haha, my apologies to the Python coders (really!).&nbsp; I don't know why I read this post as PHP.&nbsp; Maybe the syntax coloring &lt;g&gt;.<br>
  • frzx 2006-02-13 15:50
    Anonymous:
    <br>For what it's worth, the MySQL shell tool
    outputs tab separated values. So the script won't "fail if anything
    resembling a space is present in the database", just if there's a
    tab.
    <br>
    <br>
    Except the script uses .split(), not .split('\t'), so it will split fields on any whitespace, not just tabs.<br>
  • foxyshadis 2006-02-13 15:55
    R.Flowers:
    <p>Can someone port this to Windows for me? [:P]</p>
    <p>(I see that one way or another, the forum software is going to have to change...[8-)])</p>
    <br>Amusingly, as long as you have a cygwin/mingw compile of mailman sitting in c:\usr\local\mailman (or whatever your system drive is), this python script would work just fine, fwiw. :p (Unless they're shell scripts, guess you'd have to replace them with batch files that ran them inside the cygwin environment.)<br><br>Thankfully I can't see whatever got posted, and I don't really care anyway as long as it isn't another goatse. But I am a bit worried that next up is IE/ActiveX exploits.<br>
  • pmagill 2006-02-13 15:57
    and r. flowers, I find your avatar a bit umm, disturbing.<br><br>Not that that is a bad thing.<br><br>I think the only way to be rid of things like this is to deny all javascript and html and just simply block text all replies.  Even then you won't have a decent way around repeated lines in a post or even for someone to copy the entire first chapter of a novel into the post and upload, no repitition is necessary.  This then leads to the question of how long can a post get before you truncate it?  There is no perfect answer.<br><br><br>CAPTCHA = register (is someone trying to tell me something?)<br>
  • R.Flowers 2006-02-13 16:10
    <P>
    Anonymous:
    and r. flowers, I find your avatar a bit umm, disturbing.<BR><BR>Not that that is a bad thing.<BR><BR>
    </P>
    <P>I think I will change it. He's starting to disturb me, too. I found him by doing a Google image search for "WTF."</P>
  • makomk 2006-02-13 16:14
    foxyshadis:
    <br>Thankfully I can't see whatever got posted, and I don't really care anyway as long as it isn't another goatse. But I am a bit worried that next up is IE/ActiveX exploits.<br>


    Don't know about that; someone was injecting invisible JavaScript that would quietly post a comment on IE on some of the other forum threads earlier, though. (At least, it would if it actually <em>worked</em> - so many script kiddies just don't test their code properly. I really don't know what the world is coming to...)<br><br>

    Besides, I use Konqueror, so I'm probably safe (you can more-or-less use the forum, as long as you pretend to be an IE user and don't try and use the fancy WYSIWIG HTML editor/toolbar - would it kill them to write portable code for once?).
  • Disgruntled DBA 2006-02-13 16:52
    <br>would it kill them to write portable code for once?).
    <br><br>Yes.&nbsp; It was part of the deal that Bill signed with the Devil.<br>
  • Carsten Kuckuk 2006-02-13 17:29
    <P>I actually like the general approach for its decoupling qualities:</P>
    <P>- No need to link a specific database library into&nbsp;the server</P>
    <P>- Easily adaptable to other database CLIs - at least in theory</P>
    <P>- Execution time is generally not an issue this days on web servers (unless you run Slashdot or some other popular site)</P>
    <P>&nbsp;</P>
  • trollable 2006-02-13 17:42
    Anonymous:
    This guy probably heard that "Python is a scripting language" so he's using it as a replacement for #!/bin/sh instead of the full-featured programming language that it is.
    <br>Now you're just trolling, aren't you?<br><br><br><br><br><br>BTW, does Python have weak references?<br>I just read an introductary book and there was no mention of this feature.<br>
  • an apprentice 2006-02-13 17:45
    <p>I like its highly modular architecture. It seems that /usr/local/mailman/bin/list_lists, /usr/local/mailman/bin/newlist and /usr/local/mailman/bin/rmlist are all separate scripts, called by os.popen and the like. They might be even some bash for all we know.</p><p>And intermediate mysql_cmds.txt is probably being created for efficiency reasons - the coder must have thought it's faster to have one call to os.* than thousands. This is optimization gone the absolutely wrong way. But it's nice he put some effort into it...</p>
  • Stian Soiland 2006-02-13 18:44
    <div style="margin-left: 40px;"><span id="_ctl0_PostForm_Reply">BTW, does Python have weak references?</span><br><span id="_ctl0_PostForm_Reply">I just read an introductary book and there was no mention of this feature.<br><br></span></div>Of course.. the weakref module. It is seldemly used by Python programmers, though, usually only for backend maintenance stuff.<br><span id="_ctl0_PostForm_Reply"></span><br><span id="_ctl0_PostForm_Reply"></span><div style="margin-left: 40px;"><span id="_ctl0_PostForm_Reply"><br></span></div><div style="margin-left: 40px;">import weakref<br><br>class A(object):<br>&nbsp;&nbsp;&nbsp; def method(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1337<br><br>a = A()<br>a_weak = weakref.ref(a)<br><span style="font-style: italic;"># Calling the weakref will reveal the object if it still exists</span><br>print a_weak(), a<br><span style="font-style: italic;"># &lt;__main__.A object at 0x732d0&gt; &lt;__main__.A object at 0x732d0&gt;</span><br>print a_weak().method()<br># 1337<br>a = "Not the A you are looking for"<br>print a_weak()<br><span style="font-style: italic;"># None</span><span style="font-style: italic;" id="_ctl0_PostForm_Reply"></span><br style="font-style: italic;"></div><span style="font-style: italic;" id="_ctl0_PostForm_Reply"></span>
  • Stian Soiland 2006-02-13 18:50
    <div style="margin-left: 40px; font-style: italic;"><span id="_ctl0_PostForm_Reply">It seems that
    /usr/local/mailman/bin/list_lists, /usr/local/mailman/bin/newlist and
    /usr/local/mailman/bin/rmlist are all separate scripts, called by
    os.popen and the like. They might be even some bash for all we know.<br><br></span></div>Yeah.. they are actually Python scripts as well.. but it would obviously take a bit more effort to open the files and read which mailman libraries they were using.<span style="font-style: italic;"></span><br><p>What I like about this code is how they are using "Python" like if it was bash, ignoring every possibility to use a normal database driver or mailman libraries. Of course, using Python instead of say bash will make it a bit easier to split those lists by  <span style="font-family: Courier New;">[a for a in existing if not a in db_list_names],</span> but that is about the only Pythonish thing in the code - which of course in newer Pythons is done faster and easier by using sets.<br> </p>
  • makomk 2006-02-13 18:58
    Anonymous:
    <div style="margin-left: 40px;"><span id="_ctl0_PostForm_Reply">BTW, does Python have weak references?</span><br><span id="_ctl0_PostForm_Reply">I just read an introductary book and there was no mention of this feature.<br><br></span></div>Of course.. the weakref module. It is seldemly used by Python programmers, though, usually only for backend maintenance stuff.<br>


    Full documentation at http://www.python.org/doc/2.4.2/lib/module-weakref.html - as well as Python's standard weak references, there's also weakref proxy objects (which act almost like the actual object referred to - not a good idea to use carelessly, since they might disappear at any moment) and dictionaries with weak keys/values.
  • masklinn 2006-02-13 19:01
    trollable:
    BTW, does Python have weak references?<br>I just read an introductary book and there was no mention of this feature.<br>

    <p>If you're looking for something in Python, first stop is the <a href="http://python.org/doc/2.4.2/modindex.html">Global Module Index</a>, always (second one is the standard library reference).</p>
    <p>And in the Module Index you can find the <a href="http://python.org/doc/2.4.2/lib/module-weakref.html">Weakref</a> module, introduced in Python 2.1.</p>
    <p>(oh, and for the people who don't know python, it has at least 1 or 2 mysql modules, at least one of whom more or less compliant with Python's DB API 2.0)</p>
  • jspenguin 2006-02-13 19:04
    trollable:
    BTW, does Python have weak references?


    Yes, it does. Use the weakref module.
  • Anonymous Coward 2006-02-13 19:07
    trollable:
    <br>BTW, does Python have weak references?<br>I just read an introductary book and there was no mention of this feature.<br>
    <br>
    <br>
    I don't know - does C or C++?<br>
    <br>
  • Principal Skinner 2006-02-13 19:11
    Python is my favorite general-purpose scripting language (rather fond of JavaScript, but it has pretty narrow applications), but I didn't know about this syntax which still kind of blows my mind:<br><br><pre>db_list_names = [a[1] for a in db]<br><br></pre><p>This is definitely not typical Bourne-shell style.&nbsp; Seems like the bass-ackwards kind of thing that might be possible in Perl, however.<br> </p>
  • jspenguin 2006-02-13 19:30
    That's a list comprehension. It's equivalent to doing:

    <pre>
    db_list_names=list()
    for a in db:
    db_list_names.append(a[1])
    </pre>
  • David 2006-02-13 20:27
    They don't need those temporary files<br><br>proc_open -- 
    Execute a command and open file pointers for input/output<br>http://php.net/proc_open<br><br>
  • David 2006-02-13 20:36
    oops. Didn't really read the code, beyond noticing mysql and the temp files. not php<br>
  • David 2006-02-13 20:40
    http://www.python.org/doc/current/lib/module-popen2.html, the python equivalent of php's proc_open<br>
  • Gabriel 2006-02-13 20:54
    My goggles! The eyes do nothing! O_o
  • Principal Skinner 2006-02-13 22:00
    jspenguin:
    That's a list comprehension.
    <br>Interesting, though I find this concept kind of hard to... um... understand.<br>
  • a name 2006-02-13 23:35
    <i>
    I don't know - does C or C++?
    </i>
    <br><br>
    C++ - <a href="http://www.boost.org/libs/smart_ptr/weak_ptr.htm">weak_ptr</a>
    <br><br>
    C - Shouldn't be hard to roll your own, what do you think most of these GC languages are written in?
  • M 2006-02-14 00:00
    Probably the original coder didn't have root to install the "official"
    MySQLdb  package.  Rather than annoy the sysadmin (or attempt
    to install the MySQLdb package in his home directory), he decided to
    take matters into his own hands.<br>
    <br>
  • Amanjit Gill 2006-02-14 03:45
    <P>Hey [I] , weren't there license restrictions with using MySQL client libraries - they first changed from lgpl -&gt; gpl, then added the 3 licensing models: foss license, gpl license and commercial license?</P>
    <P>For a time being, the situation was gpl for client code. Dunno the exact circumstances today. [^o)]^ Also, efficient bulk importing and exporting are normally not exposed via python db api.</P>
    <P>Still WTF - for inserts etc this is weird. And the py is quite ugly. And os.system is very expensive on win32. [N]</P>
    <P>&nbsp;</P>
  • Kilroy 2006-02-14 04:36
    Then you'll love generator expressions:<br>gen_exp = (a for a in something if a == 'foo')<br>will produce a generator which will produce the list of all values in 'something' that is 'foo'. So like a list comprehension but produces its values lazily.<br><br>Produce a list from that with list(gen_exp) :)<br><br>
  • Joost_ 2006-02-14 06:13
    <P>List comprehensions are&nbsp;the&nbsp;gift from god. So many stupid for loops&nbsp;can be stuffed into a little list comprehension. If you want to have a crash course in generator expressions and list comprehensions, take a good look at the results of the Python Coding Contest[1] that was held in the last week of last year; nearly all solutions used three nested generator expressions, except the winning one, which managed to use only two.</P>
    <P>On second thoughts, maybe it's <EM>not</EM> so good for beginning Python coders to look at this code. ;-)</P>
    <P>[1]&nbsp;<A href="http://www.pycontest.net/ranking/">http://www.pycontest.net/ranking/</A></P>
  • dzR 2006-02-14 07:05
    fuck you guys are nerds go play wow or some shit <br>
  • masklinn 2006-02-14 07:14
    Principal Skinner:
    jspenguin:
    That's a list comprehension.
    <br>Interesting, though I find this concept kind of hard to... um... understand.<br>

    <p>Think of it as the combination of map and filter.</p>
    <p>They're, in fact, much more powerful than that. But it may help you start understanding the principles behind list comprehensions and generator comprehensions.</p>
  • sporty 2006-02-14 08:55
    makomk:
    Yes, but that's Perl - backticked calls to external programs are a long-standing tradition (albeit in this case a WTF-worthy one). Python makes you jump through slightly more hoops to do the same thing (and probably with good reason).
    <br><br>No, they're not.&nbsp;&nbsp;&nbsp; It's a convenience, just like system() in c.&nbsp; perl has DBI and various drivers for DB calls.&nbsp; Don't spread misinformation.&nbsp; <br>
  • johnl 2006-02-14 09:01
    dzR, are you somehow confused about what kind of site this is?<br>
  • Jago 2006-02-14 09:35
    And if you like list comprehensions and generator expressions, consider having a look at Haskell, the language Python borrowed them from.&nbsp; As an experimental research language at the cutting edge of computer science, it's full of even more mind-blowing concepts.&nbsp; You probably won't end up actually programming in it, but it's guaranteed to open your mind.<br><br>(It's also the language that the only working version of Perl 6 is written in, but don't let that put you off it.)<br>
  • neek 2006-02-14 10:11
    <span style="font-family: Tahoma;"><font size="2">the real wtf here is that he's using mysql.</font><br></span>
  • Reed 2006-02-14 11:55
    Actually, the Python code is not bad. At least it actually utilizes some of the most useful parts of the language, which lots of Python scripts fail to do and therefore end up being rather tedious C-programs-written-in-Python.<br><br>Yes, calling out to system tools instead of just connecting to the DB is dumb, but I challenge everyone here to truthfully claim that they've *never* done that (whether out of convenience, ignorance, or neccesity).<br><br>Reed<br><br><br><br>
  • DWalker 2006-02-14 12:16
    <DIV>
    Anonymous:
    Wow, did the author of one of the WTF's get pissed at Alex or something?<BR><BR>Regretfully changing the software won't keep this from happening.&nbsp; Even if you are required to sign up first this guy can sign up, post get banned and sign up again using yet another msn or hotmail address.<BR><BR>____________<BR>I am that signature virus, propogating in an assited manner.<BR>
    </DIV>
    <DIV>&nbsp;</DIV>
    <DIV>That signature virus needs spell-check...</DIV>
  • trollable 2006-02-14 12:29
    Anonymous:
    <span id="_ctl0_PostForm_Reply"></span>Of
    course.. the weakref module. It is seldemly used by Python programmers,
    though, usually only for backend maintenance stuff.
    <br>
    <br>
    Thanks for all the replies (and special mention for the example).<br>
    Next question is:<br>
    &nbsp; <span id="_ctl0_PostForm_Reply"><span id="_ctl0_PostForm_Reply">does Python have soft references?<br>
    <br>
    (yes I have checked the doc and google, I found only some kind of emulation using eval)<br>
    </span></span><span id="_ctl0_PostForm_Reply"></span>
  • masklinn 2006-02-14 12:31
    trollable:
    Anonymous:
    <span id="_ctl0_PostForm_Reply"></span>Of
    course.. the weakref module. It is seldemly used by Python programmers,
    though, usually only for backend maintenance stuff.
    <br>
    <br>
    Thanks for all the replies (and special mention for the example).<br>
    Next question is:<br>
    &nbsp; <span id="_ctl0_PostForm_Reply"><span id="_ctl0_PostForm_Reply">does Python have soft references?<br>
    <br>
    (yes I have checked the doc and google, I found only some kind of emulation using eval)<br>
    </span></span><span id="_ctl0_PostForm_Reply"></span>

    <p>What would "soft references" mean?</p>
  • Anonymous coward 2006-02-14 12:36
    <P>
    Anonymous:
    Well, at least it worked... kind of...
    </P>
    <P>WTF?</P>
    <P>&nbsp;</P>
    <P>Heh, the captcha is "random"</P>
  • pseudonymous 2006-02-14 12:37
    I think the original poster is asking about <a href="http://docs.python.org/lib/module-weakref.html">weak references</a>.

    I think.
  • Anonymous coward 2006-02-14 12:38
    <P>
    Anonymous:
    I think the original poster is asking about <A href="http://docs.python.org/lib/module-weakref.html">weak references</A>. I think.
    </P>
    <P>&nbsp;</P>
    <P>I don't see an "original post".&nbsp; The first post I see is "Well, at least it worked"</P>
    <P>[Both IE &amp; Firefox]&nbsp;&nbsp;&nbsp;</P>
  • makomk 2006-02-14 14:01
    masklinn:
    trollable:
    Anonymous:
    <span id="_ctl0_PostForm_Reply"></span>Of
    course.. the weakref module. It is seldemly used by Python programmers,
    though, usually only for backend maintenance stuff.
    <br>
    <br>
    Thanks for all the replies (and special mention for the example).<br>
    Next question is:<br>
      <span id="_ctl0_PostForm_Reply"><span id="_ctl0_PostForm_Reply">does Python have soft references?<br>
    <br>
    (yes I have checked the doc and google, I found only some kind of emulation using eval)<br>
    </span></span><span id="_ctl0_PostForm_Reply"></span>

    <p>What would "soft references" mean?</p>


    I believe they're a bit like weak references, except the object isn't freed until the program runs out of memory. I can't see them working in Python (or indeed C/C++ for that matter) - I think they're a Java idea. (How do you tell when you're out of memory?)
  • Andrew 2006-02-14 14:51
    Every now and then, for whatever weird reason, you really _do_ want to parse a mysql text report. But if you do, there's a better trick than splitting on whitespace; read the second line of the output (the "dashes" between the headers and the data) to find the width of all of the fields :)
  • masklinn 2006-02-15 06:55
    makomk:
    masklinn:
    trollable:
    Anonymous:
    <span id="_ctl0_PostForm_Reply"></span>Of
    course.. the weakref module. It is seldemly used by Python programmers,
    though, usually only for backend maintenance stuff.
    <br>
    <br>
    Thanks for all the replies (and special mention for the example).<br>
    Next question is:<br>
    &nbsp; <span id="_ctl0_PostForm_Reply"><span id="_ctl0_PostForm_Reply">does Python have soft references?<br>
    <br>
    (yes I have checked the doc and google, I found only some kind of emulation using eval)<br>
    </span></span><span id="_ctl0_PostForm_Reply"></span>

    <p>What would "soft references" mean?</p>


    I believe they're a bit like weak references, except the object isn't freed until the program runs out of memory. I can't see them working in Python (or indeed C/C++ for that matter) - I think they're a Java idea. (How do you tell when you're out of memory?)

    <p>That's some frigging bizarre concept, I have to say that I barely see the point of it (only use i'd see would be memcached data)</p>
  • jwenting 2006-02-15 09:35
    <P>
    Anonymous:
    <SPAN style="FONT-FAMILY: Tahoma"><FONT size=2>the real wtf here is that he's using mysql.</FONT><BR></SPAN>
    </P>
    <P>Indeed it is.</P>
  • James Schend 2006-02-15 13:56
    Where's the WTF?&nbsp; It's missing, all I see is the comments.<br>
  • Zygo Blaxell 2006-02-15 15:44
    I did this once.  A Tcl script monitoring a sensor device needed to do three things in an event loop:<br>
    <br>
    1.  Send a command to the device, once per second.<br>
    <br>
    2.  Read the response(s) to the command.  There may be zero or more responses.<br>
    <br>
    3.  Decode the response data and record it somewhere.  Before
    I got there it wrote the data to a file, I replaced that with code to
    insert it into a database.<br>
    <br>
    Parts 1 and 2 were real-time essential tasks, part 3 could crash and
    burn without causing inconvenience.  I wanted to avoid causing any
    part of the program running parts 1 and 2 to be disrupted by any kind
    of failure of part 3.<br>
    <br>
    Tcl provides non-blocking, event-driven I/O to remote devices (like the
    serial port) and child processes (like psql in a child process). 
    Tcl will even automatically queue up data in memory if the child
    process or device gets slow.  This is important because I don't
    want anything happening in task #3 from interfering with tasks #1 and
    #2.<br>
    <br>
    If I had used a database driver library in part #3, I would *still*
    have placed it in a separate process and fed it data asynchronously
    from the process that implements tasks #1 and #2, just so it could
    crash or hang all it likes without breaking anything I actually cared
    about.  Since a separate, isolated process already existed in the
    form of the "psql" utility, I just used that.<br>
  • Cyresse 2006-02-15 18:32
    Principal Skinner:
    Python is my favorite general-purpose scripting language (rather fond of JavaScript, but it has pretty narrow applications), but I didn't know about this syntax which still kind of blows my mind:<BR><BR><PRE>db_list_names = [a[1] for a in db]<BR><BR></PRE>
    <P>This is definitely not typical Bourne-shell style.&nbsp; Seems like the bass-ackwards kind of thing that might be possible in Perl, however.<BR></P>
    <P>
    </P>
    <P>List comprehension, stolen from Haskell. Haskell does them better, but once you learn em they're very useful. <BR><BR>i.e. for a list </P>
    <P>foo =&nbsp;["a","b",None,"c",None, "d"] to remove the Nones you can either:</P><PRE>new_list = []<BR>for item in foo:<BR>&nbsp;&nbsp;&nbsp; if item:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_list.append(item)</PRE>
    <P>or list comprehension stz</P><PRE>new_list = [item for item in foo if item]</PRE><PRE>Not abundantly clear, but generally goes.</PRE><PRE>new_list = [variable, loop, condition/loop]</PRE>
  • masklinn 2006-02-15 20:17
    Cyresse:
    Principal Skinner:
    Python is my favorite general-purpose scripting language (rather fond of JavaScript, but it has pretty narrow applications), but I didn't know about this syntax which still kind of blows my mind:<br><br><pre>db_list_names = [a[1] for a in db]<br><br></pre>
    <p>This is definitely not typical Bourne-shell style.&nbsp; Seems like the bass-ackwards kind of thing that might be possible in Perl, however.<br></p>
    <p>
    </p>
    <p>List comprehension, stolen from Haskell. Haskell does them better, but once you learn em they're very useful. <br><br>i.e. for a list </p>
    <p>foo =&nbsp;["a","b",None,"c",None, "d"] to remove the Nones you can either:</p><pre>new_list = []<br>for item in foo:<br>&nbsp;&nbsp;&nbsp; if item:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new_list.append(item)</pre>
    <p>or list comprehension stz</p><pre>new_list = [item for item in foo if item]</pre><pre>Not abundantly clear, but generally goes.</pre><pre>new_list = [variable, loop, condition/loop]</pre>

    <p>Well, for your example I think i'd use <code>filter</code> and a lambda ;)</p>
  • my name 2006-02-18 12:46
    WTF ?
  • John Hensley 2006-02-18 14:07
    Cyresse:
    List comprehension, stolen from Haskell. Haskell
    does them better, but once you learn em they're very useful.<br>
    <br>
    And I suppose Haskell stole them from Fortran, or whatever language first had a FOR statement.<br>
    <br>
  • - 2006-02-20 15:53
    I doubt the script runs on Windows.