Changeset 71:c8e39db35e46 in stamper


Ignore:
Timestamp:
Sep 5, 2019, 4:38:38 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

Make stamper python-3 compatible

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • bin/stamp

    r58 r71  
    33import sys
    44from datetime import datetime
    5 from stamper import Stamper
     5from stamper.stamper import Stamper
    66
    77
  • bin/stamps

    r61 r71  
    22
    33from stamper.cli import build_args_parser
    4 from stamper import Stamper
     4from stamper.stamper import Stamper
    55
    66
  • stamper/__init__.py

    r58 r71  
    1 from stamper import Stamper
     1
  • stamper/config.py

    r58 r71  
    11
    22import os
    3 from ConfigParser import SafeConfigParser
     3from configparser import SafeConfigParser
    44
    55
  • stamper/http.py

    r53 r71  
    11
    2 from urllib2 import (
    3     Request, urlopen, build_opener, install_opener, HTTPCookieProcessor
    4     )
    5 from urllib import urlencode
    6 from urlparse import urljoin
     2import http.client
     3from urllib.parse import urlparse, urlencode, quote_plus
    74
    85
     
    107
    118    def __init__(self, base_url):
    12         self.base_url = base_url
    13         self.request = build_opener(HTTPCookieProcessor())
    14         install_opener(self.request)
     9        self.parsed_url = urlparse(base_url)
     10        if self.parsed_url.scheme == 'https':
     11            self.conn = http.client.HTTPSConnection(self.parsed_url.netloc)
     12        else:
     13            self.conn = http.client.HTTPConnection(self.parsed_url.netloc)
    1514
    16     def send_request(self, url, data=None):
    17         response = self.request.open(url, data)
     15    def get(self, url):
     16        self.conn.request('GET', url)
     17        response = conn.getresponse()
    1818        return response.read()
    1919
    20     def get(self, url):
    21         return self.send_request(urljoin(self.base_url, url))
    22 
    2320    def post(self, url, data):
    24         encoded_data = urlencode(data)
    25         return self.send_request(urljoin(self.base_url, url), encoded_data)
     21        encoded_data = urlencode(data, quote_via=quote_plus)
     22        headers = {'Content-type': 'application/x-www-form-urlencoded',
     23                   'Accept': 'text/plain'}
     24        self.conn.request('POST', url, encoded_data, headers)
     25        response = conn.getresponse()
     26        return response.read()
  • stamper/stamper.py

    r69 r71  
    292292                    # daily totals
    293293                    print('daily total: %(total)s' % {'total': totals[day]})
    294             print '-'*79
     294            print('-'*79)
    295295
    296296        # now calculate the totals and show them
     
    318318            if totals:
    319319                print('------ Totals ------' % {'day': day})
    320                 for day, tot in totals.iteritems():
     320                for day, tot in totals.items():
    321321                    print(' %(day)s: %(total)s' % {'day': day, 'total': tot})
    322322                    sum_tot = "%(total)s %(new)s" % {
Note: See TracChangeset for help on using the changeset viewer.