<s> import datetime <EOL> import sys <EOL> import arrow <EOL> from . version import VERSION <EOL> PY3 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:3> <EOL> if PY3 : <EOL> string_types = str <EOL> else : <EOL> string_types = basestring <EOL> __author__ = '<STR_LIT>' <EOL> __version__ = VERSION <EOL> def to_universal ( local_dt , timezone = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( local_dt , ( int , float ) ) : <EOL> if timezone is not None : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> return from_unix ( local_dt ) <EOL> elif isinstance ( local_dt , string_types ) : <EOL> local_dt = arrow . get ( local_dt ) . to ( '<STR_LIT>' ) . naive <EOL> return from_local ( local_dt , timezone ) <EOL> def from_local ( local_dt , timezone = None ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( local_dt , datetime . datetime ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if timezone is None : <EOL> a = arrow . get ( local_dt ) <EOL> else : <EOL> a = arrow . get ( local_dt , timezone ) <EOL> return a . to ( '<STR_LIT>' ) . naive <EOL> def from_unix ( ut ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( ut , ( int , float ) ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> return arrow . get ( ut ) . naive <EOL> def to_local ( dt , timezone ) : <EOL> """<STR_LIT>""" <EOL> if dt . tzinfo is not None : <EOL> raise ValueError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> if not isinstance ( timezone , string_types ) : <EOL> raise TypeError ( '<STR_LIT>' . format ( type ( timezone ) ) ) <EOL> return arrow . get ( dt ) . to ( timezone ) . datetime <EOL> def to_unix ( dt ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( dt , datetime . datetime ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> return arrow . get ( dt ) . timestamp <EOL> def format ( dt , timezone , fmt = None ) : <EOL> """<STR_LIT>""" <EOL> local = to_local ( dt , timezone ) <EOL> if fmt is None : <EOL> return local . isoformat ( ) <EOL> else : <EOL> return local . strftime ( fmt ) <EOL> now = datetime . datetime . utcnow </s>
