Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""":mod:`wand.exceptions` --- Errors and warnings 

2~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

3 

4This module maps MagickWand API's errors and warnings to Python's native 

5exceptions and warnings. You can catch all MagickWand errors using Python's 

6natural way to catch errors. 

7 

8.. seealso:: 

9 

10 `ImageMagick Exceptions <http://www.imagemagick.org/script/exception.php>`_ 

11 

12.. versionadded:: 0.1.1 

13 

14.. versionchanged:: 0.5.8 

15 Warning & Error Exceptions are now explicitly defined. Previously 

16 ImageMagick domain-based errors were dynamically generated at runtime. 

17""" 

18 

19 

20class WandException(Exception): 

21 """All Wand-related exceptions are derived from this class.""" 

22 

23 

24class BaseWarning(WandException, Warning): 

25 """Base class for Wand-related warnings. 

26 

27 .. versionadded:: 0.4.4 

28 

29 """ 

30 

31 

32class BaseError(WandException): 

33 """Base class for Wand-related errors. 

34 

35 .. versionadded:: 0.4.4 

36 

37 """ 

38 

39 

40class BaseFatalError(WandException): 

41 """Base class for Wand-related fatal errors. 

42 

43 .. versionadded:: 0.4.4 

44 

45 """ 

46 

47 

48class WandLibraryVersionError(WandException): 

49 """Base class for Wand-related ImageMagick version errors. 

50 

51 .. versionadded:: 0.3.2 

52 

53 """ 

54 

55 

56class WandRuntimeError(WandException, RuntimeError): 

57 """Generic class for Wand-related runtime errors. 

58 

59 .. versionadded:: 0.5.2 

60 """ 

61 

62 

63class ResourceLimitWarning(BaseWarning, MemoryError): 

64 """A program resource is exhausted e.g. not enough memory.""" 

65 wand_error_code = 300 

66 

67 

68class ResourceLimitError(BaseError, MemoryError): 

69 """A program resource is exhausted e.g. not enough memory.""" 

70 wand_error_code = 400 

71 

72 

73class ResourceLimitFatalError(BaseFatalError, MemoryError): 

74 """A program resource is exhausted e.g. not enough memory.""" 

75 wand_error_code = 700 

76 

77 

78class TypeWarning(BaseWarning): 

79 """A font is unavailable; a substitution may have occurred.""" 

80 wand_error_code = 305 

81 

82 

83class TypeError(BaseError): 

84 """A font is unavailable; a substitution may have occurred.""" 

85 wand_error_code = 405 

86 

87 

88class TypeFatalError(BaseFatalError): 

89 """A font is unavailable; a substitution may have occurred.""" 

90 wand_error_code = 705 

91 

92 

93class OptionWarning(BaseWarning): 

94 """A command-line option was malformed.""" 

95 wand_error_code = 310 

96 

97 

98class OptionError(BaseError): 

99 """A command-line option was malformed.""" 

100 wand_error_code = 410 

101 

102 

103class OptionFatalError(BaseFatalError): 

104 """A command-line option was malformed.""" 

105 wand_error_code = 710 

106 

107 

108class DelegateWarning(BaseWarning): 

109 """An ImageMagick delegate failed to complete.""" 

110 wand_error_code = 315 

111 

112 

113class DelegateError(BaseError): 

114 """An ImageMagick delegate failed to complete.""" 

115 wand_error_code = 415 

116 

117 

118class DelegateFatalError(BaseFatalError): 

119 """An ImageMagick delegate failed to complete.""" 

120 wand_error_code = 715 

121 

122 

123class MissingDelegateWarning(BaseWarning, ImportError): 

124 """The image type can not be read or written because the appropriate; 

125 delegate is missing.""" 

126 wand_error_code = 320 

127 

128 

129class MissingDelegateError(BaseError, ImportError): 

130 """The image type can not be read or written because the appropriate; 

131 delegate is missing.""" 

132 wand_error_code = 420 

133 

134 

135class MissingDelegateFatalError(BaseFatalError, ImportError): 

136 """The image type can not be read or written because the appropriate; 

137 delegate is missing.""" 

138 wand_error_code = 720 

139 

140 

141class CorruptImageWarning(BaseWarning, ValueError): 

142 """The image file may be corrupt.""" 

143 wand_error_code = 325 

144 

145 

146class CorruptImageError(BaseError, ValueError): 

147 """The image file may be corrupt.""" 

148 wand_error_code = 425 

149 

150 

151class CorruptImageFatalError(BaseFatalError, ValueError): 

