#! /usr/bin/python

from __future__ import absolute_import, division, print_function
from bs4 import BeautifulSoup
import requests
import re


def search(term,limit=None):
    url = "https://pypi.python.org/pypi?:action=search&term=" + term
    req = requests.get(url)

    soup = BeautifulSoup(req.text, 'html.parser')
    packagestable = soup.table

    # If no package exists then there is no table displayed hence soup.table will be None
    if packagestable is None:
        return list()

    packagerows = packagestable.find_all('tr', {'class': re.compile('[odd|even]')})
	packages = list()

	for package in packagerows[:limit]:
		packagedatatd = package.find_all('td')
		packagedata = {
			'name': packagedatatd[0].text.replace(u'\xa0',' '),
			'link': 'https://pypi.python.org' + packagedatatd[0].find('a')['href'],
			'weight': int(packagedatatd[1].text),
			'description': packagedatatd[2].text
		}
		packages.append(packagedata)

	return packages

@@ -572,17 +572,20 @@
 en%5D')%7D)%0A
-%09
+    
 packages
@@ -595,17 +595,20 @@
 list()%0A%0A
-%09
+    
 for pack
@@ -635,18 +635,24 @@
 limit%5D:%0A
-%09%09
+        
 packaged
@@ -682,18 +682,24 @@
 l('td')%0A
-%09%09
+        
 packaged
@@ -706,19 +706,28 @@
 ata = %7B%0A
-%09%09%09
+            
 'name': 
@@ -770,19 +770,28 @@
 ',' '),%0A
-%09%09%09
+            
 'link': 
@@ -854,19 +854,28 @@
 href'%5D,%0A
-%09%09%09
+            
 'weight'
@@ -908,11 +908,20 @@
 t),%0A
-%09%09%09
+            
 'des
@@ -957,14 +957,26 @@
 ext%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 pack
@@ -1005,9 +1005,12 @@
 a)%0A%0A
-%09
+    
 retu

Convert indents to spaces