File: spec-to-python.xsl

package info (click to toggle)
telepathy-python 0.15.19-2.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 2,332 kB
  • ctags: 406
  • sloc: xml: 27,760; python: 2,511; sh: 715; makefile: 114
file content (71 lines) | stat: -rw-r--r-- 2,814 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0"
  exclude-result-prefixes="tp">

  <xsl:output method="text" indent="no" encoding="utf-8"/>

  <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
  <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>

  <xsl:template match="tp:section">
    <xsl:apply-templates match="node"/>
  </xsl:template>

  <xsl:template match="interface">
    <xsl:variable name="u" select="translate(../@name, concat($lower, '/'), $upper)"/>
    <xsl:variable name="superclass">
      <xsl:choose>
        <xsl:when test="contains(/node/@name, '_Interface')
                        or contains(/node/@name, '/Channel_Type_')">
          <xsl:text>dbus.service.Interface</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>dbus.service.Object</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
class <xsl:value-of select="translate(/node/@name, '/_', '')"/>(<xsl:value-of select="$superclass"/>):
    """\<xsl:value-of select="tp:docstring"/>"""
<xsl:if test="contains(/node/@name, '_Interface')">
    def __init__(self):
        self._interfaces.add('<xsl:value-of select="@name"/>')
</xsl:if>

<xsl:apply-templates select="method"/>
<xsl:apply-templates select="signal"/>
  </xsl:template>

  <xsl:template match="method">
    @dbus.service.method('<xsl:value-of select="../@name"/>', in_signature='<xsl:for-each select="arg[@direction='in']"><xsl:value-of select="@type"/></xsl:for-each>', out_signature='<xsl:for-each select="arg[@direction='out']"><xsl:value-of select="@type"/></xsl:for-each>')
    def <xsl:value-of select="@name"/>(self<xsl:for-each select="arg[@direction='in']">, <xsl:value-of select="@name"/></xsl:for-each>):
        """<xsl:value-of select="tp:docstring"/>
        """
        raise NotImplementedError
  </xsl:template>

  <xsl:template match="signal">
    @dbus.service.signal('<xsl:value-of select="../@name"/>', signature='<xsl:for-each select="arg"><xsl:value-of select="@type"/></xsl:for-each>')
    def <xsl:value-of select="@name"/>(self<xsl:for-each select="arg">, <xsl:value-of select="@name"/></xsl:for-each>):
        """<xsl:value-of select="tp:docstring"/>
        """
        pass
  </xsl:template>

  <xsl:template match="/"><xsl:if test="node/interface[not(@tp:causes-havoc)]"># -*- coding: utf-8 -*-
# Generated from the Telepathy spec
"""<xsl:for-each select="node/tp:copyright">
  <xsl:apply-templates/><xsl:text>
</xsl:text></xsl:for-each>
<xsl:apply-templates select="node/tp:license"/>
"""

import dbus.service

<xsl:apply-templates select="node/interface"/>

    </xsl:if>
  </xsl:template>

</xsl:stylesheet>

<!-- vim:set sw=2 sts=2 et noai noci: -->