152 """The image file may be corrupt.""" 

153 wand_error_code = 725 

154 

155 

156class FileOpenWarning(BaseWarning, IOError): 

157 """The image file could not be opened for reading or writing.""" 

158 wand_error_code = 330 

159 

160 

161class FileOpenError(BaseError, IOError): 

162 """The image file could not be opened for reading or writing.""" 

163 wand_error_code = 430 

164 

165 

166class FileOpenFatalError(BaseFatalError, IOError): 

167 """The image file could not be opened for reading or writing.""" 

168 wand_error_code = 730 

169 

170 

171class BlobWarning(BaseWarning, IOError): 

172 """A binary large object could not be allocated, read, or written.""" 

173 wand_error_code = 335 

174 

175 

176class BlobError(BaseError, IOError): 

177 """A binary large object could not be allocated, read, or written.""" 

178 wand_error_code = 435 

179 

180 

181class BlobFatalError(BaseFatalError, IOError): 

182 """A binary large object could not be allocated, read, or written.""" 

183 wand_error_code = 735 

184 

185 

186class StreamWarning(BaseWarning, IOError): 

187 """There was a problem reading or writing from a stream.""" 

188 wand_error_code = 340 

189 

190 

191class StreamError(BaseError, IOError): 

192 """There was a problem reading or writing from a stream.""" 

193 wand_error_code = 440 

194 

195 

196class StreamFatalError(BaseFatalError, IOError): 

197 """There was a problem reading or writing from a stream.""" 

198 wand_error_code = 740 

199 

200 

201class CacheWarning(BaseWarning): 

202 """Pixels could not be read or written to the pixel cache.""" 

203 wand_error_code = 345 

204 

205 

206class CacheError(BaseError): 

207 """Pixels could not be read or written to the pixel cache.""" 

208 wand_error_code = 445 

209 

210 

211class CacheFatalError(BaseFatalError): 

212 """Pixels could not be read or written to the pixel cache.""" 

213 wand_error_code = 745 

214 

215 

216class CoderWarning(BaseWarning): 

217 """There was a problem with an image coder.""" 

218 wand_error_code = 350 

219 

220 

221class CoderError(BaseError): 

222 """There was a problem with an image coder.""" 

223 wand_error_code = 450 

224 

225 

226class CoderFatalError(BaseFatalError): 

227 """There was a problem with an image coder.""" 

228 wand_error_code = 750 

229 

230 

231class ModuleWarning(BaseWarning): 

232 """There was a problem with an image module.""" 

233 wand_error_code = 355 

234 

235 

236class ModuleError(BaseError): 

237 """There was a problem with an image module.""" 

238 wand_error_code = 455 

239 

240 

241class ModuleFatalError(BaseFatalError): 

242 """There was a problem with an image module.""" 

243 wand_error_code = 755 

244 

245 

246class DrawWarning(BaseWarning): 

247 """A drawing operation failed.""" 

248 wand_error_code = 360 

249 

250 

251class DrawError(BaseError): 

252 """A drawing operation failed.""" 

253 wand_error_code = 460 

254 

255 

256class DrawFatalError(BaseFatalError): 

257 """A drawing operation failed.""" 

258 wand_error_code = 760 

259 

260 

261class ImageWarning(BaseWarning): 

262 """The operation could not complete due to an incompatible image.""" 

263 wand_error_code = 365 

264 

265 

266class ImageError(BaseError): 

267 """The operation could not complete due to an incompatible image.""" 

268 wand_error_code = 465 

269 

270 

271class ImageFatalError(BaseFatalError): 

272 """The operation could not complete due to an incompatible image.""" 

273 wand_error_code = 765 

274 

275 

276class WandWarning(BaseWarning): 

277 """There was a problem specific to the MagickWand API.""" 

278 wand_error_code = 370 

279 

280 

281class WandError(BaseError): 

282 """There was a problem specific to the MagickWand API.""" 

283 wand_error_code = 470 

284 

285 

286class WandFatalError(BaseFatalError): 

287 """There was a problem specific to the MagickWand API.""" 

288 wand_error_code = 770 

289 

290 

291class RandomWarning(BaseWarning): 

292 """There is a problem generating a true or pseudo-random number.""" 

293 wand_error_code = 375 

294 

295 

296class RandomError(BaseError): 

297 """There is a problem generating a true or pseudo-random number.""" 

298 wand_error_code = 475 

299 

300 

301class RandomFatalError(BaseFatalError): 

302 """There is a problem generating a true or pseudo-random number.""" 

303 wand_error_code = 775 

304 

