You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(38) |
Nov
(98) |
Dec
(58) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
(114) |
Feb
(123) |
Mar
(96) |
Apr
(66) |
May
(84) |
Jun
(72) |
Jul
(128) |
Aug
(126) |
Sep
(82) |
Oct
(80) |
Nov
(148) |
Dec
(55) |
| 2002 |
Jan
(137) |
Feb
(85) |
Mar
(118) |
Apr
(67) |
May
(71) |
Jun
(28) |
Jul
(69) |
Aug
(48) |
Sep
(83) |
Oct
(79) |
Nov
(54) |
Dec
(32) |
| 2003 |
Jan
(44) |
Feb
(47) |
Mar
(59) |
Apr
(57) |
May
(43) |
Jun
(45) |
Jul
(44) |
Aug
(39) |
Sep
(27) |
Oct
(62) |
Nov
(17) |
Dec
(23) |
| 2004 |
Jan
(41) |
Feb
(51) |
Mar
(38) |
Apr
(30) |
May
(25) |
Jun
(12) |
Jul
(11) |
Aug
(27) |
Sep
(16) |
Oct
(56) |
Nov
(23) |
Dec
(29) |
| 2005 |
Jan
(75) |
Feb
(82) |
Mar
(50) |
Apr
(77) |
May
(19) |
Jun
(104) |
Jul
(47) |
Aug
(42) |
Sep
(28) |
Oct
(143) |
Nov
(62) |
Dec
(13) |
| 2006 |
Jan
(20) |
Feb
(10) |
Mar
(59) |
Apr
(45) |
May
(25) |
Jun
(129) |
Jul
(162) |
Aug
(91) |
Sep
(15) |
Oct
(39) |
Nov
(186) |
Dec
(191) |
| 2007 |
Jan
(134) |
Feb
(140) |
Mar
(106) |
Apr
(77) |
May
(92) |
Jun
(63) |
Jul
(233) |
Aug
(102) |
Sep
(119) |
Oct
(63) |
Nov
(68) |
Dec
(32) |
| 2008 |
Jan
(69) |
Feb
(91) |
Mar
(129) |
Apr
(44) |
May
(18) |
Jun
(53) |
Jul
(50) |
Aug
(25) |
Sep
(11) |
Oct
(28) |
Nov
(67) |
Dec
(36) |
| 2009 |
Jan
(20) |
Feb
(24) |
Mar
(66) |
Apr
(53) |
May
(48) |
Jun
(48) |
Jul
(59) |
Aug
(82) |
Sep
(49) |
Oct
(30) |
Nov
(16) |
Dec
(16) |
| 2010 |
Jan
(52) |
Feb
(25) |
Mar
(36) |
Apr
(34) |
May
(14) |
Jun
(15) |
Jul
(14) |
Aug
(16) |
Sep
(23) |
Oct
(6) |
Nov
(4) |
Dec
(5) |
| 2011 |
Jan
(4) |
Feb
(22) |
Mar
(45) |
Apr
(9) |
May
(8) |
Jun
(13) |
Jul
(12) |
Aug
(4) |
Sep
(6) |
Oct
(10) |
Nov
(21) |
Dec
(5) |
| 2012 |
Jan
(6) |
Feb
(9) |
Mar
(25) |
Apr
(6) |
May
(4) |
Jun
(23) |
Jul
(6) |
Aug
(18) |
Sep
(21) |
Oct
(34) |
Nov
(19) |
Dec
(25) |
| 2013 |
Jan
(8) |
Feb
(34) |
Mar
(35) |
Apr
(4) |
May
(11) |
Jun
(4) |
Jul
(7) |
Aug
(5) |
Sep
(20) |
Oct
(12) |
Nov
(11) |
Dec
(7) |
| 2014 |
Jan
(10) |
Feb
(18) |
Mar
(50) |
Apr
(26) |
May
(53) |
Jun
(21) |
Jul
(12) |
Aug
(39) |
Sep
(43) |
Oct
(26) |
Nov
(8) |
Dec
(6) |
| 2015 |
Jan
(18) |
Feb
(32) |
Mar
(31) |
Apr
(42) |
May
(38) |
Jun
(13) |
Jul
(6) |
Aug
(11) |
Sep
(29) |
Oct
(25) |
Nov
(10) |
Dec
(11) |
| 2016 |
Jan
(24) |
Feb
(12) |
Mar
(13) |
Apr
(15) |
May
(22) |
Jun
(8) |
Jul
(12) |
Aug
(25) |
Sep
(8) |
Oct
(6) |
Nov
(13) |
Dec
(7) |
| 2017 |
Jan
(6) |
Feb
(29) |
Mar
(32) |
Apr
(8) |
May
(82) |
Jun
(42) |
Jul
(20) |
Aug
(17) |
Sep
(27) |
Oct
(14) |
Nov
(22) |
Dec
(6) |
| 2018 |
Jan
(12) |
Feb
(9) |
Mar
(22) |
Apr
(19) |
May
(14) |
Jun
(9) |
Jul
(9) |
Aug
(22) |
Sep
(22) |
Oct
(12) |
Nov
(13) |
Dec
(8) |
| 2019 |
Jan
(22) |
Feb
(3) |
Mar
(30) |
Apr
(20) |
May
(20) |
Jun
(6) |
Jul
(15) |
Aug
(25) |
Sep
(11) |
Oct
(24) |
Nov
(11) |
Dec
(6) |
| 2020 |
Jan
(9) |
Feb
(12) |
Mar
(29) |
Apr
(10) |
May
(22) |
Jun
(11) |
Jul
(15) |
Aug
(5) |
Sep
(6) |
Oct
(7) |
Nov
(7) |
Dec
(13) |
| 2021 |
Jan
(21) |
Feb
(5) |
Mar
(5) |
Apr
(6) |
May
(10) |
Jun
(7) |
Jul
(6) |
Aug
(8) |
Sep
(5) |
Oct
(9) |
Nov
(5) |
Dec
(6) |
| 2022 |
Jan
(5) |
Feb
(4) |
Mar
(8) |
Apr
(6) |
May
(5) |
Jun
(5) |
Jul
(10) |
Aug
(6) |
Sep
(7) |
Oct
(4) |
Nov
(4) |
Dec
(6) |
| 2023 |
Jan
(5) |
Feb
(5) |
Mar
(6) |
Apr
(4) |
May
(5) |
Jun
(6) |
Jul
(5) |
Aug
(5) |
Sep
(5) |
Oct
(5) |
Nov
(7) |
Dec
(8) |
| 2024 |
Jan
(3) |
Feb
(1) |
Mar
|
Apr
(2) |
May
|
Jun
(1) |
Jul
(1) |
Aug
(4) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
| 2025 |
Jan
|
Feb
(2) |
Mar
|
Apr
(1) |
May
|
Jun
(1) |
Jul
|
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
|
From: David S. <ds...@al...> - 2001-02-02 15:19:56
|
> servlet.init(getServletConfig()); This call was added to the version of PyServlet that I posted to jpython-interest back in May last year. Chris Gokey and I had a discussion around that time, and upgraded the then currently available PyServlet. Maybe we should try and merge that version with whatever people are using these days? Dave. |
|
From: <bc...@wo...> - 2001-02-02 15:11:01
|
[Brian Zhou] >Hello list, > >Following http://groups.yahoo.com/group/jpython/message/3714 I succeeded >making servlet running under PyServlet wrapper/handler on win2k tomcat3.2.1. >So far so good, I can run simple script like: > >import sys, java, javax > >class hello(javax.servlet.http.HttpServlet): > def doGet(self, req, res): > res.setContentType("text/html"); > out = res.getOutputStream() > out.println("""\ ><html> ><head><title>Hello World</title></head> ><body>Hello World! ><P> >current server time is: %s ></P> ></body> ></html> >""" % (java.util.Date())) > out.close() > return > >Or even dynamicly generate PNG graph thanks to the new javax.imagio package >from Sun. I don't expect any difficulty hooking up with database using JDBC. > >However, when trying to port SnoopServlet from java to jython, I found that >PyServlet really doesn't handover any instant variables to the jython >HttpServlet subclass except (request, response). So > > enum = self.getInitParameterNames() > >will got a NullPointerException. Any operation involve self.attribute like >self.getServletContext() will also fail. I don't think jythonc compiled >classes will have this problem because the jython servlet handle service() >directly bypassing PyServlet. > >So my questions are: > >1. Am I missing anything? Any misunderstanding of the API? I'm no expert on servlets, but I think the servlet must be initialized somehow. By adding servlet.init(getServletConfig()); to PyServlet.loadServlet(), I managed to avoid the NPE in getInitParameterNames(). regards, finn |
|
From: <bc...@wo...> - 2001-02-02 13:08:48
|
[Ype Kingma]
>Dear developers,
>
>Tried to report this via soureforge but the bugid bug
>is still there.
>In jython 2.0 a3 I have this:
>
>'aaa'.count('a',0,2) == 2, ok, and
>
>'ababab'.count('ab',0,5) == 3, should be 2 (CPython also gives 2).
>
>'defdefdef.count('def',0,8) == 3, should also be 2.
>
>Using blackdown java 1.3, powerpc, no jit.
>
>You might want to add sth like this to test_string.py,
>count() is untested there:
>
> test('count', 'aaa', 3, 'a')
> test('count', 'aaa', 2, 'a', 0, 2)
> test('count', 'ababab', 3, 'ab', 0)
> test('count', 'ababab', 2, 'ab', 0, 5)
> test('count', 'ababab', 2, 'ab', 1)
> test('count', 'ababab', 2, 'ab', 1, 6)
> test('count', 'ababab', 0, 'abc')
> test('count', 'ababab', 0, '')
Thanks, I have added this (except for the last test which should return
7 according to CPython).
regards,
finn
|
|
From: <bc...@wo...> - 2001-02-02 13:08:20
|
[Ype Kingma]
>"""
>stringbuffer.py: mutable string built on java.lang.StringBuffer.
>
>The idea is to save as many string object creations as possible
>while still be about as fast as string's, when implemented
>in Java. This python module is intended as a prototype.
>
>
>The itch:
>
>I needed java.lang.StringBuffer functionality in jython
>on the receiving side of a socket.
>I grew tired of writing:
> buf += sock.recv(maxSize)
>which creates a new buf everytime
>sock.recv(maxSize) is called. Note that sock.recv()
>may return as little as it likes, depending on
>network traffic conditions.
>The alternative of keeping a list of received
>strings did not really appeal to me.
>
>
>The questions:
>
>- This may have been done umpteen times before, when so
> could someone please tell me?
There is a UserString.MutableString class, but it have a diffrent
purpose. A module that wraps a StringBuffer could be usefull as a
standard module.
>- I added the standard string methods.
> Only when these originally return a string I have them put
> the result back into the stringbuffer.
> Methods that return something else work as if they
> were used on a string.
> Is this the right approach? Esp. for split() and friends?
Hard to say. If you haven't already, you can take a look at which
methods in UserString.UserString that returns strings and which that
return UserStrings.
>- I don't know whether I handled python default arguments
> correctly, eg:
>
> def count(self, sub, start = None, end = None):
> if start == None:
> if end == None:
> return str(self).count(sub)
> else:
> return str(self).count(sub, 0, end)
> elif end == None:
> return str(self).count(sub, start)
> else:
> return str(self).count(sub, start, end)
>
> (str(self) should disappear in the java version ...)
That is too much work. UserString simply does:
def count(self, sub, start=0, end=sys.maxint):
return self.data.count(sub, start, end)
Another way to deduce the default values are by looking at the PyString
sources for count(..):
public int count(String sub) {
return count(sub, 0, string.length());
}
public int count(String sub, int start) {
return count(sub, start, string.length());
}
public int count(String sub, int start, int end) {
...
}
The last count method will validate the start/end indexes so the
sys.maxint trick also works.
>- Is an extend() method needed? It is marked as experimental
> in my python 2.0 documentation.
Hard to say. The [].extend() is now used by standard python library so I
think it is safe to say that it will remain. I see no problem with
adding it to stringbuffer and marking it non-experimental.
>- Should slicing be allowed with other steps than 1?
No. I don't see much use for it. After all, strings are not meant as
general sequence. We have real lists for that.
>- pop() also works for slices, is that ok.?
I don't see much use for that either. It's a minor thing.
>Aside: in the sort() method this line gives an internal compiler error:
> l = [self[i] for i in range(len(self))] # internal compiler error:
>name i (jython2.0a3)
>Why?
Because there was an internal compiler error in 2.0alpha3 <wink>. It was
a bug where fast locals in listcomps was not correctly detected.
OTOH, sorting a stringbuffer is bogus. Cute but mostly useless. I'd
rather avoid adding a sort method.
I modified a copy if CPython's test_userstring.py. You should try it, it
caught some typos. It must be run from CPython's ./Lib/test directory.
#!/usr/bin/env python
import sys, string
from test_support import verbose
import string_tests
# UserString is a wrapper around the native builtin string type.
# UserString instances should behave similar to builtin string objects.
# The test cases were in part derived from 'test_string.py'.
from stringbuffer import stringbuffer
if __name__ == "__main__":
verbose = 0
tested_methods = {}
def test(methodname, input, *args):
global tested_methods
tested_methods[methodname] = 1
if verbose:
print '%s.%s(%s) ' % (input, methodname, args),
u = stringbuffer(input)
objects = [input, u, stringbuffer(u)]
res = [""] * 3
for i in range(3):
object = objects[i]
try:
f = getattr(object, methodname)
res[i] = apply(f, args)
except:
res[i] = sys.exc_type
if res[0] != res[1]:
if verbose:
print 'no'
print `input`, f, `res[0]`, "<>", `res[1]`
else:
if verbose:
print 'yes'
if res[1] != res[2]:
if verbose:
print 'no'
print `input`, f, `res[1]`, "<>", `res[2]`
else:
if verbose:
print 'yes'
string_tests.run_method_tests(test)
regards,
finn
|
|
From: <bc...@wo...> - 2001-02-02 13:05:12
|
[Vallish M.N] >sir, > I want to know that how should i copy the whole python tutorial at >one go,(i.e without doing cut and paste everytime)? >And i also want to know that is this tutorials are available in Pdf >format.If yes then from where shall I get that. http://www.python.org/doc/current/download.html >Also are Python and Jpython >are different or same(i.e the tutorials for python and Jpython are same or >different)? There are some difference: http://www.jython.org/docs/differences.html but the Python tutorial covers both implementations. regards, finn |
|
From: Vallish M.N <va...@ka...> - 2001-02-02 07:19:57
|
sir,
I want to know that how should i copy the whole python tutorial at
one go,(i.e without doing cut and paste everytime)?
And i also want to know that is this tutorials are available in Pdf
format.If yes then from where shall I get that.Also are Python and Jpython
are different or same(i.e the tutorials for python and Jpython are same or
different)?
Please send the reply of these questions as soon as possible?
My Email Id
va...@ka...
Thankyou,
vallish
|
|
From: Brian Z. <bri...@ya...> - 2001-02-02 03:23:24
|
With the changes I made, it works great now. Here are the two classes I
changed:
pyservlet.PyHandler in the place of the old PyServlet
pyservlet.HandlerAwareHttpServlet
The same handler can deal with both 1) jython servlet derived from
HttpServlet and 2) jython servlet derived from HandlerAwareHttpServlet.
Fortunately most info is from request, so only when you need to port
SnoopServlet do you need to use 2.
I also send this to the jython-dev list in hoping that in future
release, we can have servlet support built-in. I view this as one of the
big strength of using jython, if JSP is mod_php to apache, we have the
equivalent of mod_python now. JDBC, XMLC, imageio, the possiblilities
are endless.
Following are the two java files and some sample jython servlet scripts. I
love it! Thank you
jython developers.
/Brian
// pyservlet/HandlerAwareHttpServlet.java
package pyservlet;
import javax.servlet.http.*;
/**
*
* @author <a href="mailto:bri...@ya...">Brian Zhou</a>
*/
public abstract class HandlerAwareHttpServlet extends HttpServlet {
protected HttpServlet theHandler = null;
public void setHandler(HttpServlet aHandler) {
this.theHandler = aHandler;
}
public HttpServlet getHandler() {
return this.theHandler;
}
}
// pyservlet/PyHandler.java
package pyservlet;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.python.util.PythonInterpreter;
import org.python.core.*;
/**
* This servlet is used to tell the if the Apache JServ installation was
* successful.
*
* @author <a href="mailto:stefano@a...">Stefano Mazzocchi</a>
*/
public class PyHandler extends HttpServlet {
static Hashtable servlets = new Hashtable(); // Cache for HttpServlet
static Hashtable dates = new Hashtable(); // Timestamps for Cache
entries
PythonInterpreter interp = new PythonInterpreter();
public void service (ServletRequest req, ServletResponse res)
throws ServletException, IOException
{
HttpServlet servlet =
getServlet(getServletContext().getRealPath(
((HttpServletRequest)req).getServletPath()) );
if (servlet != null) {
if (servlet instanceof HandlerAwareHttpServlet) {
((HandlerAwareHttpServlet) servlet).setHandler(this);
}
servlet.service(req, res);
}
}
HttpServlet getServlet(String path)
throws ServletException, IOException
{
Long date = (Long) dates.get(path);
if (date != null) { // Check for cache validity
File file = new File(path);
if (date.longValue() < file.lastModified()) // Cache invalid
return (loadServlet(path)); // Reload servlet
else
return ((HttpServlet) servlets.get(path));
} else {
return (loadServlet(path)); // Not in cache, load servlet
}
}
HttpServlet loadServlet(String path)
throws ServletException, IOException
{
HttpServlet servlet = null;
File file = new File(path);
// Extract servlet name from path (strip ".../" and ".py")
int start = path.lastIndexOf(System.getProperty("file.separator"));
if (start < 0)
start = 0;
else
start++;
int end = path.lastIndexOf(".py");
if (end < 0 || end <= start)
end = path.length();
try { // Create servlet
interp.execfile(path);
PyObject pyServlet = interp.eval(path.substring(start,
end)+"()");
servlet =
(HttpServlet) pyServlet.__tojava__(
Class.forName("javax.servlet.http.HttpServlet"));
}
catch (PyException e) {
System.err.println(e);
throw new ServletException("Could not create Jython
servlet");
}
catch (ClassNotFoundException e) {
System.err.println(e);
throw new ServletException("Could not create Jython
servlet");
}
servlets.put(path, servlet); // Add servlet to
cache
dates.put(path, new Long(file.lastModified())); // Add timestamp
return (servlet);
}
}
# hello.py
import sys, java, javax
class hello(javax.servlet.http.HttpServlet):
def doGet(self, req, res):
res.setContentType("text/html");
out = res.getOutputStream()
out.println("""\
<html>
<head><title>Hello World</title></head>
<body>Hello World!
<P>
current server time is: %s
</P>
</body>
</html>
""" % (java.util.Date()))
out.close()
return
# titles.py
import java, javax
class titles(javax.servlet.http.HttpServlet):
def doGet(self, request, response):
response.setContentType("text/plain")
out = response.getOutputStream()
self.dbTitles(out)
out.close()
return
def dbTitles(self, out):
server, db = "ncv-dev2", "pubs"
usr, passwd = "sa", ""
driver = "com.inet.tds.TdsDriver"
port = 1433
url = "jdbc:inetdae:" + server + ":" + `port` + "?database=" + db
java.lang.Class.forName(driver).newInstance()
conn = java.sql.DriverManager.getConnection(url, usr, passwd)
query = "select title, price, ytd_sales, pubdate from titles"
stmt = conn.createStatement()
if stmt.execute(query):
rs = stmt.getResultSet()
while rs and rs.next():
out.println(rs.getString("title"))
if rs.getObject("price"):
out.println("%2.2f" % rs.getFloat("price"))
else:
out.println("null")
if rs.getObject("ytd_sales"):
out.println(rs.getInt("ytd_sales"))
else:
out.println("null")
out.println(rs.getTimestamp("pubdate").toString())
out.println()
stmt.close()
conn.close()
# snoop.py
from pyservlet import HandlerAwareHttpServlet
class snoop(HandlerAwareHttpServlet):
def doGet(self, request, response):
out = response.getOutputStream()
response.setContentType("text/plain");
out.print("""\
Snoop Servlet
""")
out.print("""\
Servlet init parameters:
""")
enum = self.getHandler().getInitParameterNames()
while enum.hasMoreElements():
key = enum.nextElement()
value = self.getInitParameter(key)
out.print("""\
%s = %s
""" % (key, value))
out.print("""\
Context init parameters:
""")
context = self.getHandler().getServletContext()
enum = context.getInitParameterNames()
while enum.hasMoreElements():
key = enum.nextElement()
value = context.getInitParameter(key)
out.print("""\
%s = %s
""" % (key, value))
out.print("""\
Context attributes:
""")
context = self.getHandler().getServletContext()
enum = context.getAttributeNames()
while enum.hasMoreElements():
key = enum.nextElement()
value = context.getAttribute(key)
out.print("""\
%s = %s
""" % (key, value))
out.print("""\
Request attributes:
""")
enum = request.getAttributeNames()
while enum.hasMoreElements():
key = enum.nextElement()
value = request.getAttribute(key)
out.print("""\
%s = %s
""" % (key, value))
out.print("""\
Servlet Name: %s
Protocol: %s
Scheme: %s
Server Name: %s
Server Port: %s
Server Info: %s
Remote Addr: %s
Remote Host: %s
Character Encoding: %s
Content Length: %s
Content Type: %s
Locale: %s
Default Response Buffer Size: %s
""" % (
self.getHandler().getServletName(),
request.getProtocol(),
request.getScheme(),
request.getServerName(),
request.getServerPort(),
self.getHandler().getServletContext().getServerInfo(),
request.getRemoteAddr(),
request.getRemoteHost(),
request.getCharacterEncoding(),
request.getContentLength(),
request.getContentType(),
request.getLocale(),
response.getBufferSize()
))
out.print("""\
Parameter names in this request:
""")
enum = request.getParameterNames()
while enum.hasMoreElements():
key = enum.nextElement()
values = request.getParameterValues(key)
out.print(" '%s' = " % key)
for value in values:
out.print("'%s' " % value)
out.println()
out.print("""\
Headers in this request:
""")
enum = request.getHeaderNames()
while enum.hasMoreElements():
key = enum.nextElement()
value = request.getHeader(key)
out.print("""\
%s = %s
""" % (key, value))
out.print("""\
Cookies in this request:
""")
cookies = request.getCookies()
for cookie in cookies:
out.print("""\
%s = %s
""" % (cookie.getName(), cookie.getValue()))
out.print("""\
Request Is Secure: %s
Auth Type: %s
HTTP Method: %s
Remote User: %s
Request URI: %s
Context Path: %s
Servlet Path: %s
Path Info: %s
Path Trans: %s
Query String: %s
""" % (
request.isSecure(),
request.getAuthType(),
request.getMethod(),
request.getRemoteUser(),
request.getRequestURI(),
request.getContextPath(),
request.getServletPath(),
request.getPathInfo(),
request.getPathTranslated(),
request.getQueryString()
))
session = request.getSession()
out.print("""\
Requested Session Id: %s
Current Session Id: %s
Session Created Time: %s
Session Last Accessed Time: %s
Session Max Inactive Interval Seconds: %d
""" % (
request.getRequestedSessionId(),
session.getId(),
session.getCreationTime(),
session.getLastAccessedTime(),
session.getMaxInactiveInterval()
))
out.print("""\
Session values:
""")
names = session.getAttributeNames()
while names.hasMoreElements():
name = names.nextElement()
out.println(" '%s' = '%s'" % (name,
session.getAttribute(name)))
out.close()
return
----- Original Message -----
From: "Brian Zhou" <bri...@ya...>
To: <jyt...@li...>
Cc: <jyt...@li...>
Sent: Wednesday, January 31, 2001 9:34 AM
Subject: [Jython-users] servlet problem self.getInitParameterNames()
under PyServlet wrapper
> Hello list,
>
> Following http://groups.yahoo.com/group/jpython/message/3714 I
succeeded
> making servlet running under PyServlet wrapper/handler on win2k
tomcat3.2.1.
> So far so good, I can run simple script like:
>
> import sys, java, javax
>
> class hello(javax.servlet.http.HttpServlet):
> def doGet(self, req, res):
> res.setContentType("text/html");
> out = res.getOutputStream()
> out.println("""\
> <html>
> <head><title>Hello World</title></head>
> <body>Hello World!
> <P>
> current server time is: %s
> </P>
> </body>
> </html>
> """ % (java.util.Date()))
> out.close()
> return
>
> Or even dynamicly generate PNG graph thanks to the new javax.imagio
package
> from Sun. I don't expect any difficulty hooking up with database using
JDBC.
>
> However, when trying to port SnoopServlet from java to jython, I found
that
> PyServlet really doesn't handover any instant variables to the jython
> HttpServlet subclass except (request, response). So
>
> enum = self.getInitParameterNames()
>
> will got a NullPointerException. Any operation involve self.attribute
like
> self.getServletContext() will also fail. I don't think jythonc
compiled
> classes will have this problem because the jython servlet handle
service()
> directly bypassing PyServlet.
>
> So my questions are:
>
> 1. Am I missing anything? Any misunderstanding of the API?
> 2. Any way around? Anyone got a better PyServlet?
> 3. If I'm the first one got bitten, any idea how we may overcome this
> problem?
>
> Seeing the power of dynamic python scripting at work (instant feedback
> without re-compiling), I really appreciate what have been done so far,
and
> want to get it going. Here are some of my ideas:
>
> 1. We can have two seperate subclasses of HttpServlet in java:
> one possibly named ServletPyHandler, doing what PyServlet
currently is
> doing, dispatching service() calls to jython servlet;
> the other JyServlet being superclass of all jython servlets, with
> constructor JyServlet(ServletPyHandler), so JyServlet always has a ref
to
> the ServletPyHandler instance;
> The downside of this approach is that now jythonc compiled servlet and
> dynamically interpreted servlet have to be written differently.
>
> 2. Have ServletPyHandler do somthing to the jython servlet class right
> before dispatching service() call, so that inside jython servlet,
later when
> messages like self.getInitParameterNames() will be redirected back to
> ServletPyHandler.
>
> TIA for any ideas,
>
> /Brian
>
>
>
> _______________________________________________
> Jython-users mailing list
> Jyt...@li...
> http://lists.sourceforge.net/lists/listinfo/jython-users
|
|
From: Brian Z. <bri...@ya...> - 2001-02-01 20:56:18
|
It works great with the change I made. Attached are the two classes I
changed:
pyservlet.PyHandler in the place of the old PyServlet
pyservlet.HandlerAwareHttpServlet
The same handler can deal with both 1) jython servlet derived from
HttpServlet and 2) jython servlet derived from HandlerAwareHttpServlet.
Fortunately most info is from request, so only when you need to port
SnoopServlet do you need to use 2.
I also send this to the jython-dev list in hoping that in future
release, we can have servlet support built-in. I view this as one of the
big strength of using jython, if JSP is mod_php to apache, we have the
equivalent of mod_python now. JDBC, XMLC, imageio, the possiblilities
are endless.
Following are some sample jython servlet scripts. I love it! Thank you
jython developers.
/Brian
# hello.py
import sys, java, javax
class hello(javax.servlet.http.HttpServlet):
def doGet(self, req, res):
res.setContentType("text/html");
out = res.getOutputStream()
out.println("""\
<html>
<head><title>Hello World</title></head>
<body>Hello World!
<P>
current server time is: %s
</P>
</body>
</html>
""" % (java.util.Date()))
out.close()
return
# titles.py
import java, javax
class titles(javax.servlet.http.HttpServlet):
def doGet(self, request, response):
response.setContentType("text/plain")
out = response.getOutputStream()
self.dbTitles(out)
out.close()
return
def dbTitles(self, out):
server, db = "ncv-dev2", "pubs"
usr, passwd = "sa", ""
driver = "com.inet.tds.TdsDriver"
port = 1433
url = "jdbc:inetdae:" + server + ":" + `port` + "?database=" + db
java.lang.Class.forName(driver).newInstance()
conn = java.sql.DriverManager.getConnection(url, usr, passwd)
query = "select title, price, ytd_sales, pubdate from titles"
stmt = conn.createStatement()
if stmt.execute(query):
rs = stmt.getResultSet()
while rs and rs.next():
out.println(rs.getString("title"))
if rs.getObject("price"):
out.println("%2.2f" % rs.getFloat("price"))
else:
out.println("null")
if rs.getObject("ytd_sales"):
out.println(rs.getInt("ytd_sales"))
else:
out.println("null")
out.println(rs.getTimestamp("pubdate").toString())
out.println()
stmt.close()
conn.close()
----- Original Message -----
From: "Brian Zhou" <bri...@ya...>
To: <jyt...@li...>
Cc: <jyt...@li...>
Sent: Wednesday, January 31, 2001 9:34 AM
Subject: [Jython-users] servlet problem self.getInitParameterNames()
under PyServlet wrapper
> Hello list,
>
> Following http://groups.yahoo.com/group/jpython/message/3714 I
succeeded
> making servlet running under PyServlet wrapper/handler on win2k
tomcat3.2.1.
> So far so good, I can run simple script like:
>
> import sys, java, javax
>
> class hello(javax.servlet.http.HttpServlet):
> def doGet(self, req, res):
> res.setContentType("text/html");
> out = res.getOutputStream()
> out.println("""\
> <html>
> <head><title>Hello World</title></head>
> <body>Hello World!
> <P>
> current server time is: %s
> </P>
> </body>
> </html>
> """ % (java.util.Date()))
> out.close()
> return
>
> Or even dynamicly generate PNG graph thanks to the new javax.imagio
package
> from Sun. I don't expect any difficulty hooking up with database using
JDBC.
>
> However, when trying to port SnoopServlet from java to jython, I found
that
> PyServlet really doesn't handover any instant variables to the jython
> HttpServlet subclass except (request, response). So
>
> enum = self.getInitParameterNames()
>
> will got a NullPointerException. Any operation involve self.attribute
like
> self.getServletContext() will also fail. I don't think jythonc
compiled
> classes will have this problem because the jython servlet handle
service()
> directly bypassing PyServlet.
>
> So my questions are:
>
> 1. Am I missing anything? Any misunderstanding of the API?
> 2. Any way around? Anyone got a better PyServlet?
> 3. If I'm the first one got bitten, any idea how we may overcome this
> problem?
>
> Seeing the power of dynamic python scripting at work (instant feedback
> without re-compiling), I really appreciate what have been done so far,
and
> want to get it going. Here are some of my ideas:
>
> 1. We can have two seperate subclasses of HttpServlet in java:
> one possibly named ServletPyHandler, doing what PyServlet
currently is
> doing, dispatching service() calls to jython servlet;
> the other JyServlet being superclass of all jython servlets, with
> constructor JyServlet(ServletPyHandler), so JyServlet always has a ref
to
> the ServletPyHandler instance;
> The downside of this approach is that now jythonc compiled servlet and
> dynamically interpreted servlet have to be written differently.
>
> 2. Have ServletPyHandler do somthing to the jython servlet class right
> before dispatching service() call, so that inside jython servlet,
later when
> messages like self.getInitParameterNames() will be redirected back to
> ServletPyHandler.
>
> TIA for any ideas,
>
> /Brian
>
>
>
> _______________________________________________
> Jython-users mailing list
> Jyt...@li...
> http://lists.sourceforge.net/lists/listinfo/jython-users
>
|
|
From: Ype K. <yk...@xs...> - 2001-02-01 20:40:42
|
Dear developers,
Tried to report this via soureforge but the bugid bug
is still there.
In jython 2.0 a3 I have this:
'aaa'.count('a',0,2) == 2, ok, and
'ababab'.count('ab',0,5) == 3, should be 2 (CPython also gives 2).
'defdefdef.count('def',0,8) == 3, should also be 2.
Using blackdown java 1.3, powerpc, no jit.
You might want to add sth like this to test_string.py,
count() is untested there:
test('count', 'aaa', 3, 'a')
test('count', 'aaa', 2, 'a', 0, 2)
test('count', 'ababab', 3, 'ab', 0)
test('count', 'ababab', 2, 'ab', 0, 5)
test('count', 'ababab', 2, 'ab', 1)
test('count', 'ababab', 2, 'ab', 1, 6)
test('count', 'ababab', 0, 'abc')
test('count', 'ababab', 0, '')
Good luck, thanks for your time,
Ype
Patch against PyString.java (the first bit is only for speeding up a little,
I have to say though that it has not even been compiled):
1045,1048c1045,1048
< if (end < 0) {
< end += n;
< } else if (end > n)
< end = n;
---
> if (end < 0)
> end = n+end;
> if (end > n)
> end = n;
1053c1053
< int lastcheck = end - slen;
---
> //end = end-slen;
1056c1056
< while (start <= lastcheck) {
---
> while (start < end) {
1058c1058
< if (index == -1)
---
> if (index >= end || index == -1)
|
|
From: Samuele P. <pe...@in...> - 2001-02-01 14:40:17
|
Some documentation about the java reload (experimental) simple support - that comes with jython 2.0 - is now available online: http://www.jython.org/docs/jreload.html We encourage everybody interested in java class reloading from jython, to read the doc and to try 'jreload'. Feedback (to jython-dev) and bug reports are welcome. The jreload.py file that comes with jython 2.0 contains a little typo (actual CVS version has been fixed): --- jreload.typo Thu Feb 1 15:14:43 2001 +++ jreload.py Thu Feb 1 15:13:12 2001 @@ -84,7 +84,7 @@ return _Unload(ls) def makeLoadSet(name,path): - if sys.modules.has_key('name'): return sys.modules[name] + if sys.modules.has_key(name): return sys.modules[name] sys.modules[name] = ls = LoadSet(name,path) return ls Thanks to Thomas Breuel for reporting this. Cheers, the jython-developers PS: the cited example files are now in the CVS tree. |
|
From: ±è»ó¿µ <reb...@ha...> - 2001-02-01 06:10:17
|
Dear Sir. I have a question about applet programming with jython.=20 I make a sample program as you know that just print=20 "hello world" It works well on jython. but, It donesn't work that compiled with jythonc. It just display gray square box in explorer. It's very simple applet program.. I also tested that sample code in your homepage. However, the result is same.. I compile the program like that jython --core --d --jar hello.jar hello.py my enviroment : windows 98 / 2000=20 pentium 3 700 jdk 1.3.0_01 jython 2.0 How can I do for that? =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =BF=EC=B8=AE =C0=CE=C5=CD=B3=DD, Daum =C6=F2=BB=FD =BE=B2=B4=C2 =B9=AB=B7=E1 E-mail =C1=D6=BC=D2 =C7=D1=B8=DE=C0= =CF=B3=DD =C1=F6=B1=B8=C3=CC =C7=D1=B1=DB =B0=CB=BB=F6=BC=AD=BA=F1=BD=BA Daum FIREB= ALL http://www.daum.net |
|
From: Samuele P. <pe...@in...> - 2001-02-01 02:22:13
|
Hi. > You can add it as ./Doc/jreload.ht. The links to the demo sources should > not contain any path, eg: <a href="Version.java">. The built script for > the Doc directory can then ensure that lastest version from Demo is used > when the documentation is generated for both local installation and the > web site. Done. I don't know if is the case to add links to this from the main doc index file: * simple java classes reload (experimental) support => jreload.html * java classes unloading and internalTablesImpl option => jreload.html#unload regards, Samuele Pedroni. |
|
From: Adam B. <ada...@gb...> - 2001-01-31 22:50:34
|
I'm posting this to the list because the bug report page gives me: = error getting bug_id all the time. " Odd problem. Jython console started with no parameters fails with an "IOError - File not found -". However the problem goes away when the interpreter is started with a script param or started with the -v = option. Compaq Tru64 Unix uname -a OSF1 supanova V4.0 1229 alpha=20 Trace / config prompt>jython Traceback (innermost last): (no code object) at line 0 IOError: File not found - (No such file or directory) supanova /usr/users/supastar/gway/bin =3D> jython -v import: 'exceptions' as org.python.core.exceptions in builtin modules Jython 2.0 on java1.2.2-1 (JIT: jit_122) import: 'site' as /usr/local/jython-20/Lib/site.py import: 'sys' as sys in builtin modules import: 'os' as org.python.modules.os in builtin modules import: 'javaos' as /usr/local/jython-20/Lib/javaos.py import: 'java' as java package import: 'File' as java class import: 'javapath' as /usr/local/jython-20/Lib/javapath.py import: 'System' as java class import: 'sitecustomize' not found (ImportError) Type "copyright", "credits" or "license" for more information. >>> ^D supanova /usr/users/supastar/gway/bin =3D> java -fullversion java full version "J2SDK.v.1.2.2:09/30/1999-19:00" supanova /usr/users/supastar/gway/bin =3D> whence java /usr/opt/java122/bin/java supanova /usr/users/supastar/gway/bin =3D> java -version java version "1.2.2-1" Classic VM (build J2SDK.v.1.2.2:09/30/1999-19:00, native threads, = jit_122) =20 I've also tried it with jdk118 on this platform. I only see the = problem on this platform. It looks like the "-" convention for stdin is not being recognised. I should be able test patches / configuration changes / suggestions if you don't have access to this env, though I haven't got = a lot of time to give to it. Any suggested starting points? -- Adam Burke www.gbst.com =BA The document is also available in oil-based toner on flattened dead trees by sending US$10 (or equivalent) to the editor (email first to check currency and postal address). -- Frequently Asked Questions about the Extensible Markup Language, |
|
From: Brian Z. <bri...@ya...> - 2001-01-31 17:34:38
|
Hello list, Following http://groups.yahoo.com/group/jpython/message/3714 I succeeded making servlet running under PyServlet wrapper/handler on win2k tomcat3.2.1. So far so good, I can run simple script like: import sys, java, javax class hello(javax.servlet.http.HttpServlet): def doGet(self, req, res): res.setContentType("text/html"); out = res.getOutputStream() out.println("""\ <html> <head><title>Hello World</title></head> <body>Hello World! <P> current server time is: %s </P> </body> </html> """ % (java.util.Date())) out.close() return Or even dynamicly generate PNG graph thanks to the new javax.imagio package from Sun. I don't expect any difficulty hooking up with database using JDBC. However, when trying to port SnoopServlet from java to jython, I found that PyServlet really doesn't handover any instant variables to the jython HttpServlet subclass except (request, response). So enum = self.getInitParameterNames() will got a NullPointerException. Any operation involve self.attribute like self.getServletContext() will also fail. I don't think jythonc compiled classes will have this problem because the jython servlet handle service() directly bypassing PyServlet. So my questions are: 1. Am I missing anything? Any misunderstanding of the API? 2. Any way around? Anyone got a better PyServlet? 3. If I'm the first one got bitten, any idea how we may overcome this problem? Seeing the power of dynamic python scripting at work (instant feedback without re-compiling), I really appreciate what have been done so far, and want to get it going. Here are some of my ideas: 1. We can have two seperate subclasses of HttpServlet in java: one possibly named ServletPyHandler, doing what PyServlet currently is doing, dispatching service() calls to jython servlet; the other JyServlet being superclass of all jython servlets, with constructor JyServlet(ServletPyHandler), so JyServlet always has a ref to the ServletPyHandler instance; The downside of this approach is that now jythonc compiled servlet and dynamically interpreted servlet have to be written differently. 2. Have ServletPyHandler do somthing to the jython servlet class right before dispatching service() call, so that inside jython servlet, later when messages like self.getInitParameterNames() will be redirected back to ServletPyHandler. TIA for any ideas, /Brian |
|
From: <bc...@wo...> - 2001-01-31 12:50:47
|
[Samuele] >I'm posting a preliminary *draft* version of some documentation for java reload >simple support module - jreload, which >is still experimental. > >Is it possible to understand what is explained? Is that too technical? or more >details are needed? >(English is too bad?) I'm hardly in a position to offer critique on correct usage of the english language, but I found a single sentences I couldn't parse: >Note: Unless one cannot predict the amount of reloading that will be >performed by an application or for the case of long-running highly >dynamic apps, the unloading issue can simply be ignored. I could understand everything else. You can add it as ./Doc/jreload.ht. The links to the demo sources should not contain any path, eg: <a href="Version.java">. The built script for the Doc directory can then ensure that lastest version from Demo is used when the documentation is generated for both local installation and the web site. regards, finn |
|
From: Samuele P. <pe...@in...> - 2001-01-31 09:46:10
|
Hi. I'm posting a preliminary *draft* version of some documentation for java reload simple support module - jreload, which is still experimental. Is it possible to understand what is explained? Is that too technical? or more details are needed? (English is too bad?) Comments, suggestions and corrections will be appreciated. Thanks, Samuele Pedroni. PS: it contains also some useful (related info) on python.options.internalTablesImpl! PS: jreload 0.2 contains a stupid typo, that will be fixed and distributed somehow... PS: The idea is that this doc will end up in the distributed jython docs (<jython-home>/Doc) and possibly on jython site. The version I'm posting is plain html, the final version will be a .ht template. PS: The doc refers to an example, it is ready too and should end up as "Demo" in jython distr. |
|
From: Robert W. B. <rb...@di...> - 2001-01-30 18:44:24
|
On Tue, 30 Jan 2001, Mike Snell wrote: > I'm preparing to do development using Jython with target platforms of > Windows 2000 and Solaris. > > My concern is Jython's seeming lack of explicit support for JDK/JRE 1.3 > (at least according to http://www.jython.org/platform.html > <http://www.jython.org/platform.html> ) An omission on my part- sorry. JVM 1.3 has been tested on Solaris 8 since Finn was kind enough to add the -o switch (I think that was rc1 or earlier)-- Thanks Finn! However, I forgot to include this info with my other Solaris test info. * "Tested" means regrtest.py (modified for Jython) and all the scripts I had at the time worked. > Anyone have any experience or guidance for these JVM/OS combiniations. Yes on the Solaris 8- all good news. > What about JPython 1.1? Anyone used it successfully with 1.3 on these > platforms? JPython1.1 is not recommended, and unnecessary as Jython + jvm1.3 + Solaris 8 is OK. -Robert |
|
From: Samuele P. <pe...@in...> - 2001-01-30 16:56:43
|
Hi. > I'm preparing to do development using Jython with target platforms of > Windows 2000 and Solaris. > > My concern is Jython's seeming lack of explicit support for JDK/JRE 1.3 > (at least according to http://www.jython.org/platform.html > <http://www.jython.org/platform.html> ) The page is simply not up to date, I think because of lack of feedbacks. I think you are referring to jdk 1.3 under Solaris. Because for Windows jdk1.3 is already indicated as the first choice I assume that up to strange quality problem of the type that jdk1.3 for solaris contains much more bugs than jdk1.3 for Windows, jdk 1.3 as platform (that should behave uniformely across os'es) is an adequate home for jython. I have done my entire part of contribution to jython mostly under jdk 1.3. In general if jython encounters a bug that does not appear on all jvms that's jvm bug per definition. In general jpython encountered such kind of bugs under browser jvm and old jvms with JITs. They were both some kind of 1st,2nd generation jvm. First JITs have a lot of robustness issues, and the very dynamic nature of jython (wrt. class loading, reflection) stressed them. My experience and technical reasons indicate that the jdk1.3 jvm is more robust. One of its goal is too completely hide the native compilation that happens behind the scenes: externally e.g. you get line numbers for exceptions in compiled code too. Another nice feature is e.g. that System.gc force collection of unloadable classes too. The porting to different os'es of this cannot break everything at once. So I encourage you to try jdk 1.3 also under Solaris and any feedback from that will be appreciated. On the other hand JPython 1.1 is really not a solution. A lot of bugs have been fixed and much improvents have been done between that and jython 2.0. regards, Samuele Pedroni. |
|
From: Brian Z. <bz...@ig...> - 2001-01-30 15:43:45
|
For what it's worth, I use Jython 2.0 on JDK 1.3 on Win2K and have not noticed a single problem related to the VM. brian -----Original Message----- From: jyt...@li... [mailto:jyt...@li...]On Behalf Of Mike Snell Sent: Tuesday, January 30, 2001 9:35 AM To: jyt...@li... Subject: [Jython-dev] Jython support for JDK/JRE 1.3 on Windows & Solaris I'm preparing to do development using Jython with target platforms of Windows 2000 and Solaris. =20 My concern is Jython's seeming lack of explicit support for JDK/JRE 1.3 (at least according to http://www.jython.org/platform.html <http://www.jython.org/platform.html> ) =20 Anyone have any experience or guidance for these JVM/OS combiniations. =20 What about JPython 1.1? Anyone used it successfully with 1.3 on these platforms? =20 Thanx, Mike _______________________________________________ Jython-dev mailing list Jyt...@li... http://lists.sourceforge.net/lists/listinfo/jython-dev |
|
From: Mike S. <MS...@em...> - 2001-01-30 15:37:29
|
I'm preparing to do development using Jython with target platforms of Windows 2000 and Solaris. =20 My concern is Jython's seeming lack of explicit support for JDK/JRE 1.3 (at least according to http://www.jython.org/platform.html <http://www.jython.org/platform.html> ) =20 Anyone have any experience or guidance for these JVM/OS combiniations. =20 What about JPython 1.1? Anyone used it successfully with 1.3 on these platforms? =20 Thanx, Mike |
|
From: Ype K. <yk...@xs...> - 2001-01-29 22:47:02
|
"""
stringbuffer.py: mutable string built on java.lang.StringBuffer.
The idea is to save as many string object creations as possible
while still be about as fast as string's, when implemented
in Java. This python module is intended as a prototype.
The itch:
I needed java.lang.StringBuffer functionality in jython
on the receiving side of a socket.
I grew tired of writing:
buf += sock.recv(maxSize)
which creates a new buf everytime
sock.recv(maxSize) is called. Note that sock.recv()
may return as little as it likes, depending on
network traffic conditions.
The alternative of keeping a list of received
strings did not really appeal to me.
The questions:
- This may have been done umpteen times before, when so
could someone please tell me?
- I added the standard string methods.
Only when these originally return a string I have them put
the result back into the stringbuffer.
Methods that return something else work as if they
were used on a string.
Is this the right approach? Esp. for split() and friends?
- I don't know whether I handled python default arguments
correctly, eg:
def count(self, sub, start = None, end = None):
if start == None:
if end == None:
return str(self).count(sub)
else:
return str(self).count(sub, 0, end)
elif end == None:
return str(self).count(sub, start)
else:
return str(self).count(sub, start, end)
(str(self) should disappear in the java version ...)
- Is an extend() method needed? It is marked as experimental
in my python 2.0 documentation.
- Should slicing be allowed with other steps than 1?
- pop() also works for slices, is that ok.?
Aside: in the sort() method this line gives an internal compiler error:
l = [self[i] for i in range(len(self))] # internal compiler error:
name i (jython2.0a3)
Why?
"""
"""
See PEP 203 for the methods to emulate the
operators += and *= : __iadd__ and __imul__.
Limitations:
- Slicing should be done with step 1, and no extended slicing is
provided (how should this be done?).
- Many methods still create string objects, by using str(self).
In java charAt() and getChars() can be used instead.
- Sorting has no compare function yet.
Not yet tested:
- insert()
- *=
- lots more: test_string.py could be used, adapting the test function
to look up the result in
the stringbuffer itself where appropriate.
From the Jython faq:
5.1. Java classes that emulate Jython Dictionaries and Sequences
In order to emulate Dictionaries and Sequences, first your Java
class must "extend" the org.python.core.PyObject class.
The following methods can then be defined on your class in order to
emulate these basic Jython types:
public PyObject __finditem__(PyObject key);
public void __setitem__(PyObject key, PyObject value);
public void __delitem__(PyObject key);
Additionally, you might want to throw the
org.python.core.Py.KeyError object if you have any exceptions
(Note, you need not declare the Java method as throwing anything.)
"""
from java.lang import StringBuffer
from java.lang import String
from org.python.core import PySlice
from org.python.core import PyList # sort from PyList doesn't work.
class stringbuffer:
""" basic customization """
def __init__(self, s = None):
if s == None: self.sb = StringBuffer()
else: self.sb = StringBuffer(s)
def dump(self): print self.sb.__class__, '<' + str(self) + '>'
def __repr__(self): # repr(sb)
return 'stringbuffer(' + repr(str(self)) + ')'
def __str__(self): # str(sb)
return self.sb.toString() # java.lang.StringBuffer.toString()
def __len__(self):
return self.sb.length()
def __nonzero__(self):
return self.sb.length() > 0
""" sequence type customization """
def ji(self, i): # java index
if i < 0:
return i + self.sb.length()
else:
return i
def sliceJavaDefaults(self, sl):
assert sl.step == 1
if sl.start == None: b = 0
else: b = self.ji(sl.start)
if sl.stop == None: e = self.sb.length()
else: e = self.ji(sl.stop)
return b, e
def __getitem__(self, i): # self[i], key may be slice
if not isinstance(i, PySlice):
return self.sb.charAt(self.ji(i))
else:
b, e = self.sliceJavaDefaults(i)
return self.sb.substring(b, e)
def __setitem__(self, i, c): # self[i] = c, key may be slice
if not isinstance(i, PySlice):
self.sb.setCharAt(self.ji(i), c)
else:
b, e = self.sliceJavaDefaults(i)
self.sb.replace(b, e, c)
def __delitem__(self, i): # del self[i], key may be slice
if not isinstance(i, PySlice):
self.sb.deleteCharAt(self.ji(i))
else:
b, e = self.sliceJavaDefaults(i)
self.sb.delete(b, e)
def min(self): return min(str(self))
def max(self): return max(str(self))
""" `numeric' operators, most can be left to string/String """
def __add__(self, s2): # self + s2
sum = stringbuffer(str(self))
sum.append(s2)
return sum
def __radd__(self, s2): # s2 + self
sbf = stringbuffer(str(s))
sbf.append(self.sb)
return sbf
def __iadd__(self, s2): # self += s2
self.append(s2)
return self
def __mul__(self, i): # self * i
return stringbuffer(str(self) * i)
def __rmul__(self, i): # i * self
return stringbuffer(str(self) * i)
def __imul__(self, i): # self *= i
# see PyString.java for better stuff.
if i > 1: self.append(str(self) * (i - 1))
elif i == 0: del self[:]
return self
""" methods that must be provided for mutable sequences """
def append(self, s): self.sb.append(str(s))
"""
Does append() need an ensureCapacity()?
In python append() is meant for single elements,
but python does not have the character type.
This append() works for any argument that can be str()'d.
"""
def count(self, sub, start = None, end = None):
""" nested if testing 4 cases: ok? """
if start == None:
if end == None: return str(self).count(sub)
else: return str(self).count(sub, 0, end)
elif end == None: return str(self).count(sub, start)
else: return str(self).count(sub, start, end)
def index(self, sub, start = None, end = None):
if start == None:
if end == None: return str(self).index(sub)
else: return str(self).index(sub, 0, end)
elif end == None: return str(self).index(sub, start)
else: return str(self).index(sub, start, end)
def pop(self, i = None): # also works for slices
if i == None: i = -1
"""
inlined:
c = self.__getitem__(i)
self.__delitem__(i)
"""
if not isinstance(i, PySlice):
jvi = self.ji(i)
c = self.sb.charAt(jvi)
self.sb.deleteCharAt(jvi)
else:
b, e = self.provideSliceDefaults(i)
c = self.sb.substring(b, e)
self.sb.delete(b, e)
return c
def remove(self, c): # remove first occurrence of string c
i = self.index(c) # raises ValueError
lc = len(c)
if lc == 1: self.sb.deleteCharAt(i)
else: self.sb.delete(i, i + lc)
def sort(self): # sort the chars standard order, no compare function yet
""" a long detour via the other mutable sequence """
# l = [self[i] for i in range(len(self))] # internal compiler
error: name i (jython2.0a3)
l = []
for i in range(len(self)):
l.append(self[i])
l.sort()
self.sb = StringBuffer(''.join(l))
def reverse(self): self.sb.reverse()
""" remaining java StringBuffer methods """
def extend(self, s): self.append(s) # still experimental in python?
def capacity(self): return self.sb.capacity()
def ensureCapacity(self, cap): return self.sb.ensureCapacity(cap)
""" superfluous: use of StringBuffer.insert() """
def setLength(self, newLength): self.sb.setLength(newLength) #
truncate or add null chars.
"""
Almost all python string methods are also useful for stringbuffers.
These are probably better implemented by getting inspiration from
PyString.java.
Straightforward adapting to putting the result back will do in most of the
cases...
"""
def capitalize(self): self.sb = StringBuffer(str(self).capitalize())
def center(self): self.sb = StringBuffer(str(self).center())
def endswith(self, suffix, start = None, end = None):
if start == None:
if end == None: return str(self).endswith(sub)
else: return str(self).endswith(sub, 0, end)
elif end == None: return str(self).endswith(sub, start)
else: return str(self).endswith(sub, start, end)
def expandtabs(self, suffix, start = None, end = None):
if start == None:
if end == None: self.sb =
StringBuffer(str(self).expandtabs(suffix))
else: self.sb = StringBuffer(str(self).expandtabs(suffix, 0, end))
elif end == None: self.sb =
StringBuffer(str(self).expandtabs(suffix, start))
else: self.sb = StringBuffer(str(self).expandtabs(suffix, start, end))
def find(self, sub, start = None, end = None):
if start == None:
if end == None: return str(self).find(sub)
else: return str(self).find(sub, 0, end)
elif end == None: return str(self).find(sub, start)
else: return str(self).find(sub, start, end)
def isalnum(self): return str(self).isalnum()
def isalpha(self): return str(self).isalpha()
def isdigit(self): return str(self).isdigit()
def islower(self): return str(self).islower()
def isspace(self): return str(self).isspace()
def istitle(self): return str(self).istitle()
def isupper(self): return str(self).isupper()
def isupper(self, seq): return str(self).join(seq)
def join(self, seq): return str(self).join(seq)
def ljust(self): self.sb = StringBuffer(str(self).ljust())
def lower(self): self.sb = StringBuffer(str(self).lower())
def lstrip(self): self.sb = StringBuffer(str(self).lstrip())
def replace(old,new,maxsplit = None):
if maxsplit == None: self.sb = StringBuffer(str(self).replace(old,new))
else: self.sb = StringBuffer(str(self).replace(old,new,maxsplit))
def rfind(self, sub, start = None, end = None):
if start == None:
if end == None: return str(self).rfind(sub)
else: return str(self).rfind(sub, 0, end)
elif end == None: return str(self).rfind(sub, start)
else: return str(self).rfind(sub, start, end)
def rindex(self, sub, start = None, end = None):
if start == None:
if end == None: return str(self).rindex(sub)
else: return str(self).rindex(sub, 0, end)
elif end == None: return str(self).rindex(sub, start)
else: return str(self).rindex(sub, start, end)
def rjust(self): self.sb = StringBuffer(str(self).rjust())
def rstrip(self): self.sb = StringBuffer(str(self).rstrip())
def split(self, sep, maxsplit = None): # returns a list of
strings, not stringbuffers
if maxsplit == None:
return str(self).split(sep)
else:
return str(self).split(sep, maxsplit)
def splitlines(self, keepends = None): # returns a list of
strings, not stringbuffers
if keepends == None:
return str(self).splitlines(sep)
else:
return str(self).splitlines(sep, keepends)
def startswith(self, suffix, start = None, end = None):
if start == None:
if end == None: return str(self).startswith(sub)
else: return str(self).startswith(sub, 0, end)
elif end == None: return str(self).startswith(sub, start)
else: return str(self).startswith(sub, start, end)
def strip(self): self.sb = StringBuffer(str(self).strip())
def swapcase(self): self.sb = StringBuffer(str(self).swapcase())
def title(self): self.sb = StringBuffer(str(self).title())
def translate(self, table, deletechars = None):
if deletechars == None:
self.sb = StringBuffer(str(self).translate(table))
else:
self.sb = StringBuffer(str(self).translate(table, deletechars))
def upper(self): self.sb = StringBuffer(str(self).upper())
if __name__ == '__main__':
# some initial tests, all empty strings
sb1 = stringbuffer()
assert not sb1
assert len(sb1) == 0
assert str(sb1) == ''
assert sb1[:0] == ''
assert str(sb1 + sb1) == ''
sb2 = stringbuffer()
sb2 += sb1
assert not sb2
sb2 += ''
assert len(sb2) == 0
sb2.append(sb1)
assert len(sb2) == 0
# two non empty strings, indexing and slicing, __getitem__
s1 = 'a'
s2 = 'bc'
sb1 = stringbuffer(s1)
assert len(sb1) == len(s1)
sb2 = stringbuffer(s2)
assert len(sb2) == len(s2)
sb1 += s2
assert str(sb1) == (s1 + s2)
assert sb1[:len(s1)] == s1
assert sb1[len(s1):] == s2
assert sb1[0] == s1[0]
assert sb1[1] == s2[0]
assert sb1[2] == s2[1]
assert sb1[1:3] == s2
assert sb1[:] == (s1 + s2)
# __setitem__
sb1 = stringbuffer(3)
sb2 = sb1
sb1.setLength(3) # now three null chars
assert sb1[:] == '\0\0\0'
assert len(sb1) == 3
sb1[0] = 'a'
sb1[1] = 'b'
sb1[2] = 'c'
assert sb1 is sb2 # check mutability
assert sb1[:] == 'abc'
sb1[1] = 'd'
assert sb1[:] == 'adc'
assert sb1 is sb2
sb1[0:2] = 'de'
assert sb1[:] == 'dec'
sb1[2:2] = 'f'
assert sb1[:] == 'defc'
sb1 = stringbuffer('ghij')
sb2 = sb1
del sb1[0]
assert sb1[:] == 'hij'
assert sb1 is sb2
# __delitem__
sb1 = stringbuffer('ghij')
sb2 = sb1
del sb1[1:3]
assert sb1[:] == 'gj'
assert sb1 is sb2
# reverse
sb1 = stringbuffer('ghij')
sb2 = sb1
sb1.reverse()
assert sb1[:] == 'jihg'
assert sb1 is sb2
# negative indexes
assert sb1[-1] == 'g'
assert sb1[:-1] == 'jih'
sb1.remove('i')
assert sb1[:] == 'jhg'
try: sb1.remove('a')
except ValueError: pass
else: raise Exception, "should throw ValueError"
assert sb1[:] == 'jhg'
sb1.sort()
assert sb1[:] == 'ghj'
|
|
From: Samuele P. <pe...@in...> - 2001-01-29 14:12:47
|
Hi. [Finn] > >In that case, wouldn't > >that be nice to have a .sig attribute (or even .signature, which gets my > >vote, > >or .__signature__ or something) instead of (or -- for backwards > >compatibility > >-- in addition to) the docstring convention (or, as some might call it, > >"hack" ;-)? > > It would be nice, but I'm not entirely sure it is possible. The function > attributes are a runtime feature, the @sig is very much a compile time > feature. Given all the real problem and confusion sources that you listed, I don't think it is worth the effort. regards, Samuele Pedroni. |
|
From: <bc...@wo...> - 2001-01-29 13:56:52
|
[Magnus Lie Hetland] >Another thing Jython seems to be lacking: A dbm-style module. >(I'm sure dumbdbm works, but...) > >Aaron Watters' bplustree.py has a dbm-compatibility mode >which would make it a possible back-end entirely implemented >in Python: >http://www.pythonpros.com/arw/bplustree/ Have anyone tried it with Jython? I recall some problems regarding ints/longs, but I have forgotten the details. >There are also a few pure Java DBM implementations out >there: > >http://www.advogato.org/proj/jdbm/ >http://dev.w3.org/cvsweb/java/classes/org/w3c/tools/jdbm/ If anyone makes an dbm compatible wrapper for any of these packages, I gladly list them in the FAQ. Even without such a wrapper, the java packages are usefull but hardly worth special mentioning. If the licensing of the dbm java package can be resolved, the combined dbm module might make it into the distribution. As always, contribution are welcome. regards, finn |
|
From: <bc...@wo...> - 2001-01-29 13:55:32
|
[Magnus Lie Hetland] >I was just browsing the documentation at jython.org, and I read about the >convention with @sig in the docstring of functions. > >Since Python now (by version 2.1a) supports function attributes [1], I >assume this will be included in future (2.1?) versions of Jython. Yes, it will be part of jython 2.1. >In that case, wouldn't >that be nice to have a .sig attribute (or even .signature, which gets my >vote, >or .__signature__ or something) instead of (or -- for backwards >compatibility >-- in addition to) the docstring convention (or, as some might call it, >"hack" ;-)? It would be nice, but I'm not entirely sure it is possible. The function attributes are a runtime feature, the @sig is very much a compile time feature. We could add some addition requirement to the use of function attributes, like: - They must be specified as part of the class def - They must use the attribute syntax With something like this, it might be possible to detect function attribute syntacticly, but that would cause these two valid uses of function attribute to be ignored: class Foo: def bar(self): pass bar.__dict__['sig'] = "public void bar()" Foo.bar.sig = "public void bar()" >At least it seems this is the sort of thing function attributes was made >for... I'm guessing it was made to improve the runtime introspection of functions. Public/private methods in Zope springs to mind. The examples listed in the pep are also about runtime inspection. Adding static type info isn't used as an example in the pep. >Example of use: > >def setExpression(self, e): > # Do something... > pass >setExpression.signature = "public void setExpression(java.lang.String e)" > >(I'm sure it might be seen as a drawback that the signature must be set >outside >the function. I don't really feel it matters much...) It may also be assigned from outside the module. That would matter a little bit from the compiler's POV <wink>. regards, finn |
|
From: <bc...@wo...> - 2001-01-29 13:48:45
|
[Magnus Lie Hetland] >Quote from http://www.jython.org/docs/differences.html >> * Some builtin extension modules don't exist in Jython. >> * The following are under consideration (working code would make >> the decision much easier ;-) -- array, select, a >> dbm/gdbm/bsddb style module, Numeric, cmath. > >I would just like to mention Tim Hochberg's Java implementation of Numeric, >JNumeric [1] which works with JPython 1.1b1. I don't know if it works with >Jython 2.0, but I'm sure that it would, with a little tweaking... > >It just seems nice to have a numeric module available :-) > >[1] http://starship.python.net/~hochberg/ I think the lastest version is avilable here: http://members.home.net/tim.hochberg/ I have added an entry in the FAQ: http://jython.sourceforge.net/cgi-bin/faqw.py?req=all#4.3 Tim, feel free to expand on it, if you want to. regards, finn |