Python方法解决Url与Tinyurl地址互换问题

# -*- coding: utf-8 -*-
import re,urllib

def tiny_url(url):
    """将url转换成tinyurl"""
    apiurl = "http://xxxx.xxxx"
    tinyurl = urllib.urlopen(apiurl + url).read()
    return tinyurl

def content_tiny_url(content):
    """让消息里面的连接转换成更短的Tinyurl"""

    regex_url = r'http:\/\/([\w.]+\/?)\S*'
    for match in re.finditer(regex_url, content):
        url = match.group(0)
        content = content.replace(url,tiny_url(url))

    return content