6.14.6.3. Body Output and Mode Control

Comienzo python section to interscript/weavers/xml.py[4 /22 ] Siguiente Previo Primero Ăšltimo
    69: #line 78 "xml_weaver.ipk"
    70:   def _setmode(self,mode):
    71:     self._write('\n<'+mode+'>')
    72:     self.mode = mode
    73: 
    74:   def _endmode(self):
    75:     if self.mode:
    76:       self._write('</'+self.mode+'>\n')
    77:       self.mode = None
    78: 
    79:   def _startmode(self,mode):
    80:     self._endmode()
    81:     self._setmode(mode)
    82: 
    83:   def _ensuremode(self,mode):
    84:     if self.mode != mode : self._startmode(mode)
    85: 
    86:   def _writeline(self,line=''):
    87:     if self.enabled: self.sink.writeline(line)
    88: 
    89:   def _write(self,line):
    90:     if self.enabled: self.sink.write(line)
    91: 
    92:   def writeline(self,line=''):
    93:     self.write(line + '\n')
    94: 
    95:   def write(self,line):
    96:     #hack to correct bug in popular broswers
    97:     #if not self.mode: self._setmode('P')
    98:     if self.translating:
    99:       self._write(cvt_text(line))
   100:     else:
   101:       self._write(line)
   102: 
   103:   def writecode(self,line):
   104:     self._ensuremode('PRE')
   105:     self._writeline(cvt_code(line))
   106: 
   107:   def begin_displayed_text(self):
   108:     self._ensuremode('P')
   109:     # note this is HTML 2, HTML 3 uses BQ instead
   110:     self.write('<BLOCKQUOTE>')
   111: 
   112:   def end_displayed_text(self):
   113:     self.write('</BLOCKQUOTE>')
   114: 
   115:   def begin_displayed_code(self):
   116:     self._write('<PRE>\n')
   117: 
   118:   def end_displayed_code(self):
   119:     self._write('</PRE>')
   120: 
   121:   def line_break(self):
   122:     self._writeline('<BR>')
   123: 
   124:   def page_break(self):
   125:     self._writeline('<BR><HR>')
   126: 
   127:   def write_tagged(self,tag, data):
   128:     self._write('<'+tag+'>')
   129:     self._writeline(data)
   130:     self._write('</'+tag+'>')
   131: 
   132:   def label_chunk(self, filename):
   133:     self._ensuremode('PRE')
   134:     self._write('<I>include</I> <STRONG>')
   135:     self._writeline(cvt_code(filename)+'</STRONG>')
   136: 
   137:   def _write_section_ref(self, filename, index):
   138:     name = filename + '['+str(index+1)+']'
   139:     anchor = '<A HREF="'+self.get_anchor(name)+'">'+str(index+1)+'</A>'
   140:     self._writeline (anchor+' ')
   141: 
   142:   def code_head(self,tangler, secno):
   143:     if tangler:
   144:       self._endmode()
   145:       filename =tangler.sink.get_sink_name()
   146:       language = tangler.get_language()
   147:       w = self._writeline
   148:       w ( '<DIV CLASS="CODE_SECTION_HEAD"><SMALL>Start <EM>'+\
   149:         language+'</EM> section to <STRONG>'+\
   150:         filename+'['+str(secno)+']</STRONG></SMALL>')
   151:       dict = self.master.section_index
   152:       if dict.has_key(filename):
   153:         nsections = len(dict[filename])
   154:         for i in range(nsections):
   155:           self._write_section_ref(filename, i)
   156:       w ('</DIV>')
   157:       w ( '<DIV CLASS="CODE">')
   158: 
   159: 
   160:   def code_foot(self,tangler, secno):
   161:     if tangler:
   162:       self._endmode()
   163:       filename =tangler.sink.get_sink_name()
   164:       language = tangler.get_language()
   165:       self._write( '</DIV><DIV CLASS="CODE_SECTION_FOOT"><SMALL>End <EM>'+\
   166:         language+'</EM> section to <STRONG>'+\
   167:         filename+'['+str(secno)+']</STRONG></SMALL></DIV>')
   168: 
   169:   def script_head(self,language,filename):
   170:       self._endmode()
   171:       self._writeline( '<DIV CLASS="CODE_SECTION_HEAD"><SMALL>Start <EM>'+\
   172:         language+'</EM> section from <STRONG>'+\
   173:         filename+'</STRONG></SMALL></DIV>')
   174:       self._writeline( '<DIV CLASS="CODE">')
   175: 
   176:   def script_foot(self,language,filename):
   177:       self._endmode()
   178:       self._write( '</DIV><DIV CLASS="CODE_SECTION_FOOT"><SMALL>End <EM>'+\
   179:         language+'</EM> section from <STRONG>'+\
   180:         filename+'</STRONG></SMALL></DIV>')
   181: 
   182:   def test_output_head(self,command, status):
   183:     self._endmode()
   184:     self._writeline( '<DIV CLASS="TEST_OUTPUT_SECTION_HEAD"><SMALL>Start <EM>'+\
   185:       'output</EM> section of <STRONG>'+\
   186:       cvt_code(command)+'</STRONG></SMALL></DIV>')
   187:     if status:
   188:       self._writeline( '<DIV CLASS="TEST_OUTPUT_RESULT">'+\
   189:         '<BIG>Command returned <STRONG>'+\
   190:         str(status)+'</STRONG></BIG></DIV>')
   191:     if status: div_class = 'BAD_TEST_OUTPUT'
   192:     else: div_class = 'TEST_OUTPUT'
   193:     self._writeline( '<DIV CLASS="'+div_class+'">')
   194: 
   195:   def test_output_foot(self,command,status):
   196:     self._endmode()
   197:     self._writeline( '</DIV><DIV CLASS="TEST_OUTPUT_SECTION_FOOT">')
   198:     self._writeline('<SMALL>End <EM>output</EM> section to <STRONG>'+\
   199:       cvt_code(command)+'</STRONG></SMALL></DIV>')
   200: 
   201:   def expected_head(self,command):
   202:     self._endmode()
   203:     self._writeline( '<DIV CLASS="EXPECTED_OUTPUT_SECTION_HEAD">'+\
   204:       '<SMALL>Start <EM>expected</EM> section of <STRONG>'+\
   205:       cvt_code(command)+'</STRONG></SMALL></DIV>')
   206:     div_class = 'EXPECTED_OUTPUT'
   207:     self._writeline( '<DIV CLASS="'+div_class+'">')
   208: 
   209:   def expected_foot(self,command):
   210:     self._endmode()
   211:     self._writeline( '</DIV><DIV CLASS="EXPECTED_OUTPUT_SECTION_FOOT">')
   212:     self._writeline('<SMALL>End <EM>expected</EM> section to <STRONG>'+\
   213:       cvt_code(command)+'</STRONG></SMALL></DIV>')
   214: 
   215:   def diff_head(self,command):
   216:     self._endmode()
   217:     self._writeline( '<DIV CLASS="DIFF_SECTION_HEAD"><SMALL>Start <EM>diff</EM> section of <STRONG>'+\
   218:       cvt_code(command)+'</STRONG></SMALL></DIV>')
   219:     div_class = 'DIFF'
   220:     self._writeline( '<DIV CLASS="'+div_class+'">')
   221: 
   222:   def diff_foot(self,command):
   223:     self._endmode()
   224:     self._writeline( '</DIV><DIV CLASS="DIFF_SECTION_FOOT">')
   225:     self._writeline('<SMALL>End <EM>diff</EM> section to <STRONG>'+\
   226:       cvt_code(command)+'</STRONG></SMALL></DIV>')
   227: 
End python section to interscript/weavers/xml.py[4]