Permalink
Browse files

Use sys.exc_info to retrieve exception info.

This approach works the same in Python 2 and 3.
  • Loading branch information...
1 parent 845c072 commit 3d8ddca92aac31101bc956a721d3d291537ae5fa @daviddrysdale committed Nov 26, 2011
Showing with 9 additions and 4 deletions.
  1. +9 −4 python/phonenumbers/phonenumberutil.py
@@ -28,6 +28,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+import sys
import re
from .re_util import fullmatch # Extra regexp function; see README
@@ -2129,7 +2130,8 @@ def parse(number, region, keep_raw_input=False,
metadata,
keep_raw_input,
numobj)
- except NumberParseException, e:
+ except NumberParseException:
+ _, e, _ = sys.exc_info()
matchobj = _PLUS_CHARS_PATTERN.match(national_number)
if (e.error_type == NumberParseException.INVALID_COUNTRY_CODE and
matchobj is not None):
@@ -2258,12 +2260,14 @@ def _is_number_match_SS(number1, number2):
try:
numobj1 = parse(number1, UNKNOWN_REGION)
return _is_number_match_OS(numobj1, number2)
- except NumberParseException, exc:
+ except NumberParseException:
+ _, exc, _ = sys.exc_info()
if exc.error_type == NumberParseException.INVALID_COUNTRY_CODE:
try:
numobj2 = parse(number2, UNKNOWN_REGION)
return _is_number_match_OS(numobj2, number1)
- except NumberParseException, exc2:
+ except NumberParseException:
+ _, exc2, _ = sys.exc_info()
if exc2.error_type == NumberParseException.INVALID_COUNTRY_CODE:
try:
numobj1 = parse(number1, None, keep_raw_input=False,
@@ -2287,7 +2291,8 @@ def _is_number_match_OS(numobj1, number2):
try:
numobj2 = parse(number2, UNKNOWN_REGION)
return _is_number_match_OO(numobj1, numobj2)
- except NumberParseException, exc:
+ except NumberParseException:
+ _, exc, _ = sys.exc_info()
if exc.error_type == NumberParseException.INVALID_COUNTRY_CODE:
# The second number has no country calling code. EXACT_MATCH is no
# longer possible. We parse it as if the region was the same as

0 comments on commit 3d8ddca

Please sign in to comment.