<commit_before># -*- coding: utf-8 -*-

import sys

from parser import parse_file
from content_error import ContentError

class Style:
  def __init__(self, f = None):
    if f != None:
      config = parse_file(f)
      filename = f.name
    else:
      config = dict()
      filename = ''

    def switch(s):
      if s in ['Y', 'y', 'ON', 'On', 'on', '1']: return True
      if s in ['N', 'n', 'OFF', 'Off', 'off', '0']: return False
      ContentError('Unknown option %s'%s, filename)

    def options(s):
      if s in ['none', 'None']: return []
      else: return s.split()

    def opt(name, default, func = None):
      if not func:
        if type(default) == str: func = str
      elif type(default) == float: func = float
      elif type(default) == bool: func = switch
      else: func = str

      if name in config:
        return func(config.pop(name))
      else:
        return default

    self.pagesize = opt('page.size', 'A4')

    self.titlepage = opt('title-page', True, switch)
    self.titlepage_margin_top = opt('title-page.margin.top', 128., float)
    self.titlepage_margin_bottom = opt('title-page.margin.bottom', 64., float)

    self.titlepage_title_font_name = opt('title-page.title.font.name', 'DejaVuSans-Bold')
    self.titlepage_title_font_size = opt('title-page.title.font.size', 48., float)
    self.titlepage_title_line_height = opt('title-page.title.line-height', 1.2*self.titlepage_title_font_size, float)

    self.titlepage_title_subtitle_spacing = opt('title-page.title-subtitle.spacing', 64., float)

    self.titlepage_subtitle_font_name = opt('title-page.subtitle.font.name', 'DejaVuSans')
    self.titlepage_subtitle_font_size = opt('title-page.subtitle.font.size', 32., float)
    self.titlepage_subtitle_line_height = opt('title-page.subtitle.line-height', 1.2*self.titlepage_subtitle_font_size, float)

    self.titlepage_author_font_name = opt('title-page.author.font.name', 'DejaVuSans')
    self.titlepage_author_font_size = opt('title-page.author.font.size', 24., float)
    self.titlepage_author_line_height = opt('title-page.author.line-height', 1.2*self.titlepage_author_font_size, float)

    self.notepage = opt('note-page', True, switch)
    self.notepage_margin_top = opt('note-page.margin.top', 64., float)
    self.notepage_margin_bottom = opt('note-page.margin.bottom', 64., float)<commit_msg>Fixed #10.<commit_after># -*- coding: utf-8 -*-

import sys

from parser import parse_file
from content_error import ContentError

class Style:
  def __init__(self, f = None):
    if f != None:
      config = parse_file(f)
      filename = f.name
    else:
      config = dict()
      filename = ''

    def switch(s):
      if s in ['Y', 'y', 'ON', 'On', 'on', '1']: return True
      if s in ['N', 'n', 'OFF', 'Off', 'off', '0']: return False
      ContentError('Unknown option %s'%s, filename)

    def options(s):
      if s in ['none', 'None']: return []
      else: return s.split()

    def opt(name, default, func = None):
      if not func:
        if type(default) == str: func = str
        elif type(default) == float: func = float
        elif type(default) == bool: func = switch
        else: func = str

      if name in config:
        return func(config.pop(name))
      else:
        return default

    self.pagesize = opt('page.size', 'A4')

    self.titlepage = opt('title-page', True, switch)
    self.titlepage_margin_top = opt('title-page.margin.top', 128., float)
    self.titlepage_margin_bottom = opt('title-page.margin.bottom', 64., float)

    self.titlepage_title_font_name = opt('title-page.title.font.name', 'DejaVuSans-Bold')
    self.titlepage_title_font_size = opt('title-page.title.font.size', 48., float)
    self.titlepage_title_line_height = opt('title-page.title.line-height', 1.2*self.titlepage_title_font_size, float)

    self.titlepage_title_subtitle_spacing = opt('title-page.title-subtitle.spacing', 64., float)

    self.titlepage_subtitle_font_name = opt('title-page.subtitle.font.name', 'DejaVuSans')
    self.titlepage_subtitle_font_size = opt('title-page.subtitle.font.size', 32., float)
    self.titlepage_subtitle_line_height = opt('title-page.subtitle.line-height', 1.2*self.titlepage_subtitle_font_size, float)

    self.titlepage_author_font_name = opt('title-page.author.font.name', 'DejaVuSans')
    self.titlepage_author_font_size = opt('title-page.author.font.size', 24., float)
    self.titlepage_author_line_height = opt('title-page.author.line-height', 1.2*self.titlepage_author_font_size, float)

    self.notepage = opt('note-page', True, switch)
    self.notepage_margin_top = opt('note-page.margin.top', 64., float)
    self.notepage_margin_bottom = opt('note-page.margin.bottom', 64., float)
{'fraction_non_alphanumeric': 0.14755140979436082, 'fraction_numerical': 0.011871952512189952, 'mean_word_length': 3.5409047160731473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7159027', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1589, 'n_words': 336}