<s> from string import maketrans <EOL> from . server import db <EOL> from . recording import Recording <EOL> from . recording_planner import RecordingPlanner <EOL> from . recording_manager import RecordingManager <EOL> from . recorder import Recorder <EOL> from . scheduler import Scheduler <EOL> from . hdhomerun import HDHomeRun <EOL> from . channel import Channel <EOL> from . category import Category <EOL> from . programme import Programme <EOL> from . schedule import Schedule <EOL> from . pvr_initializer import setup <EOL> from . database_initializer import * <EOL> def get_config_dir ( ) : <EOL> from . server import app <EOL> return os . path . abspath ( app . config [ '<STR_LIT>' ] ) <EOL> def safe_value ( x ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if type ( x ) == str : <EOL> return x <EOL> else : <EOL> return x . decode ( "<STR_LIT:utf-8>" ) <EOL> except UnicodeError : <EOL> try : <EOL> return x . encode ( "<STR_LIT:utf-8>" ) <EOL> except UnicodeError : <EOL> print ( u"<STR_LIT>" + x ) <EOL> return "<STR_LIT>" <EOL> def to_utf8 ( myStr ) : <EOL> if isinstance ( myStr , basestring ) : <EOL> if isinstance ( myStr , str ) : <EOL> return myStr . decode ( '<STR_LIT:utf-8>' , errors = '<STR_LIT:replace>' ) <EOL> else : <EOL> return myStr <EOL> def json_friendly_tuple ( x ) : <EOL> from collections import namedtuple <EOL> from datetime import datetime , date <EOL> from dateutil . tz import tzlocal <EOL> if not x : <EOL> return None <EOL> ProgrammeInformationTuple = namedtuple ( '<STR_LIT>' , [ '<STR_LIT:id>' , '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> tmp_dict = dict . fromkeys ( x . keys ( ) ) <EOL> for idx , key in enumerate ( x . keys ( ) ) : <EOL> if isinstance ( x [ idx ] , datetime ) or isinstance ( x [ idx ] , date ) : <EOL> tmp_dict [ key ] = x [ idx ] . replace ( tzinfo = tzlocal ( ) ) . isoformat ( ) <EOL> else : <EOL> tmp_dict [ key ] = x [ idx ] <EOL> return ProgrammeInformationTuple ( tmp_dict [ '<STR_LIT:id>' ] , tmp_dict [ '<STR_LIT:title>' ] , tmp_dict [ '<STR_LIT>' ] , tmp_dict [ '<STR_LIT>' ] ) <EOL> def safe_replace ( to_translate , chars_to_replace = u'<STR_LIT>' , translate_to = u'<STR_LIT:_>' ) : <EOL> if isinstance ( to_translate , unicode ) : <EOL> translate_table = dict ( ( ord ( char ) , unicode ( translate_to ) ) <EOL> for char in chars_to_replace ) <EOL> else : <EOL> assert isinstance ( to_translate , str ) <EOL> translate_table = maketrans ( chars_to_replace , translate_to * len ( chars_to_replace ) ) <EOL> return to_translate . translate ( translate_table ) </s>
