#NEWLINE# def _ToTimeZone( t , tzinfo ) : #NEWLINE# #INDENT# "Converts 't' to the time zone 'tzinfo'.\n\n  Arguments:\n    t: a datetime object.  It may be in any pytz time zone, or it may be\n        timezone-naive (interpreted as UTC).\n    tzinfo: a pytz timezone object, or None (interpreted as UTC).\n\n  Returns:\n    a datetime object in the time zone 'tzinfo'\n  " #NEWLINE# if ( pytz is None ) : #NEWLINE# #INDENT# return t . replace ( tzinfo = tzinfo ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if tzinfo : #NEWLINE# #INDENT# if ( not t . tzinfo ) : #NEWLINE# #INDENT# t = pytz . utc . localize ( t ) #NEWLINE# #UNINDENT# return tzinfo . normalize ( t . astimezone ( tzinfo ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if t . tzinfo : #NEWLINE# #INDENT# return pytz . utc . normalize ( t . astimezone ( pytz . utc ) ) . replace ( tzinfo = None ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return t