<s> import os <EOL> import re <EOL> import sys <EOL> import warnings <EOL> __version__ = '<STR_LIT>' <EOL> line_re = re . compile ( r"""<STR_LIT>""" , re . VERBOSE ) <EOL> variable_re = re . compile ( r"""<STR_LIT>""" , re . IGNORECASE | re . VERBOSE ) <EOL> def read_dotenv ( dotenv = None ) : <EOL> """<STR_LIT>""" <EOL> if dotenv is None : <EOL> frame_filename = sys . _getframe ( ) . f_back . f_code . co_filename <EOL> dotenv = os . path . join ( os . path . dirname ( frame_filename ) , '<STR_LIT>' ) <EOL> if os . path . isdir ( dotenv ) and os . path . isfile ( os . path . join ( dotenv , '<STR_LIT>' ) ) : <EOL> dotenv = os . path . join ( dotenv , '<STR_LIT>' ) <EOL> if os . path . exists ( dotenv ) : <EOL> with open ( dotenv ) as f : <EOL> for k , v in parse_dotenv ( f . read ( ) ) . items ( ) : <EOL> os . environ . setdefault ( k , v ) <EOL> else : <EOL> warnings . warn ( "<STR_LIT>" . format ( dotenv ) ) <EOL> def parse_dotenv ( content ) : <EOL> env = { } <EOL> for line in content . splitlines ( ) : <EOL> m1 = line_re . search ( line ) <EOL> if m1 : <EOL> key , value = m1 . groups ( ) <EOL> if value is None : <EOL> value = '<STR_LIT>' <EOL> value = value . strip ( ) <EOL> m2 = re . match ( r'<STR_LIT>' , value ) <EOL> if m2 : <EOL> quotemark , value = m2 . groups ( ) <EOL> else : <EOL> quotemark = None <EOL> if quotemark == '<STR_LIT:">' : <EOL> value = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , value ) <EOL> if quotemark != "<STR_LIT:'>" : <EOL> for parts in variable_re . findall ( value ) : <EOL> if parts [ <NUM_LIT:0> ] == '<STR_LIT:\\>' : <EOL> replace = '<STR_LIT>' . join ( parts [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) <EOL> else : <EOL> replace = env . get ( <EOL> parts [ - <NUM_LIT:1> ] , <EOL> os . environ . get ( parts [ - <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> ) <EOL> value = value . replace ( '<STR_LIT>' . join ( parts [ <NUM_LIT:0> : - <NUM_LIT:1> ] ) , replace ) <EOL> env [ key ] = value <EOL> elif not re . search ( r'<STR_LIT>' , line ) : <EOL> warnings . warn ( <EOL> "<STR_LIT>" . format ( repr ( line ) ) , <EOL> SyntaxWarning <EOL> ) <EOL> return env </s>
