<commit_before>
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from uuid import UUID
from StringIO import StringIO
from errors import InvalidQueryFormat
from struct import unpack

__all__ = ['prepare', 'marshal', 'unmarshal']

def prepare(query, *args):
    result = StringIO()
    index = query.find('?')
    oldindex = 0
    count = 0
    
    while (index >= 0):
        result.write(query[oldindex:index])
        try:
            result.write(marshal(args[count]))
        except IndexError:
            raise InvalidQueryFormat("not enough arguments in substitution")
        
        oldindex = index + 1
        index = query.find('?', index + 1)
        count += 1
    result.write(query[oldindex:])
    
    if count < len(args):
        raise InvalidQueryFormat("too many arguments in substitution")
    
    return result.getvalue()

def marshal(term):
    if isinstance(term, long):
        return "%dL" % term
    elif isinstance(term, int):
        return "%d" % term
    elif isinstance(term, unicode):
        return "u'%s'" % term
    elif isinstance(term, str):
        return "'%s'" % term
    elif isinstance(term, UUID):
        if term.version == 1:
            return "timeuuid(\"%s\")" % str(term)
        else:
            return "uuid(\"%s\")" % str(term)
    else:
        return str(term)
        
def unmarshal(bytestr, typestr):<commit_msg>uuid term type (hyphenated hex string)<commit_after>
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from uuid import UUID
from StringIO import StringIO
from errors import InvalidQueryFormat
from struct import unpack

__all__ = ['prepare', 'marshal', 'unmarshal']

def prepare(query, *args):
    result = StringIO()
    index = query.find('?')
    oldindex = 0
    count = 0
    
    while (index >= 0):
        result.write(query[oldindex:index])
        try:
            result.write(marshal(args[count]))
        except IndexError:
            raise InvalidQueryFormat("not enough arguments in substitution")
        
        oldindex = index + 1
        index = query.find('?', index + 1)
        count += 1
    result.write(query[oldindex:])
    
    if count < len(args):
        raise InvalidQueryFormat("too many arguments in substitution")
    
    return result.getvalue()

def marshal(term):
    if isinstance(term, long):
        return "%dL" % term
    elif isinstance(term, int):
        return "%d" % term
    elif isinstance(term, unicode):
        return "u'%s'" % term
    elif isinstance(term, str):
        return "'%s'" % term
    elif isinstance(term, UUID):
        if term.version == 1:
            return "timeuuid(\"%s\")" % str(term)
        else:
            return str(term)
    else:
        return str(term)
        
def unmarshal(bytestr, typestr):
{'fraction_non_alphanumeric': 0.09607193563653574, 'fraction_numerical': 0.005205868433506862, 'mean_word_length': 2.8922651933701657, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '566729', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1130, 'n_words': 451}