<commit_before># -*- coding: utf-8 -*-
import json
import os
import re
import threading
from os.path import isfile
from time import sleep
from urllib import urlopen
from datetime import date, datetime
from decimal import Decimal
import wx
from base_system import Tools, Settings, log

__author__ = '<NAME>'


def path_finder(filen, foldern=None, root_path=None):
    """
    filen:      Oluşturulacak dosya
    foldern:    Belirtilmişse oluşturulacak dosya bu alt klasör oluşturulup, alt klasörün altına oluşturulur.
    root_path:  Belirtilmemişse öntanımlı olarak Settings.PROJECT_ROOT kullanılır.
    full_path:  Dosyanın nihai yolunu belirtir.
    """
    full_path = None
    try:
        if root_path is None:       # Elle root path verilmemişse öntanımlı olarak Settings.PROJECT_ROOT kullanılır.
            root_path = Settings.PROJECT_ROOT

        if foldern is None:         # Alt klasör belirtilmemişse dosyayı buraya oluşturur.
            full_path = '{root_path}/{filen}'.format(root_path=root_path, filen=filen)
        else:                       # Alt klasör belirtilmişse klasör oluşturup dosyayı alt klasör içine oluşturur.
            if not Tools().check_foldr(foldern):  # Klasörün var olup olmadığını kontrol eder, yoksa oluşturur.
                Tools().create_foldr(foldern)
            full_path = '{root_path}/{foldern}/{filen}'.format(root_path=root_path, foldern=foldern, filen=filen)
    except Exception as e:
        log.exception(e.message)
        log.error(u"%s error." % filen)
    return full_path


class FetchCaptcha(threading.Thread):
    def __init__(self, parent):
        """
        Captcha resmini siteden çekip dosyaya yazar ve dosyadan okuyup ekrana basar.
        """
        super(FetchCaptcha, self).__init__()
        self._stop = threading.Event()
        self.parent = parent
        self.log = log

        self.captcha_folder_name = 'media'
        self.captcha_file_name = 'captcha.jpeg'
        self.captcha_file = path_finder(self.captcha_file_name, foldern=self.captcha_folder_name)

    def stop(self):
        """
        Stops The Thread
        """
        self.parent.stat_gauge.SetValue(0)
        self._stop.set()

    def stopped(self):
        """
        Returns Thread Status
        """
        return self._stop.isSet()

    def _check_file(self, operation):
        """
        Captcha dosyası üzerinde işlem yapmaya yarar;

        Eğer işlem 'd' ya da 'r' DEĞİLSE ise gönderilen binary'i captcha dosyasına yazar ('w' yerine).
        'd' : Eğer işlem 'd' ise captcha dosyasını dosya sisteminden siler.
        'r' : Eğer işlem 'r' ise captcha dosyasını okuyup ekrana basar.
        """
        if operation == 'd':
            try:
                os.remove(self.captcha_file)
            except OSError as e:
                self.log.error(repr(e.message))
                self.log.error(u"No file: %s" % self.captcha_file)

        elif operation == 'r':
            if isfile(self.captcha_file):
                jpg_image = wx.Image(self.captcha_file, wx.BITMAP_TYPE_JPEG)
                self.parent.captcha_image.SetBitmap(wx.BitmapFromImage(jpg_image))
            else:
                raise Exception("- No File: %s" % self.captcha_file)

        else:
            try:
                with open(self.captcha_file, mode='wb') as _file:
                    _file.write(operation)
            except Exception as e:
                self.log.error(e.message)
                raise Exception(u"> ERROR: File can't created...")

    def _fetch_captcha(self):
        """
        Login ekranındaki captcha dosyasını çekip dosyaya yazar.
        """
        try:
            self._check_file(self.captcha_fetcher_method_from_outer_class())
        except Exception as e:
            self.log.error(e.message)
            raise Exception(u'> ERROR: File cant read...')

    def run(self):
        """
        Event tarafından çalıştırılan method. (Event tetiklendiğinde Class içinde ilk çalışan methoddur)
        """
        self.parent.stat_gauge.Pulse()<commit_msg>Initial<commit_after># -*- coding: utf-8 -*-
import json
import os
import re
import threading
from os.path import isfile
from time import sleep
from urllib import urlopen
from datetime import date, datetime
from decimal import Decimal
import wx
from base_system import Tools, Settings, log

__author__ = '<NAME>'


def path_finder(filen, foldern=None, root_path=None):
    """
    filen:      Fale name
    foldern:    Subfolder name
    root_path:  Default Settings.PROJECT_ROOT
    full_path:  full file path
    """
    full_path = None
    try:
        if root_path is None:
            root_path = Settings.PROJECT_ROOT

        if foldern is None:
            full_path = '{root_path}/{filen}'.format(root_path=root_path, filen=filen)
        else:
            if not Tools().check_foldr(foldern):
                Tools().create_foldr(foldern)
            full_path = '{root_path}/{foldern}/{filen}'.format(root_path=root_path, foldern=foldern, filen=filen)
    except Exception as e:
        log.exception(e.message)
        log.error(u"%s error." % filen)
    return full_path


class FetchCaptcha(threading.Thread):
    def __init__(self, parent):
        """
        Read captcha from url and write into file
        """
        super(FetchCaptcha, self).__init__()
        self._stop = threading.Event()
        self.parent = parent
        self.log = log

        self.captcha_folder_name = 'media'
        self.captcha_file_name = 'captcha.jpeg'
        self.captcha_file = path_finder(self.captcha_file_name, foldern=self.captcha_folder_name)

    def stop(self):
        """
        Stops The Thread
        """
        self.parent.stat_gauge.SetValue(0)
        self._stop.set()

    def stopped(self):
        """
        Returns Thread Status
        """
        return self._stop.isSet()

    def _check_file(self, operation):
        """
        Captcha dosyası üzerinde işlem yapmaya yarar;

        If operation not 'd' or 'r', file mode will be "wb"
        'd' : Delete file from file system
        'r' : Read file
        """
        if operation == 'd':
            try:
                os.remove(self.captcha_file)
            except OSError as e:
                self.log.error(repr(e.message))
                self.log.error(u"No file: %s" % self.captcha_file)

        elif operation == 'r':
            if isfile(self.captcha_file):
                jpg_image = wx.Image(self.captcha_file, wx.BITMAP_TYPE_JPEG)
                self.parent.captcha_image.SetBitmap(wx.BitmapFromImage(jpg_image))
            else:
                raise Exception("- No File: %s" % self.captcha_file)

        else:
            try:
                with open(self.captcha_file, mode='wb') as _file:
                    _file.write(operation)
            except Exception as e:
                self.log.error(e.message)
                raise Exception(u"> ERROR: File can't created...")

    def _fetch_captcha(self):
        """
        Read captcha from url.
        """
        try:
            self._check_file(self.captcha_fetcher_method_from_outer_class())
        except Exception as e:
            self.log.error(e.message)
            raise Exception(u'> ERROR: File cant read...')

    def run(self):
        """
        Event method.
        """
        self.parent.stat_gauge.Pulse()
{'fraction_non_alphanumeric': 0.09659863945578231, 'fraction_numerical': 0.0005442176870748299, 'mean_word_length': 2.129416773094934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '7494458', 'n_tokens_mistral': 2433, 'n_tokens_neox': 2315, 'n_words': 550}