# -*- coding: utf-8 -*-
"""
<DefineSource>
@Date : Fri Nov 14 13:20:38 2014 \n
@Author : Erwan Ledoux \n\n
</DefineSource>
The Capturer
"""
#<DefineAugmentation>
import ShareYourSystem as SYS
BaseModuleStr="ShareYourSystem.Interfacers.Hdformater"
DecorationModuleStr="ShareYourSystem.Classors.Classer"
SYS.setSubModule(globals())
#</DefineAugmentation>
#<ImportSpecificModules>
from cStringIO import StringIO
import sys
import copy
#</ImportSpecificModules>
#<DefineClass>
@DecorationClass()
class CapturerClass(BaseClass):
#Definition
RepresentingKeyStrsList=[
'CapturingStopBool',
'CapturedStdoutVariable',
'CapturedPrintStrsList'
]
def default_init(self,
_CapturingStopBool={
'DefaultingSetType':property,
'PropertizingInitVariable':False,
'PropertizingDocStr':''
},
_CapturedStdoutVariable=sys.stdout,
_CapturedPrintStrsList=None,
**_KwargVariablesDict
):
#Call the parent __init__ method
BaseClass.__init__(self,**_KwargVariablesDict)
def setCapturingStopBool(self,_SettingValueVariable):
#set
self._CapturingStopBool=_SettingValueVariable
#reset the CapturedStrsList
if _SettingValueVariable:
#Check
if self.CapturedPrintStrsList!=None:
if hasattr(sys.stdout,'getvalue'):
#extend
self.CapturedPrintStrsList.extend(
sys.stdout.getvalue().splitlines()
)
#reset
sys.stdout = self.CapturedStdoutVariable
def do_capture(self):
#debug
'''
self.debug('We capture here ')
'''
#set
self.CapturedStdoutVariable = sys.stdout
#init
sys.stdout = StringIO()
#Return self
#return self
#</DefineClass>
View the Capturer sources on Github
In [3]:
#ImportModules
import ShareYourSystem as SYS
from ShareYourSystem.Interfacers import Capturer
#Definition a Capturer
MyCapturer=Capturer.CapturerClass().capture()
print('Hello !')
print('Bonjour !')
MyCapturer.CapturingStopBool=True
print('Y a quelqu un?')
#Definition the AttestedStr
SYS._attest(
[
'MyCapturer is '+SYS._str(
MyCapturer,
**{
'RepresentingBaseKeyStrsListBool':False
}
)
]
)
#Print