Changeset - 2d078b0004fb
[Not reviewed]
0 10 0
Ben Sturmfels (bsturmfels) - 1 month ago 2021-11-29 20:55:45
ben@sturm.com.au
Apply `futurize --stage-2` Python 2/3 compatibility transformations.

These changes specifically require the use of the "future" library.
10 files changed with 31 insertions and 17 deletions:
0 comments (0 inline, 0 general)
www/conservancy/__init__.py
Show inline comments
 
from past.builtins import basestring
 
from builtins import object
 
import hashlib
 

	
www/conservancy/apps/blog/models.py
Show inline comments
 
from future import standard_library
 
standard_library.install_aliases()
 
from builtins import object
 
from django.db import models
 
from django.conf import settings
 
from conservancy import bsoup
...
 
@@ -65,14 +68,14 @@ class Entry(models.Model, bsoup.SoupModelMixin):
 
        post_url = ('http://www.sfconservancy.org'
 
                    + self.get_absolute_url())
 

	
 
        import xmlrpclib
 
        import xmlrpc.client
 

	
 
        # Ping Technorati
 
        j = xmlrpclib.Server('http://rpc.technorati.com/rpc/ping')
 
        j = xmlrpc.client.Server('http://rpc.technorati.com/rpc/ping')
 
        reply = j.weblogUpdates.ping(blog_name, blog_url)
 

	
 
        # Ping Google Blog Search
 
        j = xmlrpclib.Server('http://blogsearch.google.com/ping/RPC2')
 
        j = xmlrpc.client.Server('http://blogsearch.google.com/ping/RPC2')
 
        reply = j.weblogUpdates.ping(blog_name, blog_url, post_url)
 

	
 
        # Call any superclass's method
www/conservancy/apps/events/view_helpers.py
Show inline comments
...
 
@@ -15,6 +15,6 @@ def organize_media_by_event(eventmedia_queryset):
 
    mbe = [{'event': x[0].event,
 
            'date': max(y.date_created for y in x),
 
            'media_list': ', '.join(set(y.get_format_display() for y in x))}
 
           for x in media_by_event.values()]
 
           for x in list(media_by_event.values())]
 
    mbe.sort(key=(lambda x: x['date']), reverse=True) # sort by date
 
    return mbe
www/conservancy/apps/fundgoal/models.py
Show inline comments
 
from __future__ import division
 
from past.utils import old_div
 
from builtins import object
 
import random
 

	
...
 
@@ -17,7 +19,7 @@ class FundraisingGoal(models.Model):
 
        return self.fundraiser_code_name
 

	
 
    def percentage_there(self):
 
        return (self.fundraiser_so_far_amount / self.fundraiser_goal_amount ) * 100
 
        return (old_div(self.fundraiser_so_far_amount, self.fundraiser_goal_amount) ) * 100
 
    
 
    class Meta(object):
 
        ordering = ('fundraiser_code_name',)
www/conservancy/apps/news/models.py
Show inline comments
 
from future import standard_library
 
standard_library.install_aliases()
 
from builtins import object
 
from django.db import models
 
from django.conf import settings
...
 
@@ -54,14 +56,14 @@ class PressRelease(models.Model, bsoup.SoupModelMixin):
 
        post_url = ('https://www.sfconservancy.org'
 
                    + self.get_absolute_url())
 

	
 
        import xmlrpclib
 
        import xmlrpc.client
 

	
 
        # Ping Technorati
 
        j = xmlrpclib.Server('http://rpc.technorati.com/rpc/ping')
 
        j = xmlrpc.client.Server('http://rpc.technorati.com/rpc/ping')
 
        reply = j.weblogUpdates.ping(blog_name, blog_url)
 

	
 
        # Ping Google Blog Search
 
        j = xmlrpclib.Server('http://blogsearch.google.com/ping/RPC2')
 
        j = xmlrpc.client.Server('http://blogsearch.google.com/ping/RPC2')
 
        reply = j.weblogUpdates.ping(blog_name, blog_url, post_url)
 

	
 
        # Call any superclass's method
www/conservancy/apps/news/templatetags/fill_url.py
Show inline comments
 
import urlparse
 
from future import standard_library
 
standard_library.install_aliases()
 
from builtins import zip
 
import urllib.parse
 

	
 
from django import template
 

	
...
 
@@ -13,8 +16,8 @@ def fill_url(given_url, base_url):
 
    Typical usage is "/URL/path"|fill_url:"https://hostname/"
 
    to generate "https://hostname/URL/path".
 
    """
 
    given_parts = urlparse.urlsplit(given_url)
 
    base_parts = urlparse.urlsplit(base_url)
 
    return urlparse.urlunsplit(
 
    given_parts = urllib.parse.urlsplit(given_url)
 
    base_parts = urllib.parse.urlsplit(base_url)
 
    return urllib.parse.urlunsplit(
 
        given_part or base_part for given_part, base_part in zip(given_parts, base_parts)
 
    )
www/conservancy/bsoup.py
Show inline comments
 
# -*- encoding: utf-8 -*-
 

	
 
from builtins import filter
 
from builtins import object
 
import io
 
import itertools
...
 
@@ -144,7 +145,7 @@ class SoupModelMixin(object):
 
        return elem_pred
 

	
 
    def _sort_and_slice_elems(self, elem_seq, elem_key, pred, *slice_args):
 
        seq = itertools.ifilter(pred, sorted(elem_seq, key=elem_key))
 
        seq = filter(pred, sorted(elem_seq, key=elem_key))
 
        if slice_args:
 
            return itertools.islice(seq, *slice_args)
 
        else:
www/conservancy/local_context_processors.py
Show inline comments
...
 
@@ -22,7 +22,7 @@ def sitefundraiser(request):
 
if conservancy.settings.FORCE_CANONICAL_HOSTNAME:
 
    _HOST_URL_VAR = {'host_url': 'https://' + conservancy.settings.FORCE_CANONICAL_HOSTNAME}
 
    def host_url(request):
 
        return _HOST_URL_VAR
 
        return _HOST_URL_VAR.decode('utf-8')
 
else:
 
    def host_url(request):
 
        return {'host_url': request.build_absolute_uri('/').rstrip('/')}
 
        return {'host_url': request.build_absolute_uri('/').rstrip('/').decode('utf-8')}
www/conservancy/static/views.py
Show inline comments
 
from builtins import str
 
import mimetypes
 
import os.path
 
from django.http import HttpResponse
www/modpythoncustom.py
Show inline comments
 
from builtins import str
 
from mod_python import apache
 

	
 
# 404 should do NOTHING so apache can handle it.  This view is referenced
...
 
@@ -83,10 +84,10 @@ class ModPythonHandler(BaseHandler):
 

	
 
        # Convert our custom HttpResponse object back into the mod_python req.
 
        req.content_type = response['Content-Type']
 
        for key, value in response.items():
 
        for key, value in list(response.items()):
 
            if key != 'content-type':
 
                req.headers_out[str(key)] = str(value)
 
        for c in response.cookies.values():
 
        for c in list(response.cookies.values()):
 
            req.headers_out.add('Set-Cookie', c.output(header=''))
 
        req.status = response.status_code
 
        try:
0 comments (0 inline, 0 general)