# -*- coding: utf-8 -*-

"""Python implementation of the Readability Shortener API"""

import requests
try:
    import simplejson as json
except ImportError:
    import json


class Readability(object):

    def __init__(self, url=None, verbose=None):
        self.url = url or 'https://readability.com/api/shortener/v1'
        self.config = {}
        if verbose is not None:
            self.config['verbose'] = verbose

    def _request(self, method, path, data=None, headers=None):
        url = self.url + path
        r = requests.request(method, url, data=data, headers=headers,
                             config=self.config, allow_redirects=True)
        r.raise_for_status()

        if not 'application/json' in r.headers['Content-Type']:
            raise TypeError('No JSON in response')

        return json.loads(r.content) if r.content.strip() else None

    def resources(self):
        """Retrieve information about sub-resources."""
        return self._request('GET', '/')

    def shorten(self, full_url):
        """Create a new shortened URL."""
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        data = 'url=%s' % full_url
        return self._request('POST', '/urls', data=data, headers=headers)

    def metadata(self, url_id):
        """Retrieve available metadata of a shortened link."""
        return self._request('GET', '/urls/%s' % url_id)

@@ -331,86 +331,15 @@
 elf.
-config = %7B%7D%0A        if verbose is not None:%0A            self.config%5B'verbose'%5D
+verbose
  = v
@@ -439,16 +439,120 @@
  + path%0A
+%0A        config = %7B%7D%0A        if self.verbose is not None:%0A            config%5B'verbose'%5D = self.verbose%0A%0A
         
@@ -649,21 +649,16 @@
  config=
-self.
 config, 
@@ -837,62 +837,219 @@
     
-return json.loads(r.content) if r.content.strip() else
+content = r.content.strip()%0A        if content:%0A            if self.verbose is not None:%0A                self.verbose.write(content + '%5Cn')%0A            return json.loads(content)%0A        else:%0A            return
  Non

Print HTTP content in verbose mode