Skip to content

Commit

Permalink
Initial update to python3
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBerg committed Apr 21, 2015
1 parent 7e43482 commit 6f1e0a6
Show file tree
Hide file tree
Showing 43 changed files with 126 additions and 132 deletions.
6 changes: 3 additions & 3 deletions api_permissions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Tastypie
from tastypie.resources import ModelResource
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
from .tastypie.resources import ModelResource
from .tastypie.authentication import Authentication
from .tastypie.authorization import Authorization


class CIStaffAuthorization(Authorization):
Expand Down
10 changes: 5 additions & 5 deletions api_urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.conf.urls import patterns, include
from tastypie.api import Api
from course.api import CourseResource, CourseInstanceResource
from userprofile.api import UserProfileResource
from course.api import CourseInstanceSummaryResource
from exercise.api import ExerciseResource, CourseModuleResource, \
from .tastypie.api import Api
from .course.api import CourseResource, CourseInstanceResource
from .userprofile.api import UserProfileResource
from .course.api import CourseInstanceSummaryResource
from .exercise.api import ExerciseResource, CourseModuleResource, \
SubmissionResource, SubmissionContentResource, LearningObjectResource

api = Api(api_name='v1')
Expand Down
2 changes: 1 addition & 1 deletion apps/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from models import ExternalIFrameTab, EmbeddedTab, RSSPlugin,\
from .models import ExternalIFrameTab, EmbeddedTab, RSSPlugin,\
ExternalIFramePlugin


Expand Down
6 changes: 3 additions & 3 deletions apps/app_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# A+
from apps.models import *
from lib.BeautifulSoup import BeautifulSoup
from bs4 import BeautifulSoup
from lib.helpers import update_url_params


Expand Down Expand Up @@ -104,7 +104,7 @@ def _build_src(self):
"view_name": self.view_name
}

for k, v in self.context.items():
for k, v in list(self.context.items()):
params[k + "_id"] = v.id

return update_url_params(self.plugin.service_url, params)
Expand Down Expand Up @@ -165,7 +165,7 @@ def _build_src(self):
return update_url_params(self.tab.content_url, params)

def render(self):
opener = urllib2.build_opener()
opener = urllib.request.build_opener()
content = opener.open(self._build_src(), timeout=5).read()

# Save the page in cache
Expand Down
2 changes: 1 addition & 1 deletion apps/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand Down
10 changes: 5 additions & 5 deletions apps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

# Python
import feedparser
import urlparse
import urllib2
import cookielib
import urllib.parse
import urllib.request, urllib.error, urllib.parse
import http.cookiejar
import datetime

# Django
Expand All @@ -33,7 +33,7 @@
ExternalIFrameTabRenderer, TabRenderer
from inheritance.models import ModelWithInheritance
from oauth_provider.models import Consumer
from lib.BeautifulSoup import BeautifulSoup
from bs4 import BeautifulSoup


class AbstractApp(ModelWithInheritance):
Expand Down Expand Up @@ -106,7 +106,7 @@ def render(self):

# If the page is not cached, retrieve it
if content == None:
opener = urllib2.build_opener()
opener = urllib.request.build_opener()
content = opener.open(url, timeout=5).read()

