~ubuntu-branches/ubuntu/precise/gst0.10-python/precise

« back to all changes in this revision

Viewing changes to gst/__init__.py

Tags: upstream-0.10.8
Import upstream version 0.10.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
                                                     self.high.denom)
77
77
 
78
78
class Fraction(Value):
79
 
   def __init__(self, num, denom):
80
 
      Value.__init__(self, 'fraction')
81
 
      self.num = num
82
 
      self.denom = denom
83
 
   def __repr__(self):
84
 
      return '<gst.Fraction %d/%d>' % (self.num, self.denom)
 
79
    def __init__(self, num, denom=1):
 
80
        Value.__init__(self, 'fraction')
 
81
        self.num = num
 
82
        self.denom = denom
 
83
 
 
84
    def __repr__(self):
 
85
        return '<gst.Fraction %d/%d>' % (self.num, self.denom)
 
86
 
 
87
    def __eq__(self, other):
 
88
        if isinstance(other, Fraction):
 
89
            return self.num * other.denom == other.num * self.denom
 
90
        return False
 
91
 
 
92
    def __ne__(self, other):
 
93
        return not self.__eq__(other)
 
94
 
 
95
    def __mul__(self, other):
 
96
        if isinstance(other, Fraction):
 
97
            return Fraction(self.num * other.num,
 
98
                            self.denom * other.denom)
 
99
        elif isinstance(other, int):
 
100
            return Fraction(self.num * other, self.denom)
 
101
        raise TypeError
 
102
 
 
103
    __rmul__ = __mul__
 
104
 
 
105
    def __div__(self, other):
 
106
        if isinstance(other, Fraction):
 
107
            return Fraction(self.num * other.denom,
 
108
                            self.denom * other.num)
 
109
        elif isinstance(other, int):
 
110
            return Fraction(self.num, self.denom * other)
 
111
        return TypeError
 
112
 
 
113
    def __rdiv__(self, other):
 
114
        if isinstance(other, int):
 
115
            return Fraction(self.denom * other, self.num)
 
116
        return TypeError
 
117
 
 
118
    def __float__(self):
 
119
        return float(self.num) / float(self.denom)
 
120
 
85
121
 
86
122
import sys
87
123
dlsave = sys.getdlopenflags()
107
143
    sys.setdlopenflags(RTLD_LAZY | RTLD_GLOBAL)
108
144
    from _gst import *
109
145
    import interfaces
 
146
    try:
 
147
        import libxml2
 
148
    except:
 
149
        pass
110
150
 
111
151
version = get_gst_version
112
152
 
113
153
sys.setdlopenflags(dlsave)
114
154
del sys
115
155
 
 
156
# Fixes for API cleanups that would cause an API breakage.
 
157
# See #446674
 
158
 
 
159
import warnings
 
160
if locals().has_key("parse_bin_from_description"):
 
161
    def gst_parse_bin_from_description(*args, **kwargs):
 
162
        warnings.warn("gst_parse_bin_from_description() is deprecated, please use parse_bin_from_description instead",
 
163
                      DeprecationWarning)
 
164
        return parse_bin_from_description(*args, **kwargs)
 
165
 
 
166
if locals().has_key("message_new_buffering"):
 
167
    def gst_message_new_buffering(*args, **kwargs):
 
168
        warnings.warn("gst_message_new_buffering() is deprecated, please use message_new_buffering() instead",
 
169
                      DeprecationWarning)
 
170
        return message_new_buffering(*args, **kwargs)
 
171
 
116
172
# this restores previously installed importhooks, so we don't interfere
117
173
# with other people's module importers
118
174
# it also clears out the module completely as if it were never loaded,