MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / _codecs_open

Function _codecs_open

lib/core/compat.py:389–427  ·  view source on GitHub ↗

Replacement for deprecated codecs.open() entry point with sqlmap-friendly behavior. - If encoding is None: return io.open(...) as-is. - If encoding is set: force underlying binary mode and wrap via StreamReaderWriter (like codecs.open()). - For write-ish modes: return a wrapp

(filename, mode="r", encoding=None, errors="strict", buffering=-1)

Source from the content-addressed store, hash-verified

387
388
389def _codecs_open(filename, mode="r", encoding=None, errors="strict", buffering=-1):
390 """
391 Replacement for deprecated codecs.open() entry point with sqlmap-friendly behavior.
392
393 - If encoding is None: return io.open(...) as-is.
394 - If encoding is set: force underlying binary mode and wrap via StreamReaderWriter
395 (like codecs.open()).
396 - For write-ish modes: return a wrapper that also accepts bytes on .write().
397 - Handles buffering=1 in binary mode by downgrading underlying buffering to -1,
398 while optionally preserving "flush on newline" behavior in the wrapper.
399 """
400 if encoding is None:
401 return io.open(filename, mode, buffering=buffering)
402
403 bmode = mode
404 if "b" not in bmode:
405 bmode += "b"
406
407 # Avoid line-buffering warnings/errors on binary streams
408 line_buffered = (buffering == 1)
409 if line_buffered:
410 buffering = -1
411
412 f = io.open(filename, bmode, buffering=buffering)
413
414 try:
415 info = codecs.lookup(encoding)
416 srw = codecs.StreamReaderWriter(f, info.streamreader, info.streamwriter, errors)
417 srw.encoding = encoding
418
419 if _is_write_mode(mode):
420 return MixedWriteTextIO(srw, encoding, errors, line_buffered=line_buffered)
421
422 return srw
423 except Exception:
424 try:
425 f.close()
426 finally:
427 raise
428
429codecs_open = _codecs_open if sys.version_info >= (3, 14) else codecs.open

Callers

nothing calls this directly

Calls 5

_is_write_modeFunction · 0.85
MixedWriteTextIOClass · 0.85
openMethod · 0.80
lookupMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…