# Save the page in cache
Expand Down
2 changes: 1 addition & 1 deletion bootstrap_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def after_install(options, home_dir):
bin = "bin"
subprocess.call([join(home_dir, bin, "pip"), "install", "-r", "requirements.txt"])
"""))
print output
print(output)
2 changes: 1 addition & 1 deletion course/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_resource_uri(self, bundle_or_obj):
kwargs['user'] = bundle_or_obj.obj['user']
kwargs['pk'] = bundle_or_obj.obj['course_instance']
else:
print bundle_or_obj
print(bundle_or_obj)
kwargs['user'] = bundle_or_obj['user']
kwargs['pk'] = bundle_or_obj['course_instance']

Expand Down
2 changes: 1 addition & 1 deletion course/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations
import django.core.validators
Expand Down
16 changes: 8 additions & 8 deletions course/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python
import logging
import urllib, urllib2
import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse
from datetime import datetime

# Django
Expand Down Expand Up @@ -37,7 +37,7 @@ class Course(models.Model):

# Relations
teachers = models.ManyToManyField(UserProfile,
related_name=u"teaching_courses",
related_name="teaching_courses",
blank=True)

def get_absolute_url(self):
Expand Down Expand Up @@ -82,7 +82,7 @@ def __unicode__(self):
'''
Returns a short representation of the course as an unicode string.
'''
return self.code + u" " + self.name
return self.code + " " + self.name


class CourseInstance(models.Model):
Expand Down Expand Up @@ -111,9 +111,9 @@ class CourseInstance(models.Model):

# Relations
assistants = models.ManyToManyField(UserProfile,
related_name=u"assisting_courses",
related_name="assisting_courses",
blank=True)
course = models.ForeignKey(Course, related_name=u"instances")
course = models.ForeignKey(Course, related_name="instances")

plugins = generic.GenericRelation(BasePlugin, object_id_field="container_pk", content_type_field="container_type")
tabs = generic.GenericRelation(BaseTab, object_id_field="container_pk", content_type_field="container_type")
Expand Down Expand Up @@ -201,7 +201,7 @@ def get_label(self):
return _("Dashboard")

def __unicode__(self):
return self.course.code + u": " + self.instance_name
return self.course.code + ": " + self.instance_name

class Meta:
unique_together = ("course", "url")
Expand Down Expand Up @@ -231,8 +231,8 @@ class CourseHook(models.Model):
def trigger(self, data):
logger = logging.getLogger("plus.hooks")
try:
res = urllib2.urlopen(self.hook_url,
urllib.urlencode(data), timeout=10)
res = urllib.request.urlopen(self.hook_url,
urllib.parse.urlencode(data), timeout=10)
logger.info("%s posted to %s on %s with %s",
self.hook_type, self.hook_url, self.course_instance, data
)
Expand Down
2 changes: 1 addition & 1 deletion course/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def results_for_template(self):
@return: the template-friendly data structure of the ResultTable data
"""
for_template = []
for student, grades_d in self.results.items():
for student, grades_d in list(self.results.items()):
grades = []
sum = 0
for ex in self.exercises:
Expand Down
2 changes: 1 addition & 1 deletion course/south_migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def forwards(self, orm):
('url', self.gf('django.db.models.fields.CharField')(max_length=16)),
('starting_time', self.gf('django.db.models.fields.DateTimeField')()),
('ending_time', self.gf('django.db.models.fields.DateTimeField')()),
('course', self.gf('django.db.models.fields.related.ForeignKey')(related_name=u'instances', to=orm['course.Course'])),
('course', self.gf('django.db.models.fields.related.ForeignKey')(related_name='instances', to=orm['course.Course'])),
))
db.send_create_signal('course', ['CourseInstance'])

Expand Down
6 changes: 3 additions & 3 deletions course/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def view_instance(request, course_url, instance_url):
.append(exercise))

visible_exercises_by_course_modules = sorted(
visible_exercises_by_course_modules.items(),
list(visible_exercises_by_course_modules.items()),
key=lambda t: (t[0].closing_time, t[0].opening_time))

exercise_tree = [
Expand Down Expand Up @@ -335,7 +335,7 @@ def set_schedule_filters(request, course_url, instance_url):
course_instance = _get_course_instance(course_url, instance_url)
profile = request.user.userprofile

if not request.POST.has_key("category_filters"):
if "category_filters" not in request.POST:
return HttpResponseForbidden("You are trying to hide all categories. "
"Select at least one category to be "
"visible!")
Expand All @@ -350,7 +350,7 @@ def set_schedule_filters(request, course_url, instance_url):
category.set_hidden_to(profile, True)


if request.GET.has_key("next"):
if "next" in request.GET:
next = request.GET["next"]
else:
next = course_instance.get_absolute_url()
Expand Down
22 changes: 11 additions & 11 deletions doc/example_grader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SimpleHTTPServer, SocketServer
from urlparse import parse_qs
import urllib
import urllib2
import http.server, socketserver
from urllib.parse import parse_qs
import urllib.request, urllib.parse, urllib.error
import urllib.request, urllib.error, urllib.parse

PORT = 8888

Expand All @@ -14,7 +14,7 @@ def grade_first_ex(submission):
points += 1
return (points,max_points)

class ExerciseGrader(SimpleHTTPServer.SimpleHTTPRequestHandler):
class ExerciseGrader(http.server.SimpleHTTPRequestHandler):

# On GET-request return the exercise
def do_GET(self):
Expand Down Expand Up @@ -95,8 +95,8 @@ def do_POST(self):
'grading_payload': '{}'
}
# Submit the score to A+
opener = urllib2.build_opener()
request_data = urllib.urlencode(request_dict)
opener = urllib.request.build_opener()
request_data = urllib.parse.urlencode(request_dict)
response = opener.open(submission_url, request_data, timeout=10).read()
# Create the response
self.send_response(200)
Expand All @@ -108,10 +108,10 @@ def do_POST(self):

# Demonstrating hook functionality
elif "/hook/" in self.path:
print "POST Hook detected!", self.path
print "Data:", post_data
print("POST Hook detected!", self.path)
print("Data:", post_data)
self.send_response(200)

