@@ -7,18 +7,13 @@ cdef class SubtitleProxy:
7
7
8
8
9
9
cdef class SubtitleSet:
10
-
11
10
def __cinit__ (self , SubtitleProxy proxy ):
12
11
self .proxy = proxy
13
12
cdef int i
14
13
self .rects = tuple (build_subtitle(self , i) for i in range (self .proxy.struct.num_rects))
15
14
16
15
def __repr__ (self ):
17
- return " <%s .%s at 0x%x >" % (
18
- self .__class__.__module__,
19
- self .__class__.__name__ ,
20
- id (self ),
21
- )
16
+ return f" <{self.__class__.__module__}.{self.__class__.__name__} at 0x{id(self):x}>"
22
17
23
18
@property
24
19
def format (self ): return self .proxy.struct.format
@@ -64,7 +59,6 @@ cdef Subtitle build_subtitle(SubtitleSet subtitle, int index):
64
59
65
60
66
61
cdef class Subtitle:
67
-
68
62
def __cinit__ (self , SubtitleSet subtitle , int index ):
69
63
if index < 0 or < unsigned int > index >= subtitle.proxy.struct.num_rects:
70
64
raise ValueError (" subtitle rect index out of range" )
@@ -80,18 +74,13 @@ cdef class Subtitle:
80
74
elif self .ptr.type == lib.SUBTITLE_ASS:
81
75
self .type = b" ass"
82
76
else :
83
- raise ValueError (" unknown subtitle type %r " % self .ptr.type)
77
+ raise ValueError (f " unknown subtitle type { self.ptr.type!r} " )
84
78
85
79
def __repr__ (self ):
86
- return " <%s .%s at 0x%x >" % (
87
- self .__class__.__module__,
88
- self .__class__.__name__ ,
89
- id (self ),
90
- )
80
+ return f" <{self.__class__.__module__}.{self.__class__.__name__} at 0x{id(self):x}>"
91
81
92
82
93
83
cdef class BitmapSubtitle(Subtitle):
94
-
95
84
def __cinit__ (self , SubtitleSet subtitle , int index ):
96
85
self .planes = tuple (
97
86
BitmapSubtitlePlane(self , i)
@@ -100,14 +89,9 @@ cdef class BitmapSubtitle(Subtitle):
100
89
)
101
90
102
91
def __repr__ (self ):
103
- return " <%s .%s %d x%d at %d ,%d ; at 0x%x >" % (
104
- self .__class__.__module__,
105
- self .__class__.__name__ ,
106
- self .width,
107
- self .height,
108
- self .x,
109
- self .y,
110
- id (self ),
92
+ return (
93
+ f" <{self.__class__.__module__}.{self.__class__.__name__} "
94
+ f" {self.width}x{self.height} at {self.x},{self.y}; at 0x{id(self):x}>"
111
95
)
112
96
113
97
@property
@@ -132,9 +116,7 @@ cdef class BitmapSubtitle(Subtitle):
132
116
133
117
134
118
cdef class BitmapSubtitlePlane:
135
-
136
119
def __cinit__ (self , BitmapSubtitle subtitle , int index ):
137
-
138
120
if index >= 4 :
139
121
raise ValueError (" BitmapSubtitles have only 4 planes" )
140
122
if not subtitle.ptr.linesize[index]:
@@ -146,34 +128,29 @@ cdef class BitmapSubtitlePlane:
146
128
self ._buffer = < void * > subtitle.ptr.data[index]
147
129
148
130
# New-style buffer support.
149
-
150
131
def __getbuffer__ (self , Py_buffer *view , int flags ):
151
132
PyBuffer_FillInfo(view, self , self ._buffer, self .buffer_size, 0 , flags)
152
133
153
134
154
135
cdef class TextSubtitle(Subtitle):
155
-
156
136
def __repr__ (self ):
157
- return " <%s .%s %r at 0x%x >" % (
158
- self .__class__.__module__,
159
- self .__class__.__name__ ,
160
- self .text,
161
- id (self ),
137
+ return (
138
+ f" <{self.__class__.__module__}.{self.__class__.__name__} "
139
+ f" {self.text!r} at 0x{id(self):x}>"
162
140
)
163
141
164
142
@property
165
- def text (self ): return self .ptr.text
143
+ def text (self ):
144
+ return self .ptr.text
166
145
167
146
168
147
cdef class AssSubtitle(Subtitle):
169
-
170
148
def __repr__ (self ):
171
- return " <%s .%s %r at 0x%x >" % (
172
- self .__class__.__module__,
173
- self .__class__.__name__ ,
174
- self .ass,
175
- id (self ),
149
+ return (
150
+ f" <{self.__class__.__module__}.{self.__class__.__name__} "
151
+ f" {self.ass!r} at 0x{id(self):x}>"
176
152
)
177
153
178
154
@property
179
- def ass (self ): return self .ptr.ass
155
+ def ass (self ):
156
+ return self .ptr.ass
0 commit comments