<commit_before># -*- coding: utf-8 -*-
##
##
## This file is part of Indico.
## Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).
##
## Indico is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.

# stdlib imports
import time, re, os
from random import randint
from datetime import datetime, date, timedelta

# 3rd party imports
from BTrees.OOBTree import OOBTree
from indico.util.date_time import format_datetime, format_date, format_time

# indico legacy imports
from MaKaC.common.timezoneUtils import isSameDay, isToday, getAdjustedDate,\
    isTomorrow
from MaKaC.common import info
from MaKaC import errors
from indico.core.db import DBMgr
from MaKaC.webinterface.linking import RoomLinker
from MaKaC.rb_location import CrossLocationQueries
from indico.core.config import Config

# indico imports
from indico.util.i18n import currentLocale


# fcntl is only available for POSIX systems
if os.name == 'posix':
    import fcntl

_KEY_DEFAULT_LENGTH = 20
_FAKENAME_SIZEMIN = 5
_FAKENAME_SIZEMAX = 10


### Backward-compatible utilities

from indico.util.string import truncate



def isWeekend( d ):
    """
    Accepts date or datetime object.
    """
    return d.weekday() in [5, 6]


HOLIDAYS_KEY = 'Holidays'
class HolidaysHolder:

    @classmethod
    def isWorkingDay( cls, d ):
        if isinstance( d, datetime ):
            d = d.date()
        if isWeekend( d ):
            return False
        return not cls.__getBranch().has_key( d )

    @classmethod
    def getHolidays( cls ):
        """
        Returns list of holidays
        """
        return cls.__getBranch().keys()

    @classmethod
    def insertHoliday( cls, d ):
        cls.__getBranch()[d] = None

    @classmethod
    def clearHolidays( cls ):
        root = DBMgr.getInstance().getDBConnection().root()
        root[HOLIDAYS_KEY] = OOBTree()

    @staticmethod
    def __getBranch():
        root = DBMgr.getInstance().getDBConnection().root()
        if not root.has_key( HOLIDAYS_KEY ):
            root[HOLIDAYS_KEY] = OOBTree()
        return root[HOLIDAYS_KEY]


def stringToDate( str ):
    months = { "January":1, "February":2, "March":3, "April":4, "May":5, "June":6, "July":7, "August":8, "September":9, "October":10, "November":11, "December":12 }
    [ day, month, year ] = str.split("-")

    if months.has_key(month):
        month = months[month]
    else:
        month = int(month)
    return datetime(int(year),month,int(day))

def getTextColorFromBackgroundColor(bgcolor):
    #Returns black if the average of the RGV values
    #is less than 128, and white if bigger.<commit_msg>[MIN] pep8 in old common utils<commit_after># -*- coding: utf-8 -*-
##
##
## This file is part of Indico.
## Copyright (C) 2002 - 2013 European Organization for Nuclear Research (CERN).
##
## Indico is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 3 of the
## License, or (at your option) any later version.
##
## Indico is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Indico;if not, see <http://www.gnu.org/licenses/>.

# stdlib imports
import time, re, os
from random import randint
from datetime import datetime, date, timedelta

# 3rd party imports
from BTrees.OOBTree import OOBTree
from indico.util.date_time import format_datetime, format_date, format_time

# indico legacy imports
from MaKaC.common.timezoneUtils import isSameDay, isToday, getAdjustedDate,\
    isTomorrow
from MaKaC.common import info
from MaKaC import errors
from MaKaC.webinterface.linking import RoomLinker

# indico imports
from indico.core.config import Config
from indico.core.db import DBMgr
from indico.util.i18n import currentLocale
# backward compatibility
from indico.util.string import truncate

# fcntl is only available for POSIX systems
if os.name == 'posix':
    import fcntl

_KEY_DEFAULT_LENGTH = 20
_FAKENAME_SIZEMIN = 5
_FAKENAME_SIZEMAX = 10


def isWeekend(d):
    """
    Accepts date or datetime object.
    """
    return d.weekday() in [5, 6]


# TODO: why don't we just use a set?
HOLIDAYS_KEY = 'Holidays'
class HolidaysHolder:

    @classmethod
    def isWorkingDay(cls, d):
        if isinstance(d, datetime):
            d = d.date()
        if isWeekend(d):
            return False
        return not cls.__getBranch().has_key(d)

    @classmethod
    def getHolidays(cls):
        """
        Returns list of holidays
        """
        return cls.__getBranch().keys()

    @classmethod
    def insertHoliday(cls, d):
        cls.__getBranch()[d] = None

    @classmethod
    def clearHolidays(cls):
        root = DBMgr.getInstance().getDBConnection().root()
        root[HOLIDAYS_KEY] = OOBTree()

    @staticmethod
    def __getBranch():
        root = DBMgr.getInstance().getDBConnection().root()
        if not root.has_key(HOLIDAYS_KEY):
            root[HOLIDAYS_KEY] = OOBTree()
        return root[HOLIDAYS_KEY]


def stringToDate( str ):
    months = { "January":1, "February":2, "March":3, "April":4, "May":5, "June":6, "July":7, "August":8, "September":9, "October":10, "November":11, "December":12 }
    [ day, month, year ] = str.split("-")

    if months.has_key(month):
        month = months[month]
    else:
        month = int(month)
    return datetime(int(year),month,int(day))

def getTextColorFromBackgroundColor(bgcolor):
    #Returns black if the average of the RGV values
    #is less than 128, and white if bigger.
{'fraction_non_alphanumeric': 0.10279930412778744, 'fraction_numerical': 0.012177763719753282, 'mean_word_length': 3.441011235955056, 'pattern_counts': {'":': 24, '<': 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': '4094132', 'n_tokens_mistral': 2017, 'n_tokens_neox': 1918, 'n_words': 659}