~ubuntu-branches/ubuntu/utopic/awn-extras-applets/utopic

« back to all changes in this revision

Viewing changes to src/lastfm/httpclient.py

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-01-13 21:50:33 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100113215033-kd9otcdjrajmiag0
Tags: 0.3.9~bzr1944-0ubuntu1
* New upstream snapshot.
 - Catch error in weather applet (LP: #359668)
* debian/patches: Refresh.
* debian/*.install: 
 - Update to new location and new applets.
 - Disable dialect applet until python-xklavier is in the archive.
 - Disable MiMenu and Pandora applets, there are unmaintained and not stable.
* debian/awn-applets-c-core: Dropped, not needed.
* debian/control:
 - Update description with new applets.
 - Remove libawn-extras and python-awnlib, all merged in python-awn-extras.
 - Replace awn-manager by awn-settings.
 - Drop build-depends on libgnome-desktop-dev, python*-dev, python2.5,
   awn-manager, libglade2-dev and libgnomeui-dev.
 - Add build-depends on libdesktop-agnostic-bin and vala-awn.
 - Bump build-depends of libawn-dev (>= 0.3.9~bzr1890), valac (>= 0.7.7) and
   debhelper (>= 7.0.50~).
 - Bump Standards-Version to 3.8.3 (no change needed).
 - Demote gconf-editor to Suggest, it's only needed for very advanced
   settings.
 - Update Recommends for python applets with new applets.
 - Suggest python-gconf for notification-area and alacarte for YAMA.
 - Add a debug package for C applets.
* debian/libawn-extras*: Removed, libawn-extras was removed upstream.
* debian/python-awnlib*: Merged with python-awn-extras.
* debian/rules:
 - Rewrite to use overrides.
* debian/copyright:
 - Update copyright and licenses.
* debian/README.source: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
# Copyright (c) 2007 Tomas Kramar (kramar.tomas@gmail.com), Jonathan Rauprich (joni@noplu.de)
4
 
#
5
 
# This library is free software; you can redistribute it and/or
6
 
# modify it under the terms of the GNU Lesser General Public
7
 
# License as published by the Free Software Foundation; either
8
 
# version 2 of the License, or (at your option) any later version.
9
 
#
10
 
# This library is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
# Lesser General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU Lesser General Public
16
 
# License along with this library; if not, write to the
17
 
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
 
# Boston, MA 02111-1307, USA.
19
 
 
20
 
import base64
21
 
import socket
22
 
import string
23
 
import lastfmexception
24
 
import sys
25
 
 
26
 
True = 1
27
 
False = 0
28
 
 
29
 
class httpclient:
30
 
 
31
 
    def __init__(self, host, port):
32
 
        self.host = host
33
 
        self.port = port
34
 
        self.status = None
35
 
        self.headers = None
36
 
        self.response = None
37
 
 
38
 
    def readline(self, s):
39
 
        res = ""
40
 
        while True:
41
 
            try:
42
 
                c = s.recv(1)
43
 
            except:
44
 
                break
45
 
            res = res + c
46
 
            if c == '\n':
47
 
                break
48
 
            if not c:
49
 
                break
50
 
        return res
51
 
 
52
 
    def req(self, url):
53
 
        try:
54
 
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
55
 
            s.connect((self.host, self.port))
56
 
            s.send("GET " + url + " HTTP/1.0\r\n")
57
 
            s.send("Host: " + self.host + "\r\n")
58
 
            s.send("\r\n")
59
 
    
60
 
            line = self.readline(s)
61
 
            self.status = string.rstrip(line)
62
 
    
63
 
            self.headers = {}
64
 
            while True:
65
 
                line = self.readline(s)
66
 
                if not line:
67
 
                    break
68
 
                if line == "\r\n":
69
 
                    break
70
 
                tmp = string.split(line, ": ")
71
 
                self.headers[tmp[0]] = string.rstrip(tmp[1])
72
 
    
73
 
            self.response = ""
74
 
            while True:
75
 
                line = self.readline(s)
76
 
                if not line:
77
 
                    break
78
 
                self.response = self.response + line
79
 
            s.close()
80
 
        except:
81
 
            #print "Unexpected error: ", sys.exc_info()[0]
82
 
            #print "Unable to contact last.fm"
83
 
            raise lastfmexception.LastFmException(sys.exc_info()[0])
84