move coverage
Browse files- pytube/exceptions.py +1 -26
pytube/exceptions.py
CHANGED
@@ -1,10 +1,6 @@
|
|
1 |
# -*- coding: utf-8 -*-
|
2 |
"""Library specific exception definitions."""
|
3 |
-
import socket
|
4 |
import sys
|
5 |
-
from traceback import format_tb
|
6 |
-
|
7 |
-
from pytube.compat import URLError
|
8 |
|
9 |
|
10 |
class PytubeError(Exception):
|
@@ -19,43 +15,22 @@ class PytubeError(Exception):
|
|
19 |
class ExtractError(PytubeError):
|
20 |
"""Data extraction based exception."""
|
21 |
|
22 |
-
def __init__(self, msg,
|
23 |
"""Construct an instance of a :class:`ExtractError <ExtractError>`.
|
24 |
|
25 |
:param str msg:
|
26 |
User defined error message.
|
27 |
-
:param list tb:
|
28 |
-
Stack trace leading up to the exception.
|
29 |
-
:param bool expected:
|
30 |
-
Whether the exception being raised requires filing a bug report.
|
31 |
:param str video_id:
|
32 |
A YouTube video identifer.
|
33 |
"""
|
34 |
-
# get information about the most recent exception caught by an except
|
35 |
-
# clause
|
36 |
-
exception_type, _, _ = sys.exc_info()
|
37 |
-
|
38 |
-
if exception_type in (URLError, socket.timeout):
|
39 |
-
expected = True
|
40 |
-
|
41 |
if video_id is not None:
|
42 |
msg = '{video_id}: {msg}'.format(video_id=video_id, msg=msg)
|
43 |
|
44 |
-
if not expected:
|
45 |
-
# TODO(nficano): bug report
|
46 |
-
pass
|
47 |
-
|
48 |
super(ExtractError, self).__init__(msg)
|
49 |
|
50 |
-
self.traceback = tb
|
51 |
self.exc_info = sys.exc_info()
|
52 |
self.video_id = video_id
|
53 |
|
54 |
-
def format_traceback(self):
|
55 |
-
"""Pretty-print the traceback."""
|
56 |
-
if self.traceback:
|
57 |
-
return ''.join(format_tb(self.traceback))
|
58 |
-
|
59 |
|
60 |
class RegexMatchError(ExtractError):
|
61 |
"""Regex pattern did not return any matches."""
|
|
|
1 |
# -*- coding: utf-8 -*-
|
2 |
"""Library specific exception definitions."""
|
|
|
3 |
import sys
|
|
|
|
|
|
|
4 |
|
5 |
|
6 |
class PytubeError(Exception):
|
|
|
15 |
class ExtractError(PytubeError):
|
16 |
"""Data extraction based exception."""
|
17 |
|
18 |
+
def __init__(self, msg, video_id=None):
|
19 |
"""Construct an instance of a :class:`ExtractError <ExtractError>`.
|
20 |
|
21 |
:param str msg:
|
22 |
User defined error message.
|
|
|
|
|
|
|
|
|
23 |
:param str video_id:
|
24 |
A YouTube video identifer.
|
25 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
if video_id is not None:
|
27 |
msg = '{video_id}: {msg}'.format(video_id=video_id, msg=msg)
|
28 |
|
|
|
|
|
|
|
|
|
29 |
super(ExtractError, self).__init__(msg)
|
30 |
|
|
|
31 |
self.exc_info = sys.exc_info()
|
32 |
self.video_id = video_id
|
33 |
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
class RegexMatchError(ExtractError):
|
36 |
"""Regex pattern did not return any matches."""
|