From 0e86695ed60c622960a2504e4d6bd14772afee60 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 19 Sep 2012 17:37:33 -0400 Subject: [PATCH] Import pygrader, instead of pygrader.ENCODING. If your just import ENCODING, changing the value rebinds the local copy, but other modules will still see the original value. --- bin/pg.py | 6 +++--- pygrader/storage.py | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bin/pg.py b/bin/pg.py index b308278..d035d18 100755 --- a/bin/pg.py +++ b/bin/pg.py @@ -30,8 +30,8 @@ import sys as _sys import pgp_mime as _pgp_mime +import pygrader as _pygrader from pygrader import __version__ -from pygrader import ENCODING as _ENCODING from pygrader import LOG as _LOG from pygrader import color as _color from pygrader.email import test_smtp as _test_smtp @@ -185,12 +185,12 @@ if __name__ == '__main__': _pgp_mime.LOG.addHandler(syslog) _color.USE_COLOR = args.color - _ENCODING = args.encoding + _pygrader.ENCODING = args.encoding config = _configparser.ConfigParser() config.read([ _os_path.expanduser(_os_path.join('~', '.config', 'smtplib.conf')), - ], encoding=_ENCODING) + ], encoding=_pygrader.ENCODING) func_args = _inspect.getargspec(args.func).args kwargs = {} diff --git a/pygrader/storage.py b/pygrader/storage.py index 892f18e..b69b798 100644 --- a/pygrader/storage.py +++ b/pygrader/storage.py @@ -26,8 +26,8 @@ import re as _re import sys as _sys import time as _time +import pygrader as _pygrader from . import LOG as _LOG -from . import ENCODING as _ENCODING from .model.assignment import Assignment as _Assignment from .model.course import Course as _Course from .model.grade import Grade as _Grade @@ -58,7 +58,8 @@ def load_course(basedir): """ _LOG.debug('loading course from {}'.format(basedir)) config = _configparser.ConfigParser() - config.read([_os_path.join(basedir, 'course.conf')], encoding=_ENCODING) + config.read([_os_path.join(basedir, 'course.conf')], + encoding=_pygrader.ENCODING) name = config.get('course', 'name') names = {'robot': [config.get('course', 'robot').strip()]} for option in ['assignments', 'professors', 'assistants', 'students']: @@ -294,8 +295,8 @@ def load_grade(basedir, assignment, person): _LOG.debug('loading {} grade for {}'.format(assignment, person)) path = assignment_path(basedir, assignment, person) gpath = _os_path.join(path, 'grade') - g = parse_grade(_io.open(gpath, 'r', encoding=_ENCODING), - assignment, person) + g = parse_grade(_io.open(gpath, 'r', encoding=_pygrader.ENCODING), + assignment, person) #g.late = _os.stat(gpath).st_mtime > assignment.due g.late = _os_path.exists(_os_path.join(path, 'late')) npath = _os_path.join(path, 'notified') @@ -348,7 +349,7 @@ def save_grade(basedir, grade): if not _os_path.isdir(path): _os.makedirs(path) gpath = _os_path.join(path, 'grade') - with _io.open(gpath, 'w', encoding=_ENCODING) as f: + with _io.open(gpath, 'w', encoding=_pygrader.ENCODING) as f: f.write('{}\n'.format(grade.points)) if grade.comment: f.write('\n{}\n'.format(grade.comment.strip())) -- 2.26.2