<commit_before>=======
py.io
=======

.. contents::
.. sectnum::

The 'py' lib provides helper classes for capturing IO during
execution of a program. 

IO Capturing examples
===============================================

:api:`py.io.StdCapture`
---------------------------

Basic Example: 

  >>> import py
  >>> capture = py.io.StdCapture()
  >>> print "hello"
  >>> out,err = capture.reset()
  >>> out.strip() == "hello"
  True

For calling functions you may use a shortcut: 
  >>> import py
  >>> def f(): print "hello"
  >>> res, out, err = py.io.StdCapture.call(f)
  >>> out.strip() == "hello"
  True

:api:`py.io.StdCaptureFD`
---------------------------

If you also want to capture writes to the stdout/stdin
filedescriptors you may invoke: 

  >>> import py, sys
  >>> capture = py.io.StdCaptureFD()
  >>> sys.stdout.write("hello")
  >>> sys.stderr.write("world")
  >>> out,err = capture.reset()
  >>> out.strip() + err.strip() == "helloworld"
  True<commit_msg>[svn r38104] fixing this so "py.test -s" passes on this as well<commit_after>=======
py.io
=======

.. contents::
.. sectnum::

The 'py' lib provides helper classes for capturing IO during
execution of a program. 

IO Capturing examples
===============================================

:api:`py.io.StdCapture`
---------------------------

Basic Example: 

  >>> import py
  >>> capture = py.io.StdCapture()
  >>> print "hello"
  >>> out,err = capture.reset()
  >>> out.strip() == "hello"
  True

For calling functions you may use a shortcut: 
  >>> import py
  >>> def f(): print "hello"
  >>> res, out, err = py.io.StdCapture.call(f)
  >>> out.strip() == "hello"
  True

:api:`py.io.StdCaptureFD`
---------------------------

If you also want to capture writes to the stdout/stderr
filedescriptors you may invoke: 

  >>> import py, sys
  >>> capture = py.io.StdCaptureFD()
  >>> sys.stderr.write("world")
  >>> out,err = capture.reset()
  >>> err
  'world'
{'fraction_non_alphanumeric': 0.2670807453416149, 'fraction_numerical': 0.002587991718426501, 'mean_word_length': 2.928861788617886, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 90, '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': '5849111', 'n_tokens_mistral': 617, 'n_tokens_neox': 588, 'n_words': 175}