New view server (was Re: Writing Lists in Python?)

35 views
Skip to first unread message

Matt Goodall

unread,
Jul 1, 2011, 9:20:10 AM7/1/11
to couchdb...@googlegroups.com
On 1 July 2011 13:55, John Meehan <jnme...@gmail.com> wrote:
Ah yes.  That's what I get for editing from my Windows box.  I stripped the carriage returns and looks like it's working!  Thanks very much for your help.

I'd really like to get the new view server into the "official" couchdb-python repo.

I got lost in the discussion, but the last comment on ticket #146 suggests that it should all be working now (thanks kxepal). So, if you guys can work together to test as much as possible and confirm that it's all ok then I would be happy to merge it.

If there's anyone else using the new view server then now is the time to speak out - good or bad.

Thanks for all the help!

- Matt


On Thu, Jun 30, 2011 at 4:38 PM, Kxepal <kxe...@gmail.com> wrote:
Wow. Looks like just SyntaxError, but it shouldn't have to produce double fail. Ok, I'll look why it happened.
Problem is that Python < 2.7 doesn't allows Windows/Mac style newlines within compile function (\r\n chars) [1]. That's my fault especially because I'm using Linux on my dev notebook and I even didn't know about such behavior(: Shortest workaround is to replace all \r\n chars to \n in function source code. I'll attach fixed version on this weekends due to I'm currently rewriting test methods from functional to pure unit tests.

Thanks for report!(:

[1] http://docs.python.org/library/functions.html#compile


On Friday, July 1, 2011 12:29:36 AM UTC+4, John Meehan wrote:
Hi,

Not sure if I've done something wrong with my list code or if I'm running into an issue with the new view server.  The views I'd written worked as expected so I take it that the new view server files were installed OK, but now trying to write a test list against one of those views seems to encounter an issue compiling the list code.  This looks like the relevant portion of the view server log.  Any thoughts?

[2011-06-30 15:17:18,362] [couchdb.server.ddoc] [DEBUG] Processing DDoc command `lists`
[2011-06-30 15:17:18,362] [couchdb.server.compiler] [DEBUG] Compiling code to function:
def fun(head, req):
start({"headers": {"Content-Type": "text/html"}})
c = 0
for row in get_row():
send(str(c) + row['key'][0])
                c+=1
[2011-06-30 15:17:18,363] [couchdb.server.compiler] [ERROR] Failed to compile function
def fun(head, req):
start({"headers": {"Content-Type": "text/html"}})
c = 0
for row in get_row():
send(str(c) + row['key'][0])
                c+=1
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/server/compiler.py", line 284, in compile_func
    bytecode = compile(funstr, '<string>', 'exec')
  File "<string>", line 1
     def fun(head, req):
                       
^
 SyntaxError: invalid syntax
[2011-06-30 15:17:18,363] [couchdb.server] [ERROR] Error `compilation_error` occurred: invalid syntax (<string>, line 1)
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/server/__init__.py", line 253, in run
    retval = self.commands[cmd](*args)
  File "/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/server/ddoc.py", line 83, in ddoc
    func = compile_func(func, ddoc)
  File "/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/server/compiler.py", line 288, in compile_func
    raise Error('compilation_error', err)
Error: ('compilation_error', SyntaxError('invalid syntax', ('<string>', 1, 20, 'def fun(head, req):\r\n')))
[2011-06-30 15:17:18,363] [couchdb.server.stream] [DEBUG] Data to respond:
['error', 'compilation_error', SyntaxError('invalid syntax', ('<string>', 1, 20, 'def fun(head, req):\r\n'))]
[2011-06-30 15:17:18,363] [couchdb.server] [ERROR] TypeError: SyntaxError('invalid syntax', ('<string>', 1, 20, 'def fun(head, req):\r\n')) is not JSON serializable
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/server/__init__.py", line 255, in run
    retval = self.error_handler(*sys.exc_info())
  File "/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/server/__init__.py", line 233, in error_handler
    return self.error_handlers.get(type, default)(type, value, traceback)
  File "/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/server/__init__.py", line 176, in handle_qs_error
    stream.respond(retval)
  File "/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/server/stream.py", line 43, in respond
    obj = json.encode(obj)
  File "/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/json.py", line 65, in encode
    return _encode(obj)
  File "/usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb/json.py", line 113, in <lambda>
    dumps(obj, allow_nan=False, ensure_ascii=False)
  File "/usr/lib/pymodules/python2.6/simplejson/__init__.py", line 237, in dumps
    **kw).encode(obj)
  File "/usr/lib/pymodules/python2.6/simplejson/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/pymodules/python2.6/simplejson/encoder.py", line 260, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/pymodules/python2.6/simplejson/encoder.py", line 177, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: SyntaxError('invalid syntax', ('<string>', 1, 20, 'def fun(head, req):\r\n')) is not JSON serializable
[2011-06-30 15:17:18,380] [couchdb.server.stream] [DEBUG] Data to respond:
['error', 'TypeError', "SyntaxError('invalid syntax', ('<string>', 1, 20, 'def fun(head, req):\\r\\n')) is not JSON serializable"]

On Wed, Jun 29, 2011 at 2:09 PM, Kxepal <kxe...@gmail.com> wrote:
Just extract couchdb folder from archive over couchdb installed package: where should be added server folder and replaced view.py by new one.
Next thing you have to do is specify version of CouchDB against that query server will be runned (supported since 0.9 till 1.1.0).
This could be done by edition [query_server] config option to made it looks like this (for 1.1.0 version):
python=/path/to/couchpy --couchdb-version=1.1.0 

And it should work(: For more information you may build sphinx docs - there have described all command line options, objects and usage examples.


On Wednesday, June 29, 2011 10:12:53 PM UTC+4, John Meehan wrote:
Thanks!  My next question, however, is how do I install the updated files?

I downloaded query-server.tar.gz from your May 9th post in the issue 146 thread.  

I'm running Ubuntu 10.04, and installed couchdb-python originally with easy-install.  So I have the following in my /usr/local/lib/python2.6/dist-packages/CouchDB-0.8-py2.6.egg/couchdb dir:

-rwxr-xr-x 1 root staff 37477 2011-06-01 09:58 client.py
-rw-r--r-- 1 root staff 45267 2011-06-01 09:58 client.pyc
-rwxr-xr-x 1 root staff  7649 2011-06-01 09:58 design.py
-rw-r--r-- 1 root staff  8355 2011-06-01 09:58 design.pyc
-rwxr-xr-x 1 root staff 17607 2011-06-01 09:58 http.py
-rw-r--r-- 1 root staff 20156 2011-06-01 09:58 http.pyc
-rwxr-xr-x 1 root staff   534 2011-06-01 09:58 __init__.py
-rw-r--r-- 1 root staff   687 2011-06-01 09:58 __init__.pyc
-rwxr-xr-x 1 root staff  4441 2011-06-01 09:58 json.py
-rw-r--r-- 1 root staff  5859 2011-06-01 09:58 json.pyc
-rwxr-xr-x 1 root staff 22337 2011-06-01 09:58 mapping.py
-rw-r--r-- 1 root staff 34371 2011-06-01 09:58 mapping.pyc
-rwxr-xr-x 1 root staff  8640 2011-06-01 09:58 multipart.py
-rw-r--r-- 1 root staff  9080 2011-06-01 09:58 multipart.pyc
drwxr-sr-x 2 root staff  4096 2011-06-01 09:58 tests
drwxr-sr-x 2 root staff  4096 2011-06-01 09:58 tools
-rwxr-xr-x 1 root staff  7167 2011-06-01 09:58 view.py
-rw-r--r-- 1 root staff  7498 2011-06-01 09:58 view.pyc

(I'm assuming I need to overwrite or add the new files from the archive here.)


On Wed, Jun 29, 2011 at 12:20 PM, Kxepal <kxe...@gmail.com> wrote:

On Wednesday, June 29, 2011 7:58:11 PM UTC+4, John Meehan wrote:
Can Lists be written in Python?

What would be the Python equivalent of this example from the CouchDB
wiki (http://wiki.apache.org/couchdb/Formatting_with_Show_and_List)?

function(head, req) {
  var row;
  start({
    "headers": {
      "Content-Type": "text/html"
     }
  });
  while(row = getRow()) {
    send(row.value);
  }
}

Hi!

Currently this could be done by using new query server from issue 146 (http://code.google.com/p/couchdb-python/issues/detail?id=146)
Equivalent would be :
def fun(head, req):
  start({
    "headers": {"Content-Type": "text/html"}
  })
  for row in get_row():
    send(row["value"])

Notice, that get_row function is generator and any dotted notation accessed attributes should be changed to getitem specification due to this is dict object.
Also notice, that builtn query server function are respect PEP-8, so there is nothing mixedCased nor CamelCase except exceptions(Forbidden, Error, FatalError).

If you would try this query server any feedback would be great(:

--
,,,^..^,,,

--
You received this message because you are subscribed to the Google Groups "CouchDB-Python" group.
To view this discussion on the web visit https://groups.google.com/d/msg/couchdb-python/-/KQWWZ2-nQo0J.

To post to this group, send email to couch...@googlegroups.com.

To unsubscribe from this group, send email to couchdb-pytho...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/couchdb-python?hl=en.

--
You received this message because you are subscribed to the Google Groups "CouchDB-Python" group.
To view this discussion on the web visit https://groups.google.com/d/msg/couchdb-python/-/sFKh8Qt6PhYJ.

To post to this group, send email to couchdb...@googlegroups.com.
To unsubscribe from this group, send email to couchdb-pytho...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/couchdb-python?hl=en.

--
You received this message because you are subscribed to the Google Groups "CouchDB-Python" group.
To view this discussion on the web visit https://groups.google.com/d/msg/couchdb-python/-/kpeiuvjMCp8J.

To post to this group, send email to couchdb...@googlegroups.com.
To unsubscribe from this group, send email to couchdb-pytho...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/couchdb-python?hl=en.

--
You received this message because you are subscribed to the Google Groups "CouchDB-Python" group.
To post to this group, send email to couchdb...@googlegroups.com.
To unsubscribe from this group, send email to couchdb-pytho...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/couchdb-python?hl=en.

Kxepal

unread,
Jul 30, 2011, 3:46:27 AM7/30/11
to couchdb...@googlegroups.com
Hi Matt, all!

Currently, I'm out of time to make new revision faster, but there are a lot of minor bugs have  found and more I hope will be, "thanks" to functional tests. That's was good idea in the beginning to port ruby testing script, but it couldn't provide insurance that all works fine and as is it should.

Next goal I try to reach is to remove shared global state as original one has. This is not a problem since QS runs in single instance, but this makes hard to test QS itself and to make it use easily  for testing design functions and document mappings.

I hope to release new version on next week.

Thank you
for your patience
(:

--
,,,^..^,,,

Kxepal

unread,
Sep 13, 2011, 6:59:40 AM9/13/11
to couchdb...@googlegroups.com
Hi Matt!

I've posted new version of view server with fixes of those problems and even more. Now it's ready to be reviewed(: The only thing that is needed to be improved is documentation. May be MockQueryServer to have it native support of mapping.ViewField and issue 186, but I'll review it later - there are more actual issues that still awaiting for patches.

--
,,,^..^,,,
Reply all
Reply to author
Forward
0 new messages