コード例 #1
0
 def test_sanitize(self):
     self.assertEqual(
         sanitize(
             "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19h\x1ae\x1bl\x1cl\x1do\x1e\x1f"  # NOQA: E501
         ),
         "hello",
     ),
コード例 #2
0
ファイル: client.py プロジェクト: janurag/pysolr
 def test_sanitize(self):
     self.assertEqual(
         sanitize(
             "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19h\x1ae\x1bl\x1cl\x1do\x1e\x1f"
         ),
         "hello",
     ),
コード例 #3
0
def update(solr,
           message,
           dsId,
           clean_ctrl_chars=True,
           commit=True,
           waitFlush=None,
           waitSearcher=None):
    """
    Posts the given xml message to http://<self.url>/update and
    returns the result.

    Passing `sanitize` as False will prevent the message from being cleaned
    of control characters (default True). This is done by default because
    these characters would cause Solr to fail to parse the XML. Only pass
    False if you're positive your data is clean.
    """
    path = 'update/'

    # Per http://wiki.apache.org/solr/UpdateXmlMessages, we can append a
    # ``commit=true`` to the URL and have the commit happen without a
    # second request.
    query_vars = []

    if commit is not None:
        query_vars.append('commit=%s' % str(bool(commit)).lower())

    if waitFlush is not None:
        query_vars.append('waitFlush=%s' % str(bool(waitFlush)).lower())

    if waitSearcher is not None:
        query_vars.append('waitSearcher=%s' % str(bool(waitSearcher)).lower())
    if dsId is not None:
        query_vars.append("lucidworks_fields=true")
        #query_vars.append("fm.ds=" + dsId)
    if query_vars:
        path = '%s?%s' % (path, '&'.join(query_vars))

    # Clean the message of ctrl characters.
    if clean_ctrl_chars:
        message = pysolr.sanitize(message)

    return solr._send_request('post', path, message,
                              {'Content-type': 'text/xml; charset=utf-8'})
コード例 #4
0
def update(solr, message, dsId, clean_ctrl_chars=True, commit=True, waitFlush=None, waitSearcher=None):
    """
    Posts the given xml message to http://<self.url>/update and
    returns the result.

    Passing `sanitize` as False will prevent the message from being cleaned
    of control characters (default True). This is done by default because
    these characters would cause Solr to fail to parse the XML. Only pass
    False if you're positive your data is clean.
    """
    path = 'update/'

    # Per http://wiki.apache.org/solr/UpdateXmlMessages, we can append a
    # ``commit=true`` to the URL and have the commit happen without a
    # second request.
    query_vars = []

    if commit is not None:
        query_vars.append('commit=%s' % str(bool(commit)).lower())

    if waitFlush is not None:
        query_vars.append('waitFlush=%s' % str(bool(waitFlush)).lower())

    if waitSearcher is not None:
        query_vars.append('waitSearcher=%s' % str(bool(waitSearcher)).lower())
    if dsId is not None:
        query_vars.append("lucidworks_fields=true")
        #query_vars.append("fm.ds=" + dsId)
    if query_vars:
        path = '%s?%s' % (path, '&'.join(query_vars))

    # Clean the message of ctrl characters.
    if clean_ctrl_chars:
        message = pysolr.sanitize(message)

    return solr._send_request('post', path, message, {'Content-type': 'text/xml; charset=utf-8'})
コード例 #5
0
 def test_sanitize(self):
     self.assertEqual(sanitize('\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19h\x1ae\x1bl\x1cl\x1do\x1e\x1f'), 'hello'),