make solr.py work with current server

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@577338 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2007-09-19 15:55:56 +00:00
parent c5b328d565
commit c364ddd185
1 changed files with 21 additions and 12 deletions

View File

@ -37,10 +37,18 @@ import urllib
class SolrException(Exception):
def __init__(self, httpcode, appcode=None, reason=None, body=None):
self.httpcode,self.appcode,self.reason,self.body = httpcode,appcode,reason,body
def __str__(self):
return 'HTTP code=%s, Application code=%s, Reason=%s, body=%s' % (self.httpcode,self.appcode,self.reason,self.body)
""" An exception thrown by solr connections """
def __init__(self, httpcode, reason=None, body=None):
self.httpcode = httpcode
self.reason = reason
self.body = body
def __repr__(self):
return 'HTTP code=%s, Reason=%s, body=%s' % (
self.httpcode, self.reason, self.body)
def __str__(self):
return 'HTTP code=%s, reason=%s' % (self.httpcode, self.reason)
class SolrConnection:
@ -72,7 +80,7 @@ class SolrConnection:
def __errcheck(self,rsp):
if rsp.status != 200:
ex = SolrException(rsp.status)
ex = SolrException(rsp.status, rsp.reason)
try:
ex.body = rsp.read()
except:
@ -99,14 +107,15 @@ class SolrConnection:
data = rsp.read()
finally:
if not self.persistent: self.conn.close()
#fast path... don't parse XML if we recognize response as success
if not data.startswith('<result status="0"'):
#detect old-style error response (HTTP response code of
#200 with a non-zero status.
if data.startswith('<result status="') and not data.startswith('<result status="0"'):
data = self.decoder(data)[0]
d = parseString(data)
status = d.documentElement.getAttribute('status')
if status!=0:
reason = d.documentElement.firstChild.nodeValue
raise SolrException(rsp.status, status, reason)
parsed = parseString(data)
status = parsed.documentElement.getAttribute('status')
if status != 0:
reason = parsed.documentElement.firstChild.nodeValue
raise SolrException(rsp.status, reason)
return data
def escapeVal(self,val):