misc: cleaninp up some pylint violations

C1001 (old-style-class), W0611 (unused-import), W1401
(anomalous-backslash-in-string), W0107 (unnecessary-pass)
This commit is contained in:
Frédéric Péters 2014-12-20 19:50:40 +01:00
parent b8c0f9067f
commit 1f2ee2336d
30 changed files with 51 additions and 64 deletions

View File

@ -24,7 +24,7 @@ from qommon.admin.menu import html_top
from wcs.formdef import FormDef
class CategoryUI:
class CategoryUI(object):
def __init__(self, category):
self.category = category
if self.category is None:

View File

@ -53,7 +53,7 @@ def get_workflows(condition=lambda x: True):
return [x[1:] for x in t]
class FormDefUI:
class FormDefUI(object):
def __init__(self, formdef):
self.formdef = formdef
@ -956,7 +956,7 @@ class FormDefPage(Directory):
def archive_submit(self, form):
class Archiver:
class Archiver(object):
def __init__(self, formdef):
self.formdef = formdef
@ -1082,7 +1082,7 @@ class FormDefPage(Directory):
def anonymise_submit(self, form):
class Anonymiser:
class Anonymiser(object):
def __init__(self, formdef, status_ids, before_date):
self.formdef = formdef
@ -1210,7 +1210,7 @@ class FormDefPage(Directory):
def invite_submit(self, form, allowed_users):
class InvitationSender:
class InvitationSender(object):
def __init__(self, formdef):
self.formdef = formdef
self.formdef_url = self.formdef.get_url()

View File

@ -25,7 +25,7 @@ from qommon.admin.menu import html_top
from wcs.roles import Role
from wcs.formdef import FormDef
class RoleUI:
class RoleUI(object):
def __init__(self, role):
self.role = role
if self.role is None:

View File

@ -16,7 +16,6 @@
import copy
import cStringIO
import cPickle
import random
import os
import urllib2
@ -886,7 +885,6 @@ class SettingsDirectory(QommonSettingsDirectory):
all_elems = []
from formdef import FormDef
for formdef in FormDef.select():
formdef.name = toutf8(formdef.name)
for field in formdef.fields:
@ -931,7 +929,6 @@ class SettingsDirectory(QommonSettingsDirectory):
category.description = toutf8(category.description)
all_elems.append(category)
from roles import Role
for role in Role.select():
role.name = toutf8(role.name)
role.details = toutf8(role.details)

View File

@ -29,7 +29,7 @@ from qommon.form import *
from qommon.admin.emails import EmailsDirectory
from qommon.admin.menu import html_top, error_page
class UserUI:
class UserUI(object):
def __init__(self, user):
self.user = user

View File

