mirror of
https://github.com/robweber/xbmcbackup.git
synced 2024-11-14 20:35:48 +01:00
fixed error handling for python 2.7+
This commit is contained in:
parent
d0b1d6bb34
commit
4513eb67f9
@ -58,7 +58,7 @@ class DropboxAuthorizer:
|
||||
try:
|
||||
user_token = flow.finish(code)
|
||||
self._setToken(user_token.access_token)
|
||||
except Exception,e:
|
||||
except Exception as e:
|
||||
utils.log("Error: %s" % (e,))
|
||||
result = False
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import xbmc
|
||||
import utils as utils
|
||||
|
||||
class ZipExtractor:
|
||||
@ -24,8 +23,7 @@ class ZipExtractor:
|
||||
#extract the file
|
||||
zipFile.extract(aFile,outLoc)
|
||||
|
||||
except Exception,e:
|
||||
print str(e)
|
||||
except Exception as e:
|
||||
utils.log("Error extracting file")
|
||||
result = False
|
||||
|
||||
|
@ -156,7 +156,7 @@ class GoogleAuth(ApiAttributeMixin, object):
|
||||
port_number = port
|
||||
try:
|
||||
httpd = ClientRedirectServer((host_name, port), ClientRedirectHandler)
|
||||
except socket.error, e:
|
||||
except socket.error as e:
|
||||
pass
|
||||
else:
|
||||
success = True
|
||||
@ -164,26 +164,16 @@ class GoogleAuth(ApiAttributeMixin, object):
|
||||
if success:
|
||||
oauth_callback = 'http://%s:%s/' % (host_name, port_number)
|
||||
else:
|
||||
print 'Failed to start a local webserver. Please check your firewall'
|
||||
print 'settings and locally running programs that may be blocking or'
|
||||
print 'using configured ports. Default ports are 8080 and 8090.'
|
||||
raise AuthenticationError()
|
||||
self.flow.redirect_uri = oauth_callback
|
||||
authorize_url = self.GetAuthUrl()
|
||||
webbrowser.open(authorize_url, new=1, autoraise=True)
|
||||
print 'Your browser has been opened to visit:'
|
||||
print
|
||||
print ' ' + authorize_url
|
||||
print
|
||||
httpd.handle_request()
|
||||
if 'error' in httpd.query_params:
|
||||
print 'Authentication request was rejected'
|
||||
raise AuthenticationRejected('User rejected authentication')
|
||||
if 'code' in httpd.query_params:
|
||||
return httpd.query_params['code']
|
||||
else:
|
||||
print 'Failed to find "code" in the query parameters of the redirect.'
|
||||
print 'Try command-line authentication'
|
||||
raise AuthenticationError('No code found in redirect')
|
||||
|
||||
@CheckAuth
|
||||
@ -195,10 +185,6 @@ class GoogleAuth(ApiAttributeMixin, object):
|
||||
"""
|
||||
self.flow.redirect_uri = OOB_CALLBACK_URN
|
||||
authorize_url = self.GetAuthUrl()
|
||||
print 'Go to the following link in your browser:'
|
||||
print
|
||||
print ' ' + authorize_url
|
||||
print
|
||||
return raw_input('Enter verification code: ').strip()
|
||||
|
||||
def LoadCredentials(self, backend=None):
|
||||
@ -309,7 +295,7 @@ class GoogleAuth(ApiAttributeMixin, object):
|
||||
client_config_file = self.settings['client_config_file']
|
||||
try:
|
||||
client_type, client_info = clientsecrets.loadfile(client_config_file)
|
||||
except clientsecrets.InvalidClientSecretsError, error:
|
||||
except clientsecrets.InvalidClientSecretsError as error:
|
||||
raise InvalidConfigError('Invalid client secrets file %s' % error)
|
||||
if not client_type in (clientsecrets.TYPE_WEB,
|
||||
clientsecrets.TYPE_INSTALLED):
|
||||
@ -334,7 +320,6 @@ class GoogleAuth(ApiAttributeMixin, object):
|
||||
self.client_config[config] = self.settings['client_config'][config]
|
||||
|
||||
except KeyError:
|
||||
print config
|
||||
raise InvalidConfigError('Insufficient client config in settings')
|
||||
|
||||
def GetFlow(self):
|
||||
@ -374,7 +359,7 @@ class GoogleAuth(ApiAttributeMixin, object):
|
||||
self.http = httplib2.Http()
|
||||
try:
|
||||
self.credentials.refresh(self.http)
|
||||
except AccessTokenRefreshError, error:
|
||||
except AccessTokenRefreshError as error:
|
||||
raise RefreshError('Access token refresh failed: %s' % error)
|
||||
|
||||
def GetAuthUrl(self, keys = None):
|
||||
@ -414,9 +399,8 @@ class GoogleAuth(ApiAttributeMixin, object):
|
||||
self.GetFlow()
|
||||
try:
|
||||
self.credentials = self.flow.step2_exchange(code)
|
||||
except FlowExchangeError, e:
|
||||
except FlowExchangeError as e:
|
||||
raise AuthenticationError('OAuth2 code exchange failed: %s' % e)
|
||||
print 'Authentication successful.'
|
||||
|
||||
def Authorize(self):
|
||||
"""Authorizes and builds service.
|
||||
|
@ -108,7 +108,7 @@ class GoogleDriveFile(ApiAttributeMixin, ApiResource):
|
||||
"""
|
||||
try:
|
||||
return dict.__getitem__(self, key)
|
||||
except KeyError, e:
|
||||
except KeyError as e:
|
||||
if self.uploaded:
|
||||
raise KeyError(e)
|
||||
if self.get('id'):
|
||||
@ -180,7 +180,7 @@ class GoogleDriveFile(ApiAttributeMixin, ApiResource):
|
||||
if file_id:
|
||||
try:
|
||||
metadata = self.auth.service.files().get(fileId=file_id).execute()
|
||||
except errors.HttpError, error:
|
||||
except errors.HttpError as error:
|
||||
raise ApiRequestError(error)
|
||||
else:
|
||||
self.uploaded = True
|
||||
@ -244,7 +244,7 @@ class GoogleDriveFile(ApiAttributeMixin, ApiResource):
|
||||
if self.dirty['content']:
|
||||
param['media_body'] = self._BuildMediaBody()
|
||||
metadata = self.auth.service.files().insert(**param).execute()
|
||||
except errors.HttpError, error:
|
||||
except errors.HttpError as error:
|
||||
raise ApiRequestError(error)
|
||||
else:
|
||||
self.uploaded = True
|
||||
@ -268,7 +268,7 @@ class GoogleDriveFile(ApiAttributeMixin, ApiResource):
|
||||
if self.dirty['content']:
|
||||
param['media_body'] = self._BuildMediaBody()
|
||||
metadata = self.auth.service.files().update(**param).execute()
|
||||
except errors.HttpError, error:
|
||||
except errors.HttpError as error:
|
||||
raise ApiRequestError(error)
|
||||
else:
|
||||
self.uploaded = True
|
||||
@ -290,7 +290,7 @@ class GoogleDriveFile(ApiAttributeMixin, ApiResource):
|
||||
param['fileId'] = self.metadata.get('id')
|
||||
try:
|
||||
metadata = self.auth.service.files().patch(**param).execute()
|
||||
except errors.HttpError, error:
|
||||
except errors.HttpError as error:
|
||||
raise ApiRequestError(error)
|
||||
else:
|
||||
self.UpdateMetadata(metadata)
|
||||
|
@ -120,7 +120,7 @@ def LoadSettingsFile(filename=SETTINGS_FILE):
|
||||
try:
|
||||
stream = file(filename, 'r')
|
||||
data = load(stream, Loader=Loader)
|
||||
except (YAMLError, IOError), e:
|
||||
except (YAMLError, IOError) as e:
|
||||
print e
|
||||
raise SettingsError(e)
|
||||
return data
|
||||
|
@ -115,7 +115,7 @@ Here is the behavior of operations with relativedelta:
|
||||
if dt1 and dt2:
|
||||
if not isinstance(dt1, datetime.date) or \
|
||||
not isinstance(dt2, datetime.date):
|
||||
raise TypeError, "relativedelta only diffs datetime/date"
|
||||
raise TypeError("relativedelta only diffs datetime/date")
|
||||
if type(dt1) is not type(dt2):
|
||||
if not isinstance(dt1, datetime.datetime):
|
||||
dt1 = datetime.datetime.fromordinal(dt1.toordinal())
|
||||
@ -195,7 +195,7 @@ Here is the behavior of operations with relativedelta:
|
||||
self.day = yday-ydayidx[idx-1]
|
||||
break
|
||||
else:
|
||||
raise ValueError, "invalid year day (%d)" % yday
|
||||
raise ValueError("invalid year day (%d)" % yday)
|
||||
|
||||
self._fix()
|
||||
|
||||
@ -244,7 +244,7 @@ Here is the behavior of operations with relativedelta:
|
||||
|
||||
def __radd__(self, other):
|
||||
if not isinstance(other, datetime.date):
|
||||
raise TypeError, "unsupported type for add operation"
|
||||
raise TypeError("unsupported type for add operation")
|
||||
elif self._has_time and not isinstance(other, datetime.datetime):
|
||||
other = datetime.datetime.fromordinal(other.toordinal())
|
||||
year = (self.year or other.year)+self.years
|
||||
@ -290,7 +290,7 @@ Here is the behavior of operations with relativedelta:
|
||||
|
||||
def __add__(self, other):
|
||||
if not isinstance(other, relativedelta):
|
||||
raise TypeError, "unsupported type for add operation"
|
||||
raise TypeError("unsupported type for add operation")
|
||||
return relativedelta(years=other.years+self.years,
|
||||
months=other.months+self.months,
|
||||
days=other.days+self.days,
|
||||
@ -310,7 +310,7 @@ Here is the behavior of operations with relativedelta:
|
||||
|
||||
def __sub__(self, other):
|
||||
if not isinstance(other, relativedelta):
|
||||
raise TypeError, "unsupported type for sub operation"
|
||||
raise TypeError("unsupported type for sub operation")
|
||||
return relativedelta(years=other.years-self.years,
|
||||
months=other.months-self.months,
|
||||
days=other.days-self.days,
|
||||
@ -426,5 +426,5 @@ Here is the behavior of operations with relativedelta:
|
||||
"hour", "minute", "second", "microsecond"]:
|
||||
value = getattr(self, attr)
|
||||
if value is not None:
|
||||
l.append("%s=%s" % (attr, `value`))
|
||||
l.append("%s=%s" % (attr, value))
|
||||
return "%s(%s)" % (self.__class__.__name__, ", ".join(l))
|
||||
|
Loading…
Reference in New Issue
Block a user