1
2
3
4
5 """
6
7 Serialize DOAP as XML/RDF
8 =========================
9
10 This plugin outputs DOAP in RDF/XML
11 It basically does nothing because all DOAP today is in RDF/XML.
12 In the future this may take N3, Turtle, RDFa etc. and convert it to RDF/XML.
13
14 """
15
16 __docformat__ = 'epytext'
17
18 from elementtree import ElementTree
19
20 from doapfiend.plugins.base import Plugin
21
22
24
25 """Class for formatting DOAP output"""
26
27
28 name = "xml"
29 enabled = False
30 enable_opt = None
31
33 '''Setup RDF/XML OutputPlugin class'''
34 super(OutputPlugin, self).__init__()
35 self.options = None
36
38 """Add plugin's options to doapfiend's opt parser"""
39 output.add_option('-x', '--%s' % self.name,
40 action='store_true',
41 dest=self.enable_opt,
42 help='Output DOAP as RDF/XML')
43 return parser, output, search
44
46 '''
47 Serialize RDF/XML DOAP as N3 syntax
48
49 Since the only input we currently have is XML, all this really does
50 is parse the XML and raise an exception if it's invalid.
51 When we do content negotiation/accept N3 etc., this will serialize.
52
53 @param doap_xml: DOAP in RDF/XML serialization
54 @type doap_xml: string
55
56 @rtype: unicode
57 @returns: DOAP
58 '''
59
60
61
62
63 ElementTree.fromstring(doap_xml)
64 if hasattr(self.options, 'no_color'):
65 color = not self.options.no_color
66 if color:
67
68
69 try:
70 from pygments import highlight
71 from pygments.lexers import XmlLexer
72 from pygments.formatters import TerminalFormatter
73 except ImportError:
74 return doap_xml
75 return highlight(doap_xml,
76 XmlLexer(),
77 TerminalFormatter(full=False))
78 else:
79 return doap_xml
80