@@ 45,7 45,7 @@ class SubscriptionManager(models.Manager
raise TypeError(
'callback cannot be None if there is not a reversible URL')
else:
- callback = 'http://%s%s' % (
+ callback = 'http://{0}{1}'.format(
config.get_default_callback_host(topic, hub),
callback_path
)
@@ 62,35 62,44 @@ class SubscriptionManager(models.Manager
info = response.info()
info.status = response.code
if debug:
- print 'Info:\n%s\n\n' % str(info)
+ print('Info:\n{0}\n\n'.format(info))
if info.status not in [204, 202]:
# 204 is sync verification
# 202 is async verification
error = response.read()
raise urllib2.URLError(
- 'error with mode "%s" to %s on %s:\n%s' % \
- (mode, topic, hub, error)
+ 'error with mode "{0}" to {1} on {2}:\n{3}'.format(
+ mode,
+ topic,
+ hub,
+ error,
+ )
)
return subscription
-
+
def status(self, topic, hub=None, debug=False):
config = Config()
if hub is None:
hub = self._get_hub(topic)
headers = config.get_extra_hub_headers(topic, hub)
-
+
try:
- response = self._send_request(hub+'?hub.mode=status&hub.topic='+topic, {}, headers, debug)
- except urllib2.HTTPError, e:
+ response = self._send_request(
+ '{0}?hub.mode=status&hub.topic={1}'.format(hub, topic),
+ {},
+ headers,
+ debug,
+ )
+ except urllib2.HTTPError as e:
if e.code == 302:
return True
return False
-
+
def subscribe(self, topic, **kwargs):
return self.do_action(topic, mode='subscribe', **kwargs)
-
+
def unsubscribe(self, topic, **kwargs):
return self.do_action(topic, mode='unsubscribe', **kwargs)
@@ 114,11 123,15 @@ class SubscriptionManager(models.Manager
encoded_data = urlencode(list(data_generator()))
#headers.update({'Content-Length': (len(encoded_data) + 2)})
if debug:
- print 'Sending:\n%s\n%s\n%s\n\n' % (url, encoded_data, headers)
+ print('Sending:\n{0}\n{1}\n{2}\n\n'.format(
+ url,
+ encoded_data,
+ headers,
+ ))
req = urllib2.Request(url, encoded_data, headers=headers)
else:
if debug:
- print 'Sending:\n%s\n%s\n\n' % (url, headers)
+ print 'Sending:\n{0}\n{1}\n\n'.format(url, headers)
req = urllib2.Request(url, headers=headers)
return urllib2.urlopen(req)
@@ 130,9 143,9 @@ class Subscription(models.Model):
verified = models.BooleanField(default=False)
verify_token = models.CharField(max_length=60)
lease_expires = models.DateTimeField(default=datetime.now)
-
+
is_subscribed = models.BooleanField(default=False)
-
+
date = models.DateTimeField(default=datetime.now)
updated = models.DateTimeField(default=datetime.now)
@@ 147,8 160,11 @@ class Subscription(models.Model):
verified = u'verified'
else:
verified = u'unverified'
- return u'to %s on %s: %s' % (
- self.topic, self.hub, verified)
+ return u'to {0} on {1}: {2}'.format(
+ self.topic,
+ self.hub,
+ verified,
+ )
def __str__(self):
return str(unicode(self))
@@ 162,13 178,19 @@ class Subscription(models.Model):
def generate_token(self, mode, run_save=True):
assert self.pk is not None, \
'Subscription must be saved before generating token'
- token = mode[:20] + sha1('%s%i%s' % (
- settings.SECRET_KEY, self.pk, mode)).hexdigest()
+ token = '{0}{1}'.format(
+ mode[:20],
+ sha1('{0}{1}{2}'.format(
+ settings.SECRET_KEY,
+ self.pk,
+ mode,
+ )).hexdigest(),
+ )
self.verify_token = token
if run_save:
self.save()
return token
-
+
def save(self, *args, **kwargs):
if self.id:
self.updated = datetime.now()