httpd = SocketServer.TCPServer(('', PORT), ExerciseGrader)
print 'Serving at port:', PORT
httpd = socketserver.TCPServer(('', PORT), ExerciseGrader)
print('Serving at port:', PORT)
httpd.serve_forever()
4 changes: 2 additions & 2 deletions exercise/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

# A+
from userprofile.models import UserProfile
from exercise_models import LearningObject, BaseExercise, CourseModule, CourseInstance
from submission_models import Submission, SubmittedFile
from .exercise_models import LearningObject, BaseExercise, CourseModule, CourseInstance
from .submission_models import Submission, SubmittedFile
from api_permissions import SuperuserAuthorization

class LearningObjectResource(ModelResource):
Expand Down
6 changes: 3 additions & 3 deletions exercise/async_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""
# Python
import socket
from urlparse import urlparse
from urllib.parse import urlparse
import json

# Django
Expand Down Expand Up @@ -199,11 +199,11 @@ def _post_async_submission(request, exercise, submission, students):
# Return a dict after successful save
return {"success": True,
"errors": []}
except Exception, e:
except Exception as e:
return {"success": False,
"errors": [str(e)]}
else:
submission.feedback = unicode(
submission.feedback = str(
_("<div class=\"alert alert-error\">\n"
" <p>The assessment service communicated the "
"assessment results in an invalid format and "
Expand Down
18 changes: 9 additions & 9 deletions exercise/exercise_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python
import urllib
import urllib2
import urllib.request, urllib.parse, urllib.error
import urllib.request, urllib.error, urllib.parse
import hmac
import hashlib
from datetime import datetime, timedelta
Expand Down Expand Up @@ -39,7 +39,7 @@ class CourseModule(models.Model):
introduction = models.TextField(blank=True)

# Relations
course_instance = models.ForeignKey(CourseInstance, related_name=u"course_modules")
course_instance = models.ForeignKey(CourseInstance, related_name="course_modules")

# Fields related to the opening of the rounds
opening_time = models.DateTimeField(default=datetime.now)
Expand Down Expand Up @@ -129,7 +129,7 @@ class LearningObjectCategory(models.Model):
points_to_pass = models.PositiveIntegerField(default=0)

course_instance = models.ForeignKey(CourseInstance,
related_name=u"categories")
related_name="categories")

hidden_to = models.ManyToManyField(
UserProfile,
Expand All @@ -141,7 +141,7 @@ class Meta:
unique_together = ("name", "course_instance")

def __unicode__(self):
return self.name + u" -- " + unicode(self.course_instance)
return self.name + " -- " + str(self.course_instance)

def get_exercises(self):
return BaseExercise.objects.filter(category=self)
Expand Down Expand Up @@ -266,7 +266,7 @@ def get_page(self, submission_url):
# Build the URL with a callback address, max points etc.
url = self.build_service_url(submission_url)

opener = urllib2.build_opener()
opener = urllib.request.build_opener()
page_content = opener.open(url, timeout=20).read()

return ExercisePage(self, page_content)
Expand Down Expand Up @@ -367,7 +367,7 @@ def submit(self, submission):
# and a callback URL to which the service may return the grading
url = self.build_service_url( submission.get_callback_url() )

opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
opener = urllib.request.build_opener(MultipartPostHandler.MultipartPostHandler)
response_body = opener.open(url.encode('ascii'), post_params, timeout=50).read()

# Close all opened file handles
Expand Down Expand Up @@ -421,7 +421,7 @@ def is_open_for(self, students, when=None):
dlrd.submitter in is_open_booleans_by_submitters)
is_open_booleans_by_submitters[dlrd.submitter] = True

if False in is_open_booleans_by_submitters.values():
if False in list(is_open_booleans_by_submitters.values()):
# Not all the submitters had enough extra time given.
return False
else:
Expand Down Expand Up @@ -523,7 +523,7 @@ def build_service_url(self, submission_url):
# use question mark.
delimiter = ("?", "&")["?" in self.service_url]

url = self.service_url + delimiter + urllib.urlencode(params)
url = self.service_url + delimiter + urllib.parse.urlencode(params)
return url

def get_submissions_for_student(self, userprofile):
Expand Down
4 changes: 2 additions & 2 deletions exercise/exercise_page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from lib.BeautifulSoup import BeautifulSoup
from bs4 import BeautifulSoup
from django.core.validators import URLValidator
import urllib, urllib2
import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse
from django.conf import settings

def _get_value_from_soup(soup, tag_name, attribute, parameters={}, default=None):
Expand Down
Loading

0 comments on commit 6f1e0a6

Please sign in to comment.