Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Small changes

  • Loading branch information...
commit 44d7d7bb0f2b04df22a2de94de9fc28aa52ec461 1 parent 406e292
@dustball dustball authored
Showing with 22 additions and 16 deletions.
  1. +15 −12 spreedly.py
  2. +7 −4 templates/needaccount.html
View
27 spreedly.py
@@ -1,4 +1,4 @@
-import urllib, xml.dom.minidom
+import urllib2, xml.dom.minidom, base64
__version__ = '0.1'
@@ -6,6 +6,10 @@
SPREEDLY_BASE_URL = 'https://spreedly.com/api/v4/%(site)s/'
SPREEDLY_TOKEN = 'your-token'
+def basic_auth(user, password):
+ return "Basic %s" % base64.b64encode('%s:%s' % (user, password))[:-1]
+
+
def remove_whitespace_nodes(node, unlink=True):
remove_list = set()
@@ -25,16 +29,6 @@ def get_code(response):
return int(response.headers['status'][0:3])
-class UAOpener(urllib.FancyURLopener):
- def __init__(self, token, *args, **kwargs):
- self.token = token
- urllib.FancyURLopener.__init__(self, *args, **kwargs)
-
- def prompt_user_passwd(self, host, realm):
- return (self.token, 'X')
-
- version = 'pyspreedly/%s' % __version__
-
class XMLReply(object):
def __init__(self, payload):
self.raw_payload = payload
@@ -102,9 +96,18 @@ def __init__(self, site=SITE_NAME, base_url=SPREEDLY_BASE_URL, token=SPREEDLY_TO
def url(self, rel_url):
return self.base_url % { 'site': self.site }+rel_url
+
def request(self, url, data=None):
- opener = UAOpener(self.token)
+
+ auth_handler = urllib2.HTTPBasicAuthHandler()
+ auth_handler.add_password(realm='Web Password',
+ uri='https://spreedly.com/', user=self.token,
+ passwd='X')
+ opener = urllib2.build_opener(auth_handler)
+ urllib2.install_opener(opener)
+
return self.to_reply(opener.open(self.url(url), data))
+
def to_reply(self, response):
if not get_code(response) == 200:
View
11 templates/needaccount.html
@@ -9,14 +9,17 @@ <h4 style="margin-bottom: 20px;">
</h4>
<span style="color: red;">{{ message }}</span>
<div>
+
+<!--
<div style="width: 45%; background: #fee; border: 2px solid #db002a; float: left; margin: 5px; padding: 10px;">
<h3>I signed up with PayPal.</h3>
<p style="font-size:smaller;">You need to upgrade to our new billing system by signing up on this site. Your PayPal subscription will be canceled once you switch.</p>
<input type="submit" value="Continue here" style="font-size: larger;" onclick="window.location.href='/?paypal=1'"/>
</div>
-
- <div style="width: 45%; background: #fee; border: 2px solid #db002a; float: right; margin: 5px; padding: 10px;">
- <h3>I signed up with Spreedly.</h3>
+
+-->
+ <div style="width: 45%; background: #fee; border: 2px solid #db002a; margin: 5px; margin-left:25%; padding: 10px;">
+<!-- <h3>I signed up with Spreedly.</h3> -->
<p style="font-size: smaller;">Tell us the email address you used:</p>
<form action="{{self.request.path}}" method="post" style="margin:0px;">
<input type="text" name="email" style="font-size: larger;"/><br />
@@ -28,4 +31,4 @@ <h4 style="margin-bottom: 20px;">
</div>
{% endif %}
</center>
-{% endblock %}
+{% endblock %}
Please sign in to comment.
Something went wrong with that request. Please try again.