(
mycli: 'MyCli',
string: str,
_render_counter: int,
)
| 272 | |
| 273 | @functools.lru_cache(maxsize=256) |
| 274 | def render_prompt_string( |
| 275 | mycli: 'MyCli', |
| 276 | string: str, |
| 277 | _render_counter: int, |
| 278 | ) -> FormattedText: |
| 279 | sqlexecute = mycli.sqlexecute |
| 280 | assert sqlexecute is not None |
| 281 | if mycli.login_path and mycli.login_path_as_host: |
| 282 | prompt_host = mycli.login_path |
| 283 | elif sqlexecute.host is not None: |
| 284 | prompt_host = sqlexecute.host |
| 285 | else: |
| 286 | prompt_host = DEFAULT_HOST |
| 287 | short_prompt_host, _, _ = prompt_host.partition('.') |
| 288 | if re.match(r'^[\d\.]+$', short_prompt_host): |
| 289 | short_prompt_host = prompt_host |
| 290 | now = datetime.now() |
| 291 | species_name = sqlexecute.server_info.species.name if sqlexecute.server_info and sqlexecute.server_info.species else 'MySQL' |
| 292 | strings = string.split('\\\\') |
| 293 | is_html = strings[0].startswith('\\<html>') |
| 294 | strings = [x.replace('\\u', maybe_html_escape(sqlexecute.user or '(none)', is_html)) for x in strings] |
| 295 | strings = [x.replace('\\h', maybe_html_escape(prompt_host or '(none)', is_html)) for x in strings] |
| 296 | strings = [x.replace('\\H', maybe_html_escape(short_prompt_host or '(none)', is_html)) for x in strings] |
| 297 | strings = [x.replace('\\d', maybe_html_escape(sqlexecute.dbname or '(none)', is_html)) for x in strings] |
| 298 | strings = [x.replace('\\t', maybe_html_escape(species_name, is_html)) for x in strings] |
| 299 | strings = [x.replace('\\n', '\n') for x in strings] |
| 300 | strings = [x.replace('\\D', maybe_html_escape(now.strftime('%a %b %d %H:%M:%S %Y'), is_html)) for x in strings] |
| 301 | strings = [x.replace('\\m', maybe_html_escape(now.strftime('%M'), is_html)) for x in strings] |
| 302 | strings = [x.replace('\\P', maybe_html_escape(now.strftime('%p'), is_html)) for x in strings] |
| 303 | strings = [x.replace('\\R', maybe_html_escape(now.strftime('%H'), is_html)) for x in strings] |
| 304 | strings = [x.replace('\\r', maybe_html_escape(now.strftime('%I'), is_html)) for x in strings] |
| 305 | strings = [x.replace('\\s', maybe_html_escape(now.strftime('%S'), is_html)) for x in strings] |
| 306 | strings = [x.replace('\\p', maybe_html_escape(str(sqlexecute.port), is_html)) for x in strings] |
| 307 | strings = [ |
| 308 | x.replace('\\j', maybe_html_escape(os.path.basename(sqlexecute.socket or '(none)').replace('\\', '/'), is_html)) for x in strings |
| 309 | ] |
| 310 | strings = [x.replace('\\J', maybe_html_escape((sqlexecute.socket or '(none)').replace('\\', '/'), is_html)) for x in strings] |
| 311 | strings = [ |
| 312 | x.replace('\\k', maybe_html_escape(os.path.basename(sqlexecute.socket or str(sqlexecute.port)).replace('\\', '/'), is_html)) |
| 313 | for x in strings |
| 314 | ] |
| 315 | strings = [ |
| 316 | x.replace('\\K', maybe_html_escape((sqlexecute.socket or str(sqlexecute.port)).replace('\\', '/'), is_html)) for x in strings |
| 317 | ] |
| 318 | strings = [x.replace('\\A', maybe_html_escape(mycli.dsn_alias or '(none)', is_html)) for x in strings] |
| 319 | strings = [x.replace('\\_', ' ') for x in strings] |
| 320 | |
| 321 | checker_string = ' '.join(strings) |
| 322 | if hasattr(sqlexecute, 'conn') and sqlexecute.conn is not None: |
| 323 | if '\\y' in checker_string: |
| 324 | with sqlexecute.conn.cursor() as cur: |
| 325 | strings = [x.replace('\\y', maybe_html_escape(str(get_uptime(cur)) or '(none)', is_html)) for x in strings] |
| 326 | if '\\Y' in checker_string: |
| 327 | with sqlexecute.conn.cursor() as cur: |
| 328 | strings = [x.replace('\\Y', maybe_html_escape(format_uptime(str(get_uptime(cur))) or '(none)', is_html)) for x in strings] |
| 329 | else: |
| 330 | strings = [x.replace('\\y', '(none)') for x in strings] |
| 331 | strings = [x.replace('\\Y', '(none)') for x in strings] |
no test coverage detected