@ -156,7 +156,7 @@ def graphviz(workflow, url_prefix='', select=None, svg=True,
return out
class WorkflowUI:
class WorkflowUI(object):
def __init__(self, workflow):
self.workflow = workflow
@ -977,7 +977,7 @@ class WorkflowsDirectory(Directory):
get_response().breadcrumb.append( ('workflows/', _('Workflows')) )
get_response().breadcrumb.append( ('import', _('Import')) )
html_top('workflows', title = _('Import Workflow'))
self.html_top(title=_('Import Workflow'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Import Workflow')
r += htmltext('<p>%s</p>') % _(

View File

@ -475,7 +475,7 @@ $(document).ready(function(){
return FormPage(component)
class FakeField:
class FakeField(object):
def __init__(self, id, type_, label):
self.id = id
self.type = type_
@ -753,7 +753,7 @@ class FormPage(Directory):
user = get_request().user
query = get_request().form.get('q')
class Exporter:
class Exporter(object):
def __init__(self, formpage, formdef, fields, selected_filter):
self.formpage = formpage
self.formdef = formdef
@ -849,7 +849,7 @@ class FormPage(Directory):
user = get_request().user
query = get_request().form.get('q')
class Exporter:
class Exporter(object):
def __init__(self, formpage, formdef, fields, selected_filter):
self.formpage = formpage
self.formdef = formdef
@ -903,7 +903,7 @@ class FormPage(Directory):
user = get_request().user
query = get_request().form.get('q')
class Exporter:
class Exporter(object):
def __init__(self, formpage, formdef, fields, selected_filter):
self.formpage = formpage
self.formdef = formdef

View File

@ -20,7 +20,7 @@ from quixote import get_publisher, get_response
from quixote.html import TemplateIO, htmltext
from qommon.storage import StorableObject
from qommon.misc import simplify, is_user_admin, indent_xml
from qommon.misc import simplify, indent_xml
from qommon.substitution import Substitutions
from qommon.xml_storage import XmlStorableObject

View File

@ -15,7 +15,6 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.
import ConfigParser
import fnmatch
import json
import os
import subprocess
@ -23,7 +22,7 @@ import sys
import tempfile
import urllib2
from qommon.ctl import Command, make_option
from qommon.ctl import Command
from qommon.storage import atomic_write

View File

@ -118,7 +118,7 @@ class PrefillSelectionWidget(CompositeWidget):
return r.getvalue()
class Field:
class Field(object):
id = None
type = None
varname = None

View File

@ -92,7 +92,7 @@ class JSONEncoder(json.JSONEncoder):
return json.JSONEncoder.default(self, obj)
class Evolution:
class Evolution(object):
who = None
status = None
time = None
@ -293,7 +293,6 @@ class FormData(StorableObject):
return get_role_translation(self, '_receiver')
def get_handling_role(self):
from roles import Role
try:
return Role.get(self.get_handling_role_id())
except KeyError:

View File

@ -39,7 +39,7 @@ class FormdefImportError(Exception):
pass
class FormField:
class FormField(object):
### only used to unpickle form fields from older (<200603) versions
def __setstate__(self, dict):
type = dict['type']

View File

@ -14,8 +14,6 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
import urllib
from quixote import get_request, get_publisher
from quixote.html import htmltext, TemplateIO
@ -23,7 +21,7 @@ from qommon import misc
from qommon.form import *
from qommon.backoffice.listing import pagination_links
class FormDefUI:
class FormDefUI(object):
def __init__(self, formdef):
self.formdef = formdef

View File

@ -301,7 +301,7 @@ class FormPage(Directory):
self.check_role()
if self.formdef.is_disabled():
if self.formdef.disabled_redirection:
if re.search('\[.*\]', self.formdef.disabled_redirection):
if re.search(r'\[.*\]', self.formdef.disabled_redirection):
try:
variables = get_publisher().substitutions.get_context_variables()
redirect_url = template.process_template(self.formdef.disabled_redirection, variables)

View File

@ -26,9 +26,7 @@ try:
except ImportError:
pass
import qommon
from qommon.publisher import get_publisher_class, set_publisher_class, QommonPublisher, get_cfg
from qommon.publisher import set_publisher_class, QommonPublisher, get_cfg
# this is terribly ugly but import RootDirectory will import a bunch of things,
# and some of them need a publisher to be set

View File

@ -21,7 +21,7 @@ from M2Crypto import X509, SMIME, BIO
from qommon.storage import StorableObject
class Certificate:
class Certificate(object):
def __init__(self, cert, type = 'x509'):
"""type : x509 or pkcs7"""

View File

@ -29,7 +29,7 @@ def stop_cron_process(*args):
global parent_killed
parent_killed = True
class CronJob:
class CronJob(object):
hours = None
minutes = None
weekdays = None

View File

@ -27,7 +27,7 @@ __all__ = [
import qommon
qommon._commands = {}
class Command:
class Command(object):
doc = ''
name = None
usage_args = '[ options ... ]'
@ -78,7 +78,7 @@ class Command:
qommon._commands[cls.name] = cls
register = classmethod(register)
class Ctl:
class Ctl(object):
def __init__(self, cmd_prefixes=[]):
self.cmd_prefixes = cmd_prefixes
self.parser = optparse.OptionParser(

View File

@ -332,7 +332,7 @@ def email(subject, mail_body, email_rcpt, replyto = None, bcc = None,
EmailToSend(msg_from, rcpts, msg.as_string()),
fire_and_forget = True)
class EmailToSend:
class EmailToSend(object):
def __init__(self, msg_from, rcpts, msg_as_string):
self.msg_from = msg_from
self.rcpts = rcpts

View File

@ -57,7 +57,7 @@ class AccessUnauthorizedError(AccessForbiddenError):
class EmailError(Exception):
pass
class InternalServerError:
class InternalServerError(object):
def render(self):
template.html_top(_('Oops, the server borked severely'))
r = TemplateIO(html=True)

View File

@ -368,7 +368,7 @@ for (i=0; i<all_obj.length; i++) {
return r.getvalue()
class HtmlWidget:
class HtmlWidget(object):
error = None
def __init__(self, string, title = None, *args, **kwargs):
@ -440,7 +440,7 @@ class CheckboxWidget(quixote.form.CheckboxWidget):
else:
self.value = True
class UploadedFile:
class UploadedFile: #pylint: disable=C1001
def __init__(self, directory, filename, upload):
self.directory = directory
self.base_filename = upload.base_filename
@ -979,7 +979,7 @@ class ValidatedStringWidget(StringWidget):
class UrlWidget(ValidatedStringWidget):
'''StringWidget which checks the value entered is a correct url starting with http or https'''
regex = '^https?://.+'
regex = r'^https?://.+'
def _parse(self, request):
ValidatedStringWidget._parse(self, request)
@ -1024,7 +1024,7 @@ class ValidUrlWidget(UrlWidget):
class UrlOrAbsPathWidget(UrlWidget):
'''StringWidget which checks the value entered is a correct url for an existing page'''
regex = '^https?://.+'
regex = r'^https?://.+'
def _parse(self, request):
UrlWidget._parse(self, request)
@ -1039,7 +1039,7 @@ class UrlOrAbsPathWidget(UrlWidget):
class VarnameWidget(ValidatedStringWidget):
'''StringWidget which checks the value entered is a syntactically correct
variable name.'''
regex = '^[a-zA-Z][a-zA-Z0-9_]*'
regex = r'^[a-zA-Z][a-zA-Z0-9_]*'
def _parse(self, request):
ValidatedStringWidget._parse(self, request)
@ -1050,7 +1050,7 @@ class VarnameWidget(ValidatedStringWidget):
class FileSizeWidget(ValidatedStringWidget):
'''StringWidget which checks the value entered is a syntactically correct
file size.'''
regex = '^\s*([\d]+)\s*([MK]i?)?[oB]?\s*$'
regex = r'^\s*([\d]+)\s*([MK]i?)?[oB]?\s*$'
@classmethod
def parse_file_size(cls, value):

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
class AuthMethod:
class AuthMethod(object):
method_admin_widget = None
def is_interactive(self):

View File

@ -1014,7 +1014,7 @@ class MethodAdminDirectory(Directory):
get_session().message = ('info', _('Number of accounts created: %s') % (i+1))
if send_notifications:
class NotificationSender:
class NotificationSender(object):
def __init__(self, accounts):
self.accounts = accounts
def email(self, job=None):

View File

@ -18,7 +18,6 @@ import os
import urllib
import urlparse
import httplib
import sys
from quixote import get_field, get_request, get_response, get_session, \
get_session_manager, redirect, get_publisher

View File

@ -27,7 +27,7 @@ except ImportError:
from quixote import get_request, get_response, redirect, get_field, get_publisher
from quixote.http_request import parse_header
from quixote.directory import Directory
from quixote import get_user, get_session, get_session_manager
from quixote import get_session, get_session_manager
import misc
from publisher import get_cfg, get_logger

View File

@ -23,7 +23,7 @@ from qommon import get_cfg
from qommon.form import StringWidget, PasswordWidget
class MobytSMS():
class MobytSMS(object):
"""This class allows to send a SMS using Mobyt provider"""
parameters = [
(StringWidget, 'sender', N_('Sender (number or name)')),
@ -94,7 +94,7 @@ class MobytSMS():
return self.get_credit("credit")
class OxydSMS:
class OxydSMS(object):
"""This class allows to send a SMS using Oxyd provider"""
parameters = [
(StringWidget, 'oxyd_username', N_('Username')),
@ -116,7 +116,7 @@ class OxydSMS:
for dest in destinations:
# oxyd needs the number prefixed by the country code, this is
# really unfortunate.
number = ''.join(re.findall('\d', dest))
number = ''.join(re.findall(r'\d', dest))
if dest.startswith('+'):
pass # it already is fully qualified
elif number.startswith('00'):
@ -146,7 +146,7 @@ class OxydSMS:
raise NotImplementedError
class ChoositSMS:
class ChoositSMS(object):
"""This class allows to send a SMS using the Choosit provider
http://sms.choosit.com/documentation_technique.html
@ -169,7 +169,7 @@ class ChoositSMS:
for dest in destinations:
# choosit needs the number prefixed by the country code, this is
# really unfortunate.
number = ''.join(re.findall('\d', dest))
number = ''.join(re.findall(r'\d', dest))
if dest.startswith('+'):
pass # it already is fully qualified
elif number.startswith('00'):
@ -197,7 +197,7 @@ class ChoositSMS:
raise NotImplementedError
class SMS:
class SMS(object):
providers = {
'mobyt': (N_('Mobyt provider'), MobytSMS),
'oxyd': (N_('Oxyd provider'), OxydSMS),

View File

@ -322,7 +322,7 @@ class RootDirectory(Directory):
'token': token})
get_response().set_content_type('application/json')
useragent = get_request().get_header('User-agent')
if re.findall('MSIE \d\.', useragent):
if re.findall(r'MSIE \d\.', useragent):
# hack around MSIE version < 10 as they do not have support for
# XmlHttpRequest 2 (hence the forced usage of an iframe to send
# a file in the background (cf jquery.iframe-transport.js); and

View File

@ -24,6 +24,7 @@ import qommon
from qommon.storage import _take, parse_clause as parse_storage_clause
from qommon import get_cfg
import wcs.categories
import wcs.formdata
import wcs.users
@ -509,7 +510,6 @@ def do_views(formdef):
', '.join([y[1] for y in common_fields]), x) for x in view_names])
cur.execute('''CREATE VIEW wcs_all_forms AS %s''' % union)
import wcs.categories
for category in wcs.categories.Category.select():
name = get_name_as_sql_identifier(category.name)[:40]
cur.execute('''CREATE VIEW wcs_category_%s AS SELECT * from wcs_all_forms
@ -519,7 +519,9 @@ def do_views(formdef):
cur.close()
class SqlMixin:
class SqlMixin(object):
_table_name = None
@guard_postgres
def keys(cls):
conn, cur = get_connection_and_cursor()
@ -689,7 +691,6 @@ class SqlMixin:
value = [[x, str(y)] for x, y in value.items()]
elif sql_type == 'varchar':
assert isinstance(value, basestring)
pass
elif sql_type == 'date':
assert type(value) is time.struct_time
value = datetime.datetime(value.tm_year, value.tm_mon, value.tm_mday)

View File

@ -22,7 +22,7 @@ from qommon import ezt
from wcs.workflows import WorkflowStatusItem, register_item_class, template_on_formdata
class JournalEvolutionPart:
class JournalEvolutionPart: #pylint: disable=C1001
content = None
def __init__(self, formdata, message):

View File

@ -50,7 +50,7 @@ class WorkflowImportError(Exception):
pass
class AttachmentEvolutionPart:
class AttachmentEvolutionPart: #pylint: disable=C1001
orig_filename = None
base_filename = None
content_type = None
@ -483,7 +483,7 @@ class Workflow(StorableObject):
class WorkflowStatus:
class WorkflowStatus(object):
id = None
name = None
items = None
@ -687,7 +687,7 @@ class WorkflowStatus:
item_o.parent = self
item_o.init_with_xml(item, charset, include_id=include_id)
class WorkflowStatusItem:
class WorkflowStatusItem(object):
description = 'XX'
category = None # (key, label)
id = None
@ -1580,7 +1580,6 @@ class ExportToModel(WorkflowStatusItem):
if not evo.comment:
evo.comment = _('Form exported in a model')
if self.attach_to_history:
from wcs.wf.attachment import AttachmentEvolutionPart
evo.add_part(AttachmentEvolutionPart(
self.model_file.base_filename,
StringIO(self.apply_template_to_formdata(formdata)),
@ -1673,9 +1672,6 @@ class ExportToModel(WorkflowStatusItem):
content_type = elem.find('content_type').text
content = elem.find('content').text
from quixote.http_request import Upload
from wcs.qommon.form import UploadedFile
ids = (self.parent.parent.id, self.parent.id, self.id)
filename = 'export_to_model-%s-%s-%s.upload' % ids