235: #line 253 "text_weaver.ipk" 236: def writecode(self,line): 237: self._flush() 238: self._writeline(line) 239: 240: def echotangle(self,count,data): 241: self.writecode("%6d: %s" % (count,data)) 242: 243: def _write_word(self,word): 244: if self.c == 0: 245: self._write((' '*self.margin)+word) 246: elif self.c + len(word) < self.width: 247: self._write(' '+word) 248: else: 249: self._writeline() 250: self._write((' '*self.margin)+word) 251: 252: def _flush(self): 253: words = self.string.split(self.buffer) 254: for w in words: 255: self._write_word(w) 256: self.buffer = '' 257: 258: def write(self,line): 259: if self.translating: 260: if self.strong: line = string.upper(line) 261: self.buffer = self.buffer + line 262: else: 263: self._write(line) 264: 265: def writeline(self,line = ''): 266: if self.translating: 267: self.write(line) 268: if self.code: 269: self._writeline(self.buffer) 270: self.buffer = '' 271: else: 272: self._flush() 273: else: 274: self._writeline(line) 275: 276: def par(self): 277: self.line_break() 278: if not self.sop: 279: self._writeline() 280: self.sop = 1 281: 282: def line_break(self): 283: self._flush() 284: if self.c != 0: self._writeline() 285: 286: def page_break(self): 287: self.par() 288: self._writeline() 289: self._writeline('-' * self.width) 290: self._writeline() 291: self.sop = 1 292: 293: def begin_emphasize(self): 294: self.write('_') 295: 296: def end_emphasize(self): 297: self.write('_') 298: 299: def begin_strong(self): 300: self.strong = 1 301: 302: def end_strong(self): 303: self.strong = 0 304: 305: def begin_displayed_code(self): 306: self.par() 307: self.code = 1 308: 309: def end_displayed_code(self): 310: self.par() 311: self.code = 0 312: 313: def begin_displayed_text(self): 314: self.par() 315: self.margin = self.margin + 4 316: 317: def end_displayed_text(self): 318: self.par() 319: self.margin = self.margin - 4 320: 321: def new_heading(self,level): 322: while level>len(self.hcount): self.hcount.append(0) 323: while level<len(self.hcount): del self.hcount[-1] 324: counter = self.hcount[level-1]+1 325: self.hcount[level-1] = counter 326: return counter 327: 328: def get_formatted_heading_number(self, sep): 329: hnumber = '' 330: for i in range(0,len(self.hcount)-1): 331: hnumber = hnumber + str(self.hcount[i])+sep 332: hnumber = hnumber + str(self.hcount[-1]) 333: return hnumber 334: 335: def head(self,level, text, **kwds): 336: atext=kwds.get('short_text') 337: anchor=kwds.get('key','') 338: self.par() 339: self.strong = 0 340: self.new_heading(level) 341: h = self.get_formatted_heading_number('.')+'. '+text 342: if anchor: h=h + '['+anchor+']' 343: self.toc.append((level,text,self.sink.lines_written)) 344: self._writeline(h) 345: self._writeline('-'*len(h)) 346: self._writeline() 347: 348: def code_head(self,tangler, secno): 349: if tangler: 350: self.par() 351: language = tangler.get_language() 352: filename =tangler.sink.get_sink_name() 353: self._writeline( 'Start '+language+' section to '+\ 354: filename+'['+str(secno)+']') 355: self._writeline() 356: 357: def code_foot(self,tangler,secno): 358: if tangler: 359: self.par() 360: language = tangler.get_language() 361: filename =tangler.sink.get_sink_name() 362: self._writeline() 363: self._writeline( 'End '+language+' section to '+filename+\ 364: '['+str(secno)+']') 365: self.par() 366: 367: def test_output_head(self,command, status): 368: self.par() 369: self._writeline( 'Start output section of '+command) 370: if status: 371: self._writeline( 'Command returned '+str(status)) 372: self.par() 373: 374: def test_output_foot(self,command,status): 375: self.par() 376: self._writeline('End output section of '+command) 377: self.par() 378: 379: def expected_head(self,command): 380: self.par() 381: self._writeline( 'Start expected section of '+command) 382: self.par() 383: 384: def expected_foot(self,command): 385: self.par() 386: self._writeline('End expected section of '+command) 387: self.par() 388: 389: def diff_head(self,command): 390: self.par() 391: self._writeline( 'Start diff section of '+command) 392: self.par() 393: 394: def diff_foot(self,command): 395: self.par() 396: self._writeline('End diff section of '+command) 397: self.par() 398: 399: def __del__(self): 400: self._flush() 401: if self.c != 0: 402: self._writeline() 403: self.persistent_frame['contents']=self.toc 404: