def format(self, document): L = [] arguments = self.arguments for x in self.pattern: if isinstance(x, strTypes): L.append(pdfdocEnc(x)) elif isinstance(x, PDFObject): L.append(x.format(document)) else: name = x[0] value = arguments.get(name, None) if value is None: raise ValueError("%s value not defined" % ascii(name)) if isinstance(value, PDFObject): L.append(format(value, document)) elif isinstance(value, strTypes): L.append(pdfdocEnc(value)) else: L.append(pdfdocEnc(str(value))) return b"".join(L)
def format(self, document): L = [] arguments = self.arguments from types import StringType, InstanceType for x in self.pattern: tx = type(x) if tx is StringType: L.append(x) elif tx is InstanceType: L.append(x.format(document)) else: name = x[0] value = arguments.get(name, None) if value is None: raise ValueError, "%s value not defined" % repr(name) if type(value) is InstanceType: #L.append( value.format(document) ) L.append(format(value, document)) else: L.append(str(value)) return string.join(L, "")
def format(self, document): L = [] arguments = self.arguments from types import StringType, InstanceType for x in self.pattern: tx = type(x) if tx is StringType: L.append(x) elif tx is InstanceType: L.append( x.format(document) ) else: name = x[0] value = arguments.get(name, None) if value is None: raise ValueError, "%s value not defined" % repr(name) if type(value) is InstanceType: #L.append( value.format(document) ) L.append(format(value, document)) else: L.append( str(value) ) return string.join(L, "")
def eval(self, L): arguments = self.arguments document = self.__document for x in L: if isinstance(x, strTypes): yield pdfdocEnc(x) elif isinstance(x, PDFObject): yield x.format(document) elif isinstance(x, PDFPatternIf): result = list(self.eval(x.cond)) cond = result and result[0] for z in self.eval(x.thenPart if cond else x.elsePart): yield z else: name = x[0] value = arguments.get(name, None) if value is None: raise ValueError("%s value not defined" % ascii(name)) if isinstance(value, PDFObject): yield format(value, document) elif isinstance(value, strTypes): yield pdfdocEnc(value) else: yield pdfdocEnc(str(value))
def eval(self,L): arguments = self.arguments document = self.__document for x in L: if isinstance(x,strTypes): yield pdfdocEnc(x) elif isinstance(x,PDFObject): yield x.format(document) elif isinstance(x,PDFPatternIf): result = list(self.eval(x.cond)) cond = result and result[0] for z in self.eval(x.thenPart if cond else x.elsePart): yield z else: name = x[0] value = arguments.get(name, None) if value is None: raise ValueError("%s value not defined" % ascii(name)) if isinstance(value,PDFObject): yield format(value,document) elif isinstance(value,strTypes): yield pdfdocEnc(value) else: yield pdfdocEnc(str(value))