Skip to content

Commit 5bddae7

Browse files
christophgysinbchew
authored andcommitted
python3 support (#42)
* refactor imports * python3 compatibility
1 parent 85fd983 commit 5bddae7

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

dynamodump.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python
22
"""
33
Simple backup and restore script for Amazon DynamoDB using boto to work similarly to mysqldump.
44
@@ -15,15 +15,24 @@
1515
import os
1616
import shutil
1717
import threading
18-
import Queue
1918
import datetime
2019
import errno
2120
import sys
2221
import time
2322
import re
2423
import zipfile
2524
import tarfile
26-
import urllib2
25+
26+
try:
27+
from queue import Queue
28+
except ImportError:
29+
from Queue import Queue
30+
31+
try:
32+
from urllib.request import urlopen
33+
from urllib.error import URLError, HTTPError
34+
except ImportError:
35+
from urllib2 import urlopen, URLError, HTTPError
2736

2837
import boto.dynamodb2.layer1
2938
from boto.dynamodb2.exceptions import ProvisionedThroughputExceededException
@@ -63,13 +72,13 @@ def _get_aws_client(profile, region, service):
6372
# Fallback to querying metadata for region
6473
if not aws_region:
6574
try:
66-
azone = urllib2.urlopen(METADATA_URL + "placement/availability-zone",
67-
data=None, timeout=5).read().decode()
75+
azone = urlopen(METADATA_URL + "placement/availability-zone",
76+
data=None, timeout=5).read().decode()
6877
aws_region = azone[:-1]
69-
except urllib2.URLError:
78+
except URLError:
7079
logging.exception("Timed out connecting to metadata service.\n\n")
7180
sys.exit(1)
72-
except urllib2.HTTPError as e:
81+
except HTTPError as e:
7382
logging.exception("Error determining region used for AWS client. Typo in code?\n\n" +
7483
str(e))
7584
sys.exit(1)
@@ -913,7 +922,7 @@ def main():
913922
except AttributeError:
914923
# Didn't specify srcTable if we get here
915924

916-
q = Queue.Queue()
925+
q = Queue()
917926
threads = []
918927

919928
for i in range(MAX_NUMBER_BACKUP_WORKERS):

0 commit comments

Comments
 (0)