<s> import os <EOL> import subprocess <EOL> from django . core . files . temp import NamedTemporaryFile <EOL> from django . db . backends . base . client import BaseDatabaseClient <EOL> from django . utils . six import print_ <EOL> def _escape_pgpass ( txt ) : <EOL> """<STR_LIT>""" <EOL> return txt . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( '<STR_LIT::>' , '<STR_LIT>' ) <EOL> class DatabaseClient ( BaseDatabaseClient ) : <EOL> executable_name = '<STR_LIT>' <EOL> @ classmethod <EOL> def runshell_db ( cls , settings_dict ) : <EOL> args = [ cls . executable_name ] <EOL> host = settings_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> port = settings_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> name = settings_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> user = settings_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> passwd = settings_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if user : <EOL> args += [ '<STR_LIT>' , user ] <EOL> if host : <EOL> args += [ '<STR_LIT>' , host ] <EOL> if port : <EOL> args += [ '<STR_LIT>' , str ( port ) ] <EOL> args += [ name ] <EOL> temp_pgpass = None <EOL> try : <EOL> if passwd : <EOL> temp_pgpass = NamedTemporaryFile ( mode = '<STR_LIT>' ) <EOL> try : <EOL> print_ ( <EOL> _escape_pgpass ( host ) or '<STR_LIT:*>' , <EOL> str ( port ) or '<STR_LIT:*>' , <EOL> _escape_pgpass ( name ) or '<STR_LIT:*>' , <EOL> _escape_pgpass ( user ) or '<STR_LIT:*>' , <EOL> _escape_pgpass ( passwd ) , <EOL> file = temp_pgpass , <EOL> sep = '<STR_LIT::>' , <EOL> flush = True , <EOL> ) <EOL> os . environ [ '<STR_LIT>' ] = temp_pgpass . name <EOL> except UnicodeEncodeError : <EOL> pass <EOL> subprocess . call ( args ) <EOL> finally : <EOL> if temp_pgpass : <EOL> temp_pgpass . close ( ) <EOL> if '<STR_LIT>' in os . environ : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> def runshell ( self ) : <EOL> DatabaseClient . runshell_db ( self . connection . settings_dict ) </s>
