Beispiel #1
0
def _create_report_keywords(data):
    # In Python 3, 'unquote_plus()' must be called with a 'str', which
    # is the case. In Python 2, if the quoted keyword is a 'unicode'
    # object, unquoting it does not yield back the original keyword.
    #
    # In Python 2:
    #    >>> encoded = '\xc3\xa9'
    #    >>> decoded = unicode(encoded, 'utf-8')
    #    >>> decoded
    #    u'\xe9'
    #    >>> quote_plus(encoded)
    #    '%C3%A9'
    # Now the following is fine:
    #    >>> unquote_plus('%C3%A9')
    #    '\x3\xa9'
    # But we cannot do that. Since 'unquote_plus()' requires a 'str'
    # in Python 3, we pass is a 'unicode' object in Python 2, and
    # unquoting the 'unicode' object does not return the decoded
    # string:
    #    >>> unquote_plus(unicode('%C3%A9'))
    #    u'\xc3\xa9'
    #
    # This is why, in Python 2, we first encode the 'unicode' object,
    # then unquote it, and finally decode it back to have a 'unicode'
    # object.
    if PY3:  # pragma: no cover
        converter = unquote_plus
    else:
        converter = lambda uni: unquote_plus(
            uni.encode('utf-8')).decode('utf-8')
    keys = {'keyword': converter, 'searches': int}
    discr = 'keyword'
    aggregate_keys = ('searches', )
    return _create_report_helper(
        data, 'KEYWORDS', keys, discr, aggregate_keys, 'searches', top=30)
Beispiel #2
0
def _create_report_phrases(data):
    # See comments in '_create_report_keywords()' for details about
    # the block below.
    if PY3:  # pragma: no cover
        converter = unquote_plus
    else:
        converter = lambda uni: unquote_plus(
            uni.encode('utf-8')).decode('utf-8')
    keys = {'phrase': converter, 'searches': int}
    discr = 'phrase'
    aggregate_keys = ('searches', )
    return _create_report_helper(
        data, 'SEARCHWORDS', keys, discr, aggregate_keys, 'searches', top=30)
Beispiel #3
0
def _create_report_phrases(data):
    # See comments in '_create_report_keywords()' for details about
    # the block below.
    if PY3:  # pragma: no cover
        converter = unquote_plus
    else:
        converter = lambda uni: unquote_plus(uni.encode('utf-8')).decode(
            'utf-8')
    keys = {'phrase': converter, 'searches': int}
    discr = 'phrase'
    aggregate_keys = ('searches', )
    return _create_report_helper(data,
                                 'SEARCHWORDS',
                                 keys,
                                 discr,
                                 aggregate_keys,
                                 'searches',
                                 top=30)
Beispiel #4
0
def _create_report_keywords(data):
    # In Python 3, 'unquote_plus()' must be called with a 'str', which
    # is the case. In Python 2, if the quoted keyword is a 'unicode'
    # object, unquoting it does not yield back the original keyword.
    #
    # In Python 2:
    #    >>> encoded = '\xc3\xa9'
    #    >>> decoded = unicode(encoded, 'utf-8')
    #    >>> decoded
    #    u'\xe9'
    #    >>> quote_plus(encoded)
    #    '%C3%A9'
    # Now the following is fine:
    #    >>> unquote_plus('%C3%A9')
    #    '\x3\xa9'
    # But we cannot do that. Since 'unquote_plus()' requires a 'str'
    # in Python 3, we pass is a 'unicode' object in Python 2, and
    # unquoting the 'unicode' object does not return the decoded
    # string:
    #    >>> unquote_plus(unicode('%C3%A9'))
    #    u'\xc3\xa9'
    #
    # This is why, in Python 2, we first encode the 'unicode' object,
    # then unquote it, and finally decode it back to have a 'unicode'
    # object.
    if PY3:  # pragma: no cover
        converter = unquote_plus
    else:
        converter = lambda uni: unquote_plus(uni.encode('utf-8')).decode(
            'utf-8')
    keys = {'keyword': converter, 'searches': int}
    discr = 'keyword'
    aggregate_keys = ('searches', )
    return _create_report_helper(data,
                                 'KEYWORDS',
                                 keys,
                                 discr,
                                 aggregate_keys,
                                 'searches',
                                 top=30)