Python bindings: PEP8 mandates two blank lines before class
[babeltrace.git] / bindings / python / common.py
CommitLineData
be5a4e67
PP
1# common.py
2#
3# Babeltrace Python module common definitions
4#
5# Copyright 2012-2015 EfficiOS Inc.
6#
7# Author: Danny Serres <danny.serres@efficios.com>
8# Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9#
10# Permission is hereby granted, free of charge, to any person obtaining a copy
11# of this software and associated documentation files (the "Software"), to deal
12# in the Software without restriction, including without limitation the rights
13# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14# copies of the Software, and to permit persons to whom the Software is
15# furnished to do so, subject to the following conditions:
16#
17# The above copyright notice and this permission notice shall be included in
18# all copies or substantial portions of the Software.
19#
20# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26# SOFTWARE.
27
5b489212 28
be5a4e67
PP
29class CTFStringEncoding:
30 """
31 CTF string encodings.
32 """
33
34 #: None
35 NONE = 0
36
37 #: UTF-8
38 UTF8 = 1
39
40 #: ASCII
41 ASCII = 2
42
43 #: Unknown
44 UNKNOWN = 3
45
46
47# Based on the enum in ctf-writer/writer.h
48class ByteOrder:
49 """
50 Byte orders.
51 """
52
53 #: Native byte order
54 BYTE_ORDER_NATIVE = 0
55
56 #: Little-endian
57 BYTE_ORDER_LITTLE_ENDIAN = 1
58
59 #: Big-endian
60 BYTE_ORDER_BIG_ENDIAN = 2
61
62 #: Network byte order (big-endian)
63 BYTE_ORDER_NETWORK = 3
64
65 #: Unknown byte order
66 BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
67
68
69# enum equivalent, accessible constants
70# These are taken directly from ctf/events.h
71# All changes to enums must also be made here
72class CTFTypeId:
73 """
74 CTF numeric type identifiers.
75 """
76
77 #: Unknown type
78 UNKNOWN = 0
79
80 #: Integer
81 INTEGER = 1
82
83 #: Floating point number
84 FLOAT = 2
85
86 #: Enumeration
87 ENUM = 3
88
89 #: String
90 STRING = 4
91
92 #: Structure
93 STRUCT = 5
94
95 #: Untagged variant
96 UNTAGGED_VARIANT = 6
97
98 #: Variant
99 VARIANT = 7
100
101 #: Array
102 ARRAY = 8
103
104 #: Sequence
105 SEQUENCE = 9
106
107 NR_CTF_TYPES = 10
108
109 def type_name(id):
110 """
111 Returns the name of the CTF numeric type identifier *id*.
112 """
113
114 name = "UNKNOWN_TYPE"
115 constants = [
116 attr for attr in dir(CTFTypeId) if not callable(
117 getattr(
118 CTFTypeId,
119 attr)) and not attr.startswith("__")]
120
121 for attr in constants:
122 if getattr(CTFTypeId, attr) == id:
123 name = attr
124 break
125
126 return name
127
128
129class CTFScope:
130 """
131 CTF scopes.
132 """
133
134 #: Packet header
135 TRACE_PACKET_HEADER = 0
136
137 #: Packet context
138 STREAM_PACKET_CONTEXT = 1
139
140 #: Event header
141 STREAM_EVENT_HEADER = 2
142
143 #: Stream event context
144 STREAM_EVENT_CONTEXT = 3
145
146 #: Event context
147 EVENT_CONTEXT = 4
148
149 #: Event fields
150 EVENT_FIELDS = 5
151
152 def scope_name(scope):
153 """
154 Returns the name of the CTF scope *scope*.
155 """
156
157 name = "UNKNOWN_SCOPE"
158 constants = [
159 attr for attr in dir(CTFScope) if not callable(
160 getattr(
161 CTFScope,
162 attr)) and not attr.startswith("__")]
163
164 for attr in constants:
165 if getattr(CTFScope, attr) == scope:
166 name = attr
167 break
168
169 return name
This page took 0.029374 seconds and 4 git commands to generate.