<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import codecs, os, re, subprocess, sys, yaml

# We don't read the index
IGNORED_FILES = "index.md"

# The class for all reql objects
query = 'rethinkdb.ast.RqlQuery.'

# The python class associated with each type
parents = {
    None: '',
    'r': 'rethinkdb.',
    'sequence': query,
    'query': query,
    'stream': query,
    'grouped_stream': query,
    'singleSelection': query,
    'array': query,
    'number': query,
    'bool': query,
    'value': query,
    'string': query,
    'time': query,
    'any': query,
    'geometry': query,
    'point': query,
    'line': query,
    'polygon': query,
    'connection': 'rethinkdb.net.Connection.',
    'cursor': 'rethinkdb.net.Cursor.',
    'db': 'rethinkdb.ast.DB.',
    'table': 'rethinkdb.ast.Table.',
    'set_loop_type': 'rethinkdb.'
}

# The real python names for names used in the docs
tags = {
    '[] (bracket)': [(query, '__getitem__')],
    'nth, []': [(query, 'nth')],
    'slice, []': [(query, 'slice')],
    '+': [(query, '__add__'), ('rethinkdb.', 'add')],
    '-': [(query, '__sub__'), ('rethinkdb.', 'sub')],
    '*': [(query, '__mul__'), ('rethinkdb.', 'mul')],
    '/': [(query, '__div__'), ('rethinkdb.', 'div')],
    '%': [(query, '__mod__'), ('rethinkdb.', 'mod')],
    '&, and_': [(query, '__and__'), ('rethinkdb.', 'and_')],
    '|, or_': [(query, '__or__'), ('rethinkdb.', 'or_')],
    '==, eq': [(query, '__eq__'), (query, 'eq')],
    '!=, ne': [(query, '__ne__'), (query, 'ne')],
    '<, lt': [(query, '__lt__'), (query, 'lt')],
    '>, gt': [(query, '__gt__'), (query, 'gt')],
    '<=, le': [(query, '__le__'), (query, 'le')],
    '>=, ge': [(query, '__ge__'), (query, 'ge')],
    '~, not_': [(query, '__invert__'), (query, 'not_'), ('rethinkdb.', 'not_')],
    'r': [('', 'rethinkdb')],
    'repl': [('rethinkdb.net.Connection.', 'repl')],
    'count': lambda parent: not parent == 'rethinkdb.' and [(query, 'count')] or [],
    'rethinkdb': [('', 'rethinkdb')],
    'to_json_string, to_json': [(query, 'to_json_string'), (query, 'to_json')],
    'for': [],
    'list': [],
    'set_loop_type': [('rethinkdb.', 'set_loop_type')]
}

# Write the header of the docs.py file
def write_header(file):
    commit = subprocess.Popen(['git', 'log', '-n', '1', '--pretty=format:"%H"'], stdout=subprocess.PIPE).communicate()[0].decode('utf-8')
    file.write('''# This file was generated by _scripts/gen_python.py from the rethinkdb documentation in http://github.com/rethinkdb/docs
# hash: %s

import rethinkdb
<commit_msg>Add coding: utf-8 header to output; closes #1006<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import codecs, os, re, subprocess, sys, yaml

# We don't read the index
IGNORED_FILES = "index.md"

# The class for all reql objects
query = 'rethinkdb.ast.RqlQuery.'

# The python class associated with each type
parents = {
    None: '',
    'r': 'rethinkdb.',
    'sequence': query,
    'query': query,
    'stream': query,
    'grouped_stream': query,
    'singleSelection': query,
    'array': query,
    'number': query,
    'bool': query,
    'value': query,
    'string': query,
    'time': query,
    'any': query,
    'geometry': query,
    'point': query,
    'line': query,
    'polygon': query,
    'connection': 'rethinkdb.net.Connection.',
    'cursor': 'rethinkdb.net.Cursor.',
    'db': 'rethinkdb.ast.DB.',
    'table': 'rethinkdb.ast.Table.',
    'set_loop_type': 'rethinkdb.'
}

# The real python names for names used in the docs
tags = {
    '[] (bracket)': [(query, '__getitem__')],
    'nth, []': [(query, 'nth')],
    'slice, []': [(query, 'slice')],
    '+': [(query, '__add__'), ('rethinkdb.', 'add')],
    '-': [(query, '__sub__'), ('rethinkdb.', 'sub')],
    '*': [(query, '__mul__'), ('rethinkdb.', 'mul')],
    '/': [(query, '__div__'), ('rethinkdb.', 'div')],
    '%': [(query, '__mod__'), ('rethinkdb.', 'mod')],
    '&, and_': [(query, '__and__'), ('rethinkdb.', 'and_')],
    '|, or_': [(query, '__or__'), ('rethinkdb.', 'or_')],
    '==, eq': [(query, '__eq__'), (query, 'eq')],
    '!=, ne': [(query, '__ne__'), (query, 'ne')],
    '<, lt': [(query, '__lt__'), (query, 'lt')],
    '>, gt': [(query, '__gt__'), (query, 'gt')],
    '<=, le': [(query, '__le__'), (query, 'le')],
    '>=, ge': [(query, '__ge__'), (query, 'ge')],
    '~, not_': [(query, '__invert__'), (query, 'not_'), ('rethinkdb.', 'not_')],
    'r': [('', 'rethinkdb')],
    'repl': [('rethinkdb.net.Connection.', 'repl')],
    'count': lambda parent: not parent == 'rethinkdb.' and [(query, 'count')] or [],
    'rethinkdb': [('', 'rethinkdb')],
    'to_json_string, to_json': [(query, 'to_json_string'), (query, 'to_json')],
    'for': [],
    'list': [],
    'set_loop_type': [('rethinkdb.', 'set_loop_type')]
}

# Write the header of the docs.py file
def write_header(file):
    commit = subprocess.Popen(['git', 'log', '-n', '1', '--pretty=format:"%H"'], stdout=subprocess.PIPE).communicate()[0].decode('utf-8')
    file.write('''# -*- coding: utf-8 -*-
# This file was generated by _scripts/gen_python.py from the rethinkdb documentation in http://github.com/rethinkdb/docs
# hash: %s

import rethinkdb

{'fraction_non_alphanumeric': 0.25970264529832016, 'fraction_numerical': 0.0027032245607260088, 'mean_word_length': 3.765409383624655, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1034182', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1945, 'n_words': 463}