<commit_before>##
# copyright 2009, <NAME>
# http://python.projects.postgresql.org
##
"""
Python command with a PG-API connection.
"""
import os
import sys
import re
import code
import optparse
import contextlib
from .. import clientparameters
from ..resolved import pythoncommand as pycmd
from .. import __version__

from ..driver import default as pg_driver
from .. import exceptions as pg_exc

pq_trace = optparse.make_option(
	'--pq-trace',
	dest = 'pq_trace',
	help = 'trace PQ protocol transmissions',
	default = None,
)
default_options = [
	pq_trace,
] + pycmd.default_optparse_options

def command(argv = sys.argv):
	p = clientparameters.DefaultParser(
		"%prog [connection options] [script] ...",
		version = __version__,
		option_list = default_options
	)
	p.disable_interspersed_args()
	co, ca = p.parse_args(argv[1:])

	need_prompt = False
	cond = None
	connector = None
	connection = None
	while connection is None:
		try:
			cond = clientparameters.standard(co = co, prompt_title = None)
			if need_prompt:
				# authspec error thrown last time
				cond['prompt_password'] = True
			try:
				clientparameters.resolve_password(cond, prompt_title = 'pg_python')
			except EOFError:
				sys.stderr.write(os.linesep + "ERROR: session aborted" + os.linesep)
				raise SystemExit(1)
			connector = pg_driver.create(**cond)
			connection = connector()
		except pg_exc.ClientCannotConnectError as err:
			for (didssl, sc, cf) in err.connection_failures:
				if isinstance(cf, pg_exc.AuthenticationSpecificationError):
					sys.stderr.write(os.linesep + cf.message + (os.linesep*2))
					# keep prompting the user
					need_prompt = True
					break
			else:
				# no invalid password failures..
				raise

	pythonexec = pycmd.Execution(ca,
		context = getattr(co, 'python_context', None),<commit_msg>Remove "session abort" error printout.<commit_after>##
# copyright 2009, <NAME>
# http://python.projects.postgresql.org
##
"""
Python command with a PG-API connection.
"""
import os
import sys
import re
import code
import optparse
import contextlib
from .. import clientparameters
from ..resolved import pythoncommand as pycmd
from .. import __version__

from ..driver import default as pg_driver
from .. import exceptions as pg_exc

pq_trace = optparse.make_option(
	'--pq-trace',
	dest = 'pq_trace',
	help = 'trace PQ protocol transmissions',
	default = None,
)
default_options = [
	pq_trace,
] + pycmd.default_optparse_options

def command(argv = sys.argv):
	p = clientparameters.DefaultParser(
		"%prog [connection options] [script] ...",
		version = __version__,
		option_list = default_options
	)
	p.disable_interspersed_args()
	co, ca = p.parse_args(argv[1:])

	need_prompt = False
	cond = None
	connector = None
	connection = None
	while connection is None:
		try:
			cond = clientparameters.standard(co = co, prompt_title = None)
			if need_prompt:
				# authspec error thrown last time
				cond['prompt_password'] = True
			try:
				clientparameters.resolve_password(cond, prompt_title = 'pg_python')
			except EOFError:
				raise SystemExit(1)
			connector = pg_driver.create(**cond)
			connection = connector()
		except pg_exc.ClientCannotConnectError as err:
			for (didssl, sc, cf) in err.connection_failures:
				if isinstance(cf, pg_exc.AuthenticationSpecificationError):
					sys.stderr.write(os.linesep + cf.message + (os.linesep*2))
					# keep prompting the user
					need_prompt = True
					break
			else:
				# no invalid password failures..
				raise

	pythonexec = pycmd.Execution(ca,
		context = getattr(co, 'python_context', None),
{'fraction_non_alphanumeric': 0.10443571027512634, 'fraction_numerical': 0.0039303761931499155, 'mean_word_length': 4.068278805120911, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4122458', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1109, 'n_words': 312}