<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sebthom.de &#187; Jython</title>
	<atom:link href="http://sebthom.de/category/it/development/jython/feed/" rel="self" type="application/rss+xml" />
	<link>http://sebthom.de</link>
	<description>Selbständiger IT Berater - Java, J2EE, WebSphere Portal, Lotus Domino</description>
	<lastBuildDate>Sun, 14 Mar 2010 14:10:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>de</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Leveraging PyDev&#8217;s auto completion for indirectly created objects</title>
		<link>http://sebthom.de/140-leveraging-pydevs-auto-completion-indirectly-created-objects/lang/de/</link>
		<comments>http://sebthom.de/140-leveraging-pydevs-auto-completion-indirectly-created-objects/lang/de/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 23:29:00 +0000</pubDate>
		<dc:creator>Sebastian Thomschke</dc:creator>
				<category><![CDATA[Jython]]></category>
		<category><![CDATA[pydev]]></category>
		<category><![CDATA[pydoc]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rtype]]></category>

		<guid isPermaLink="false">http://sebthom.de/?p=140</guid>
		<description><![CDATA[     <link rel="alternate" type="application/atom+xml" title="sebthom.de Category: Jython" href="http://sebthom.de/category/it/development/jython/lang/de/feed/" />
This is just a quick tip how to enable auto completion in PyDev for indirectly created objects. 
By default, PyDev has no problems in presenting you the possible object attributes and methods on a variable if that variable gets a new object instance assigned directly in the code. 
For example, when you first type &#8230;
mybook [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick tip how to enable auto completion in <a href="http://pydev.org" rel="nofollow" >PyDev</a> for indirectly created objects. </p>
<p>By default, PyDev has no problems in presenting you the possible object attributes and methods on a variable if that variable gets a new object instance assigned directly in the code. </p>
<p>For example, when you first type &#8230;</p>
<pre name="code" class="python">mybook = Book()</pre>
<p>&#8230; and in the next line you enter &#8230;</p>
<pre name="code" class="python">mybook.</pre>
<p>&#8230; PyDev will dutifully present you the statically declared features for the Book class in a popup.</p>
<p>If you however get that Book instance as the result of another method, e.g. &#8230;</p>
<pre name="code" class="python">mybook = bookstore.findBook("foobar")</pre>
<p>&#8230; PyDev currently seems to be helpless. </p>
<p>Because of Python&#8217;s dynamic nature it is of course a bit harder for an IDE to figure out what kind of objects may a method. But PyDev could for example honor the @return / @rtype <a href="http://epydoc.sourceforge.net/manual-epytext.html" rel="nofollow" >PyDoc</a> annotations (which you can add to the findBook&#8217;s method declaration) but currently it just does not.</p>
<p>To still have autocompletion you have two options:</p>
<ol>
<li> Temporarily instantiate a Book object in the code.
<pre name="code" class="python">
mybook = Book()
mybook = bookstore.findBook("foobar")
mybook. #--> now you have auto completion
</pre>
<p>This has the drawback, that if you forget to remove the first line before you finish coding an unneccessary Book instance will be created on every execution during runtime.</p>
<li> Use an assertion to ensure that the mybook variable contains an object of type Book
<pre name="code" class="python">
mybook = bookstore.findBook("foobar")
assert isinstance(mybook, Book)
mybook. #--> now you have auto completion
</pre>
</ol>
 <img src="http://sebthom.de/wp-content/plugins/feed-statistics.php?view=1&post_id=140" width="1" height="1" style="display: none;" /><hr />
<p><small>&copy; sebthom for <a href="http://sebthom.de">sebthom.de</a>, 2010. |
<a href="http://sebthom.de/140-leveraging-pydevs-auto-completion-indirectly-created-objects/lang/de/">Permalink</a> |
<a href="http://sebthom.de/140-leveraging-pydevs-auto-completion-indirectly-created-objects/lang/de/#comments">One comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://sebthom.de/140-leveraging-pydevs-auto-completion-indirectly-created-objects/lang/de/&amp;title=Leveraging PyDev&#8217;s auto completion for indirectly created objects">del.icio.us</a>
<br/>
Post tags: <a href="http://sebthom.de/tag/jython/" rel="nofollow tag">Jython</a>, <a href="http://sebthom.de/tag/pydev/" rel="nofollow tag">pydev</a>, <a href="http://sebthom.de/tag/pydoc/" rel="nofollow tag">pydoc</a>, <a href="http://sebthom.de/tag/python/" rel="nofollow tag">python</a>, <a href="http://sebthom.de/tag/rtype/" rel="nofollow tag">rtype</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://sebthom.de/140-leveraging-pydevs-auto-completion-indirectly-created-objects/feed/lang/de/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Comparing version numbers in Jython / Python</title>
		<link>http://sebthom.de/136-comparing-version-numbers-in-jython-pytho/lang/de/</link>
		<comments>http://sebthom.de/136-comparing-version-numbers-in-jython-pytho/lang/de/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 23:03:57 +0000</pubDate>
		<dc:creator>Sebastian Thomschke</dc:creator>
				<category><![CDATA[Jython]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://sebthom.de/?p=136</guid>
		<description><![CDATA[Here comes a function to compare version numbers of e.g. Maven artifacts in Jython / Python.

import re

def cmpver(vA, vB):
    """
    Compares two version number strings
    @param vA: first version string to compare
    @param vB: second version string to compare
    @author [...]]]></description>
			<content:encoded><![CDATA[<p>Here comes a function to compare version numbers of e.g. Maven artifacts in Jython / Python.</p>
<pre name="code" class="python">
import re

def cmpver(vA, vB):
    """
    Compares two version number strings
    @param vA: first version string to compare
    @param vB: second version string to compare
    @author <a href="http://sebthom.de/">Sebastian Thomschke</a>
    @return negative if vA < vB, zero if vA == vB, positive if vA > vB.

    Examples:
    >>> cmpver("0", "1")
    -1
    >>> cmpver("1", "0")
    1
    >>> cmpver("1", "1")
    0
    >>> cmpver("1.0", "1.0")
    0
    >>> cmpver("1.0", "1")
    0
    >>> cmpver("1", "1.0")
    0
    >>> cmpver("1.1.0", "1.0.1")
    1
    >>> cmpver("1.0.1", "1.1.1")
    -1
    >>> cmpver("0.3-SNAPSHOT", "0.3")
    -1
    >>> cmpver("0.3", "0.3-SNAPSHOT")
    1
    >>> cmpver("1.3b", "1.3c")
    -1
    >>> cmpver("1.14b", "1.3c")
    1
    """
    if vA == vB: return 0

    def num(s):
        if s.isdigit(): return int(s)
        return s

    seqA = map(num, re.findall('\d+|\w+', vA.replace('-SNAPSHOT', '')))
    seqB = map(num, re.findall('\d+|\w+', vB.replace('-SNAPSHOT', '')))

    # this is to ensure that 1.0 == 1.0.0 in cmp(..)
    lenA, lenB = len(seqA), len(seqB)
    for i in range(lenA, lenB): seqA += (0,)
    for i in range(lenB, lenA): seqB += (0,)

    rc = cmp(seqA, seqB)

    if rc == 0:
        if vA.endswith('-SNAPSHOT'): return -1
        if vB.endswith('-SNAPSHOT'): return 1
    return rc
</pre>
<p>Theoretically lines 43 &#8211; 49 could be written in a more compact way but using the short circuit evaluations (as below) lead to wrong results &#8211; at least in Jython 2.1:</p>
<pre name="code" class="python">
    seqa = map(lambda s: s.isdigit() and int(s) or s, re.findall('\d+|\w+', vA.replace('-SNAPSHOT', '')))
    seqb = map(lambda s: s.isdigit() and int(s) or s, re.findall('\d+|\w+', vB.replace('-SNAPSHOT', '')))
</pre>
 <img src="http://sebthom.de/wp-content/plugins/feed-statistics.php?view=1&post_id=136" width="1" height="1" style="display: none;" /><hr />
<p><small>&copy; sebthom for <a href="http://sebthom.de">sebthom.de</a>, 2009. |
<a href="http://sebthom.de/136-comparing-version-numbers-in-jython-pytho/lang/de/">Permalink</a> |
<a href="http://sebthom.de/136-comparing-version-numbers-in-jython-pytho/lang/de/#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://sebthom.de/136-comparing-version-numbers-in-jython-pytho/lang/de/&amp;title=Comparing version numbers in Jython / Python">del.icio.us</a>
<br/>
Post tags: <a href="http://sebthom.de/tag/jython/" rel="nofollow tag">Jython</a>, <a href="http://sebthom.de/tag/python/" rel="nofollow tag">python</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://sebthom.de/136-comparing-version-numbers-in-jython-pytho/feed/lang/de/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>getpass f&#252;r Jython</title>
		<link>http://sebthom.de/70-getpass-jython/lang/de/</link>
		<comments>http://sebthom.de/70-getpass-jython/lang/de/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 00:02:15 +0000</pubDate>
		<dc:creator>Sebastian Thomschke</dc:creator>
				<category><![CDATA[Jython]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://sebthom.de/?p=70</guid>
		<description><![CDATA[In meinem aktuellen Projekt entwickle ich u.a. verschiedene Jython basierte Kommandozeilenanwendungen. Einige davon erwarten die Eingabe von maskierten Passw&#246;rtern. Python stellt hierf&#252;r das getpass Modul bereit. Leider ist bisher keine entsprechende Implementierung f&#252;r Jython verf&#252;gbar.
Im folgenden ein passendes Modul, welches diese Funktionalit&#228;t bereitstellt. Es verwendet einen Mechanismus um die Passworteingabe in der Kommandozeile zu maskieren, [...]]]></description>
			<content:encoded><![CDATA[<p>In meinem aktuellen Projekt entwickle ich u.a. verschiedene Jython basierte Kommandozeilenanwendungen. Einige davon erwarten die Eingabe von maskierten Passw&ouml;rtern. Python stellt hierf&uuml;r das <a href="http://www.python.org/doc/lib/module-getpass.html" rel="nofollow" >getpass</a> Modul bereit. Leider ist bisher keine entsprechende Implementierung f&uuml;r Jython verf&uuml;gbar.</p>
<p>Im folgenden ein passendes Modul, welches diese Funktionalit&auml;t bereitstellt. Es verwendet einen Mechanismus um die Passworteingabe in der Kommandozeile zu maskieren, welcher hier beschrieben wurde <a href="http://java.sun.com/developer/technicalArticles/Security/pwordmask/" rel="nofollow" >http://java.sun.com/developer/technicalArticles/Security/pwordmask/</a>. Sollte Jython in Verbindung mit Java 6 oder h&ouml;her eingesetzt werden, so nutzt dieses Modul stattdessen die neue <a href="http://java.sun.com/javase/6/docs/api/java/io/Console.html#readPassword%28%29" rel="nofollow" >Console.readPassword()</a> Methode. Sollte das Modul in einer Umgebung laufen in welcher eine getpass Modulimplementierung verf&uuml;gbar ist, dann wird stattdessen an die entsprechende Methode im getpass Modul delegiert.</p>
<pre class="python" name="code"># ext_getpass.py
# @author Sebastian Thomschke, http://sebthom.de/
import thread, sys, time, os

# exposed methods:
__all__ = ["getpass","getuser"]

def __doMasking(stream):
    __doMasking.stop = 0
    while not __doMasking.stop:
        stream.write("b*")
        stream.flush()
        time.sleep(0.01)

def generic_getpass(prompt="Password: ", stream=None):
    if not stream:
        stream = sys.stderr
    prompt = str(prompt)
    if prompt:
        stream.write(prompt)
        stream.flush()
    thread.start_new_thread(__doMasking, (stream,))
    password = raw_input()
    __doMasking.stop = 1
    return password

def generic_getuser():
    for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
        usr = os.environ.get(name)
        if usr: return usr

def java6_getpass(prompt="Password: ", stream=None):
    if not stream:
        stream = sys.stderr
    prompt = str(prompt)
    if prompt:
        stream.write(prompt)
        stream.flush()

    from java.lang import System
    console = System.console()
    if console == None:
	    return generic_getpass(prompt, stream)
    else:
        return "".join(console.readPassword())

try:
    # trying to use Python's getpass implementation
    import getpass
    getpass = getpass.getpass
    getuser = getpass.getuser
except ImportError, e:
    getuser = generic_getuser

    # trying to use Java 6's Console.readPassword() implementation
    try:
        from java.io import Console
        getpass = java6_getpass
    except ImportError, e:
        # use the generic getpass implementation
        getpass = generic_getpass
</pre>
<p>Here is an usage example:</p>
<pre class="python" name="code">
import ext_getpass as getpass

pw = getpass.getpass("Please enter your password:")
print "The entered password was: " + pw
</pre>
 <img src="http://sebthom.de/wp-content/plugins/feed-statistics.php?view=1&post_id=70" width="1" height="1" style="display: none;" /><hr />
<p><small>&copy; sebthom for <a href="http://sebthom.de">sebthom.de</a>, 2008. |
<a href="http://sebthom.de/70-getpass-jython/lang/de/">Permalink</a> |
<a href="http://sebthom.de/70-getpass-jython/lang/de/#comments">One comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://sebthom.de/70-getpass-jython/lang/de/&amp;title=getpass f&uuml;r Jython">del.icio.us</a>
<br/>
Post tags: <a href="http://sebthom.de/tag/java/" rel="nofollow tag">Java</a>, <a href="http://sebthom.de/tag/jython/" rel="nofollow tag">Jython</a>, <a href="http://sebthom.de/tag/password/" rel="nofollow tag">password</a>, <a href="http://sebthom.de/tag/python/" rel="nofollow tag">python</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://sebthom.de/70-getpass-jython/feed/lang/de/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
