def _make_start_format(tag_uri, tag_name, attributes, encoding): # We must search for translatable attributes result = [(u'<%s' % get_qname(tag_uri, tag_name), False, None)] for attr_uri, attr_name in attributes: qname = get_attribute_qname(attr_uri, attr_name) qname = Unicode.decode(qname, encoding=encoding) value = attributes[(attr_uri, attr_name)] value = Unicode.decode(value, encoding=encoding) value = XMLAttribute.encode(value) datatype = get_attr_datatype(tag_uri, tag_name, attr_uri, attr_name, attributes) if issubclass(datatype, Unicode): result[-1] = (result[-1][0] + u' %s="' % qname, False, None) context = _get_attr_context(datatype, tag_name, attr_name) result.append((value, True, context)) result.append((u'"', False, None)) else: result[-1] = (result[-1][0] + u' %s="%s"' % (qname, value), False, None) # Close the start tag if is_empty(tag_uri, tag_name): result[-1] = (result[-1][0] + u'/>', False, None) else: result[-1] = (result[-1][0] + u'>', False, None) return result
def to_str(self): output = [] # Opent tag open_tag = '<file original="%s"%s>\n' attributes = [ ' %s="%s"' % (key, XMLAttribute.encode(value)) for key, value in self.attributes.items() if key != 'space'] if 'space' in self.attributes: attributes.append(' xml:space="%s"' % self.attributes['space']) attributes = ''.join(attributes) open_tag = open_tag % (self.original, attributes) output.append(open_tag) # The header if self.header: output.append('<header>\n') for line in self.header: output.append(line.to_str()) output.append('</header>\n') # The body output.append('<body>\n') if self.body: output.extend([ unit.to_str() for unit in self.body.values() ]) output.append('</body>\n') # Close tag output.append('</file>\n') return ''.join(output)
def to_str(self): output = [] # Opent tag open_tag = '<file original="%s"%s>\n' attributes = [ ' %s="%s"' % (key, XMLAttribute.encode(value)) for key, value in self.attributes.items() if key != 'space' ] if 'space' in self.attributes: attributes.append(' xml:space="%s"' % self.attributes['space']) attributes = ''.join(attributes) open_tag = open_tag % (self.original, attributes) output.append(open_tag) # The header if self.header: output.append('<header>\n') for line in self.header: output.append(line.to_str()) output.append('</header>\n') # The body output.append('<body>\n') if self.body: output.extend([unit.to_str() for unit in self.body.values()]) output.append('</body>\n') # Close tag output.append('</file>\n') return ''.join(output)
def to_str(self, encoding=None): # The XML prolog output = [ '<?xml version="1.0" encoding="%s"?>\n' % encoding, '<!DOCTYPE tmx SYSTEM "http://www.lisa.org/tmx/tmx14.dtd">\n' ] # TMX header output.append('<tmx version="%s">\n' % self.version) attributes = [ ' %s="%s"' % (key, XMLAttribute.encode(value)) for key, value in self.header.items() ] output.append('<header%s>\n' % ''.join(attributes)) # TMX header / notes for note in self.header_notes: output.append(note.to_str()) output.append('</header>\n') # TMX body output.append('<body>\n') messages = self.messages msgids = messages.keys() msgids.sort() for msgid in msgids: output.append(messages[msgid].to_str()) output.append('</body>\n') # Ok output.append('</tmx>\n') return ''.join(output)
def to_str(self, encoding=None): # The XML prolog output = [ '<?xml version="1.0" encoding="%s"?>\n' % encoding, '<!DOCTYPE tmx SYSTEM "http://www.lisa.org/tmx/tmx14.dtd">\n'] # TMX header output.append('<tmx version="%s">\n' % self.version) attributes = [ ' %s="%s"' % (key, XMLAttribute.encode(value)) for key, value in self.header.items() ] output.append('<header%s>\n' % ''.join(attributes)) # TMX header / notes for note in self.header_notes: output.append(note.to_str()) output.append('</header>\n') # TMX body output.append('<body>\n') messages = self.messages msgids = messages.keys() msgids.sort() for msgid in msgids: output.append(messages[msgid].to_str()) output.append('</body>\n') # Ok output.append('</tmx>\n') return ''.join(output)
def get_start_tag(value): tag_uri, tag_name, attributes = value s = '<%s' % get_qname(tag_uri, tag_name) # Output the attributes for attr_uri, attr_name in attributes: value = attributes[(attr_uri, attr_name)] qname = get_attribute_qname(attr_uri, attr_name) value = XMLAttribute.encode(value) s += ' %s="%s"' % (qname, value) return s + '>'
def get_start_tag(value): tag_uri, tag_name, attributes = value s = '<%s' % get_qname(tag_uri, tag_name) # Output the attributes for attr_uri, attr_name in attributes: value = attributes[(attr_uri, attr_name)] qname = get_attribute_qname(attr_uri, attr_name) value = XMLAttribute.encode(value) s += ' %s="%s"' % (qname, value) return s + '>'
def text_widget(context, form, datatype, name, value, schema, fields, readonly, tabindex=None): # Reçoit des int en GET if not isinstance(value, basestring): value = datatype.encode(value) if isinstance(datatype, NumDecimal): try: value = context.format_number(value, places=datatype.decimals) except InvalidOperation: pass # Reçoit des str en POST if not type(value) is unicode: value = unicode(value, 'utf8') if readonly: tagname = u"div" attributes = {u"class": [u"readonly"]} content = XMLContent.encode(value) else: tagname = u"input" attributes = { u"type": u"text", u"id": u"field_{name}".format(name=name), u"name": name, u"value": XMLAttribute.encode(value), u"size": str(datatype.size), u"maxlength": str(datatype.length) } content = u"" # Right-align numeric fields if issubclass(datatype, Numeric): attributes.setdefault(u"class", []).append(u"num") attributes.setdefault(u"style", []).append(u"text-align:right") # Check for errors check_errors(context, form, datatype, name, value, schema, fields, readonly, attributes, tabindex=None) return make_element(tagname, attributes, content)
def test_encode(self): self.assertEqual(XMLContent.encode(self.data), self.result1) self.assertEqual(XMLAttribute.encode(self.data), self.result2)
def file_widget(context, form, datatype, name, value, schema, fields, readonly, tabindex=None): if readonly: tagname = u"div" attributes = {u"class": [u"readonly"]} content = XMLContent.encode(value) else: tagname = u"input" attributes = { u"type": u"file", u"id": u"field_{name}".format(name=name), u"name": name, u"value": XMLAttribute.encode(value), u"size": str(datatype.size), u"maxlength": str(datatype.length) } content = u"" # Check for errors check_errors(context, form, datatype, name, value, schema, fields, readonly, attributes, tabindex=None) html = make_element(tagname, attributes, content) # Preview if not value: return html resource = form.parent.get_resource(value, soft=True) if resource is None: return html context = get_context() link = context.get_link(resource) href = u"{0}/;download".format(link) src = u"{0}/;thumb?width=128&height=128".format(link) preview = make_element(u"a", { u"href": href, u"target": u"_new" }, make_element(u"img", {u"src": src})) field_id = u"field_{name}_delete".format(name=name) if readonly: delete = u"" else: delete = make_element( u"input", { u"type": u"checkbox", u"id": field_id, u"name": u"{name}_delete".format(name=name), u"value": u"1" }, make_element(u"label", {u"for": field_id}, MSG(u"Delete"))) html = html + preview + delete return html