<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import abc <EOL> import os <EOL> import logging <EOL> from . utils import print_info <EOL> import six <EOL> try : <EOL> from dateutil . parser import parse as dtparse <EOL> except ImportError : <EOL> print_info ( """<STR_LIT>""" ) <EOL> from datetime import datetime <EOL> def dtparse ( dtstring ) : <EOL> """<STR_LIT>""" <EOL> return datetime . strptime ( dtstring , '<STR_LIT>' ) <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> try : <EOL> import yaml <EOL> except ImportError : <EOL> def load ( self , filename ) : <EOL> raise Exception ( "<STR_LIT>" . format ( filename ) ) <EOL> yaml = type ( '<STR_LIT>' , ( object , ) , { <EOL> '<STR_LIT>' : load <EOL> } ) ( ) <EOL> log = logging . getLogger ( __name__ ) <EOL> class FixtureLoader ( six . with_metaclass ( abc . ABCMeta , object ) ) : <EOL> @ abc . abstractmethod <EOL> def load ( self ) : <EOL> pass <EOL> class JSONLoader ( FixtureLoader ) : <EOL> extensions = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def load ( self , filename ) : <EOL> def _datetime_parser ( dct ) : <EOL> for key , value in list ( dct . items ( ) ) : <EOL> try : <EOL> dct [ key ] = dtparse ( value ) <EOL> except Exception : <EOL> pass <EOL> return dct <EOL> with open ( filename ) as fin : <EOL> return json . load ( fin , object_hook = _datetime_parser ) <EOL> class YAMLLoader ( FixtureLoader ) : <EOL> extensions = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def load ( self , filename ) : <EOL> with open ( filename ) as fin : <EOL> return yaml . load ( fin ) <EOL> def load ( filename ) : <EOL> name , extension = os . path . splitext ( filename ) <EOL> for cls in FixtureLoader . __subclasses__ ( ) : <EOL> if not hasattr ( cls , '<STR_LIT>' ) : <EOL> log . warn ( "<STR_LIT>" . format ( cls . __name__ ) ) <EOL> continue <EOL> for ext in cls . extensions : <EOL> if extension == ext : <EOL> return cls ( ) . load ( filename ) <EOL> raise Exception ( "<STR_LIT>" . format ( filename ) ) <EOL> def extensions ( ) : <EOL> return [ ext for c in FixtureLoader . __subclasses__ ( ) for ext in c . extensions ] </s>