305 

306class XServerWarning(BaseWarning): 

307 """An X resource is unavailable.""" 

308 wand_error_code = 380 

309 

310 

311class XServerError(BaseError): 

312 """An X resource is unavailable.""" 

313 wand_error_code = 480 

314 

315 

316class XServerFatalError(BaseFatalError): 

317 """An X resource is unavailable.""" 

318 wand_error_code = 780 

319 

320 

321class MonitorWarning(BaseWarning): 

322 """There was a problem activating the progress monitor.""" 

323 wand_error_code = 385 

324 

325 

326class MonitorError(BaseError): 

327 """There was a problem activating the progress monitor.""" 

328 wand_error_code = 485 

329 

330 

331class MonitorFatalError(BaseFatalError): 

332 """There was a problem activating the progress monitor.""" 

333 wand_error_code = 785 

334 

335 

336class RegistryWarning(BaseWarning): 

337 """There was a problem getting or setting the registry.""" 

338 wand_error_code = 390 

339 

340 

341class RegistryError(BaseError): 

342 """There was a problem getting or setting the registry.""" 

343 wand_error_code = 490 

344 

345 

346class RegistryFatalError(BaseFatalError): 

347 """There was a problem getting or setting the registry.""" 

348 wand_error_code = 790 

349 

350 

351class ConfigureWarning(BaseWarning): 

352 """There was a problem getting a configuration file.""" 

353 wand_error_code = 395 

354 

355 

356class ConfigureError(BaseError): 

357 """There was a problem getting a configuration file.""" 

358 wand_error_code = 495 

359 

360 

361class ConfigureFatalError(BaseFatalError): 

362 """There was a problem getting a configuration file.""" 

363 wand_error_code = 795 

364 

365 

366class PolicyWarning(BaseWarning): 

367 """A policy denies access to a delegate, coder, filter, path, or 

368 resource.""" 

369 wand_error_code = 399 

370 

371 

372class PolicyError(BaseError): 

373 """A policy denies access to a delegate, coder, filter, path, or 

374 resource.""" 

375 wand_error_code = 499 

376 

377 

378class PolicyFatalError(BaseFatalError): 

379 """A policy denies access to a delegate, coder, filter, path, or 

380 resource.""" 

381 wand_error_code = 799 

382 

383 

384#: (:class:`dict`) The dictionary of (code, exc_type). 

385TYPE_MAP = { 

386 300: ResourceLimitWarning, 

387 305: TypeWarning, 

388 310: OptionWarning, 

389 315: DelegateWarning, 

390 320: MissingDelegateWarning, 

391 325: CorruptImageWarning, 

392 330: FileOpenWarning, 

393 335: BlobWarning, 

394 340: StreamWarning, 

395 345: CacheWarning, 

396 350: CoderWarning, 

397 355: ModuleWarning, 

398 360: DrawWarning, 

399 365: ImageWarning, 

400 370: WandWarning, 

401 375: RandomWarning, 

402 380: XServerWarning, 

403 385: MonitorWarning, 

404 390: RegistryWarning, 

405 395: ConfigureWarning, 

406 399: PolicyWarning, 

407 400: ResourceLimitError, 

408 405: TypeError, 

409 410: OptionError, 

410 415: DelegateError, 

411 420: MissingDelegateError, 

412 425: CorruptImageError, 

413 430: FileOpenError, 

414 435: BlobError, 

415 440: StreamError, 

416 445: CacheError, 

417 450: CoderError, 

418 455: ModuleError, 

419 460: DrawError, 

420 465: ImageError, 

421 470: WandError, 

422 475: RandomError, 

423 480: XServerError, 

424 485: MonitorError, 

425 490: RegistryError, 

426 495: ConfigureError, 

427 499: PolicyError, 

428 700: ResourceLimitFatalError, 

429 705: TypeFatalError, 

430 710: OptionFatalError, 

431 715: DelegateFatalError, 

432 720: MissingDelegateFatalError, 

433 725: CorruptImageFatalError, 

434 730: FileOpenFatalError, 

435 735: BlobFatalError, 

436 740: StreamFatalError, 

437 745: CacheFatalError, 

438 750: CoderFatalError, 

439 755: ModuleFatalError, 

440 760: DrawFatalError, 

441 765: ImageFatalError, 

442 770: WandFatalError, 

443 775: RandomFatalError, 

444 780: XServerFatalError, 

445 785: MonitorFatalError, 

446 790: RegistryFatalError, 

447 795: ConfigureFatalError, 

448 799: PolicyFatalError, 

449}