Esempio n. 1
0
def _key_from_query(query, qualifier=None):
    """Given a Query, create a cache key.

    There are many approaches to this; here we use the simplest,
    which is to create an md5 hash of the text of the SQL statement,
    combined with stringified versions of all the bound parameters
    within it.  There's a bit of a performance hit with
    compiling out "query.statement" here; other approaches include
    setting up an explicit cache key with a particular Query,
    then combining that with the bound parameter values.
    """
    stmt = query.with_labels().statement
    compiled = stmt.compile()
    params = compiled.params

    # here we return the key as a long string.  our "key mangler"
    # set up with the region will boil it down to an md5.
    return " ".join(
        [clean_unicode(compiled).decode("utf-8")] +
        [clean_unicode(params[k]).decode("utf-8") for k in sorted(params)])
Esempio n. 2
0
 def test_string(self):
     value = clean_unicode("cookies")
     assert value, b"cookies"
Esempio n. 3
0
    def test_nonstring(self):
        value = clean_unicode(22.04)
        assert value == b"22.04"

        value = clean_unicode(None)
        assert value == b"None"
Esempio n. 4
0
 def test_unicode_string_two_byte_no_chars(self):
     test_string = u"“ЌύБЇ”"
     expected_string = b""
     value = clean_unicode(test_string)
     assert value == expected_string
Esempio n. 5
0
 def test_unicode_string_o_walk(self):
     test_string = u"oòóôõöōŏǫȯőǒȍȏ"
     expected_string = b"oooooooooooooo"
     value = clean_unicode(test_string)
     assert value == expected_string
Esempio n. 6
0
 def test_unicode_string_dashes(self):
     test_string = u"― Like this? ― Right."
     expected_string = b" Like this?  Right."
     value = clean_unicode(test_string)
     assert value == expected_string
Esempio n. 7
0
 def test_unicode_string_single_upper(self):
     test_string = u"«küßî»"
     expected_string = b"kui"
     value = clean_unicode(test_string)
     assert value == expected_string
Esempio n. 8
0
 def test_unicode_string(self):
     test_string = u"Falsches Üben von Xylophonmusik quält jeden größeren" " Zwerg"
     expected_string = (b"Falsches Uben von Xylophonmusik qualt jeden "
                        b"groeren Zwerg")
     value = clean_unicode(test_string)
     assert value == expected_string