Mercurial > libervia-web
changeset 451:1a0cec9b0f1e
better PEP-8 compliance
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 20 May 2014 10:54:03 +0200 |
parents | 41aae13cab2b |
children | 7b6506372466 |
files | setup.py src/browser/card_game.py src/browser/contact.py src/browser/dialog.py src/browser/libervia_main.py src/browser/nativedom.py src/browser/panels.py src/browser/radiocol.py src/browser/register.py src/browser/xmlui.py src/server/html_tools.py src/server/server.py src/twisted/plugins/libervia_server.py |
diffstat | 13 files changed, 65 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/setup.py Tue May 20 07:22:10 2014 +0200 +++ b/setup.py Tue May 20 10:54:03 2014 +0200 @@ -83,7 +83,6 @@ """Change options for twistd in the shell script Mainly change the paths""" sh_buffer = "" - run_dir = os.path.dirname(self.sh_script_path) with open(self.sh_script_path, 'r') as sh_file: for ori_line in sh_file: if ori_line.startswith('DAEMON='): @@ -234,7 +233,7 @@ modules_toinstall.append('mercurial')""" # hg can be installed from pypi if modules_toinstall: - if AUTO_DEB_OPT in install_opt: # auto debian installation is requested + if AUTO_DEB_OPT in install_opt: # auto debian installation is requested # are we on a distribution using apt ? apt_path = subprocess.Popen('which apt-get', stdout=subprocess.PIPE, shell=True).communicate()[0][:-1] else:
--- a/src/browser/card_game.py Tue May 20 07:22:10 2014 +0200 +++ b/src/browser/card_game.py Tue May 20 10:54:03 2014 +0200 @@ -280,7 +280,7 @@ elif phase == "ecart": self.state = "ecart" else: - log.error("INTERNAL ERROR: unmanaged game phase") # FIXME: raise an exception here + log.error("INTERNAL ERROR: unmanaged game phase") # FIXME: raise an exception here for suit, value in played_cards: self.hand.append(self.cards[(suit, value)])
--- a/src/browser/contact.py Tue May 20 07:22:10 2014 +0200 +++ b/src/browser/contact.py Tue May 20 10:54:03 2014 +0200 @@ -60,7 +60,7 @@ def __init__(self, host, group): self.group = group self.host = host - Label.__init__(self, group) #, Element=DOM.createElement('div') + Label.__init__(self, group) # , Element=DOM.createElement('div') self.setStyleName('group') DragLabel.__init__(self, group, "GROUP") ClickHandler.__init__(self) @@ -222,7 +222,7 @@ class ContactTitleLabel(DragLabel, Label, ClickHandler): def __init__(self, host, text): - Label.__init__(self, text) #, Element=DOM.createElement('div') + Label.__init__(self, text) # , Element=DOM.createElement('div') self.host = host self.setStyleName('contactTitle') DragLabel.__init__(self, text, "CONTACT_TITLE") @@ -412,4 +412,3 @@ for contact in self._contact_list: if contact.jid in self.groups[sender.group]: contact.removeStyleName("selected") -
--- a/src/browser/dialog.py Tue May 20 07:22:10 2014 +0200 +++ b/src/browser/dialog.py Tue May 20 10:54:03 2014 +0200 @@ -309,7 +309,7 @@ if not options: options = [] _body = VerticalPanel() - _body.setSize('100%','100%') + _body.setSize('100%', '100%') _body.setSpacing(4) _body.add(main_widget) _body.setCellWidth(main_widget, '100%') @@ -320,7 +320,7 @@ _body.setCellHorizontalAlignment(_close_button, HasAlignment.ALIGN_CENTER) self.setHTML(title) self.setWidget(_body) - self.panel.setSize('100%', '100%') #Need this hack to have correct size in Gecko & Webkit + self.panel.setSize('100%', '100%') # Need this hack to have correct size in Gecko & Webkit def close(self): """Same effect as clicking the close button"""
--- a/src/browser/libervia_main.py Tue May 20 07:22:10 2014 +0200 +++ b/src/browser/libervia_main.py Tue May 20 10:54:03 2014 +0200 @@ -41,7 +41,8 @@ from contact import ContactPanel from base_widget import WidgetsPanel from panels import MicroblogItem -import panels, dialog +import panels +import dialog from jid import JID from xmlui import XMLUI from html_tools import html_sanitize @@ -397,7 +398,7 @@ # action was a one shot, nothing to do pass elif "xmlui" in data: - ui = XMLUI(self, xml_data = data['xmlui']) + ui = XMLUI(self, xml_data=data['xmlui']) options = ['NO_CLOSE'] if ui.type == 'form' else [] _dialog = dialog.GenericDialog(ui.title, ui, options=options) ui.setCloseCb(_dialog.close) @@ -498,10 +499,10 @@ #put our own microblogs in cache, then fill all panels with them for publisher in mblogs: for mblog in mblogs[publisher]: - if not mblog.has_key('content'): + if 'content' not in mblog: log.warning("No content found in microblog [%s]" % mblog) continue - if mblog.has_key('groups'): + if 'groups' not in mblog: _groups = set(mblog['groups'].split() if mblog['groups'] else []) else: _groups = None @@ -513,8 +514,8 @@ for lib_wid in self.libervia_widgets: if isinstance(lib_wid, panels.MicroblogPanel): self.FillMicroblogPanel(lib_wid) - self.initialised = True # initialisation phase is finished here - for event_data in self.init_cache: # so we have to send all the cached events + self.initialised = True # initialisation phase is finished here + for event_data in self.init_cache: # so we have to send all the cached events self._personalEventCb(*event_data) del self.init_cache @@ -697,7 +698,7 @@ self.room_list.append(_target) chat_panel = panels.ChatPanel(self, _target, type_='group') chat_panel.setUserNick(user_nick) - if _target.node.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :) + if _target.node.startswith('sat_tarot_'): # XXX: it's not really beautiful, but it works :) self.addTab("Tarot", chat_panel) elif _target.node.startswith('sat_radiocol_'): self.addTab("Radio collective", chat_panel) @@ -782,6 +783,7 @@ def ok_cb(ignore): self.bridge.call('subscription', None, "subscribed", entity, '', _dialog.getSelectedGroups()) + def cancel_cb(ignore): self.bridge.call('subscription', None, "unsubscribed", entity, '', '')
--- a/src/browser/nativedom.py Tue May 20 07:22:10 2014 +0200 +++ b/src/browser/nativedom.py Tue May 20 10:54:03 2014 +0200 @@ -31,10 +31,10 @@ self._node = js_node def _jsNodesList2List(self, js_nodes_list): - ret=[] + ret = [] for i in range(len(js_nodes_list)): #ret.append(Element(js_nodes_list.item(i))) - ret.append(self.__class__(js_nodes_list.item(i))) # XXX: Ugly, but used to word around a Pyjamas's bug + ret.append(self.__class__(js_nodes_list.item(i))) # XXX: Ugly, but used to word around a Pyjamas's bug return ret @property @@ -105,4 +105,3 @@ def parseString(self, xml): return Document(self.parseXml(xml)) -
--- a/src/browser/panels.py Tue May 20 07:22:10 2014 +0200 +++ b/src/browser/panels.py Tue May 20 10:54:03 2014 +0200 @@ -174,7 +174,7 @@ self._selected_cache = selected -class UniBox(MessageBox, MouseHandler): #AutoCompleteTextBox): +class UniBox(MessageBox, MouseHandler): # AutoCompleteTextBox): """This text box is used as a main typing point, for message, microblog, etc""" def __init__(self, host):
--- a/src/browser/radiocol.py Tue May 20 07:22:10 2014 +0200 +++ b/src/browser/radiocol.py Tue May 20 10:54:03 2014 +0200 @@ -191,7 +191,6 @@ self.setAutoplay(False) self.setVisible(False) - def preload(self, timestamp, filename, title, artist, album): """preload the song but doesn't play it""" self.timestamp = timestamp
--- a/src/browser/register.py Tue May 20 07:22:10 2014 +0200 +++ b/src/browser/register.py Tue May 20 10:54:03 2014 +0200 @@ -20,7 +20,7 @@ #This page manage subscription and new account creation -import pyjd # this is dummy in pyjs +import pyjd # this is dummy in pyjs from sat.core.i18n import _ from pyjamas.ui.SimplePanel import SimplePanel
--- a/src/browser/xmlui.py Tue May 20 07:22:10 2014 +0200 +++ b/src/browser/xmlui.py Tue May 20 10:54:03 2014 +0200 @@ -52,7 +52,7 @@ class LabelWidget(xmlui.LabelWidget, TextWidget): def __init__(self, parent, value): - TextWidget.__init__(self, parent, value+": ") + TextWidget.__init__(self, parent, value + ": ") class JidWidget(xmlui.JidWidget, TextWidget): @@ -226,7 +226,6 @@ except AttributeError: log.warning("no select callback set") - def _xmluiAppend(self, widget): self.setWidget(self.row, self.col, widget) self.col += 1 @@ -235,7 +234,7 @@ self.row += 1 self.col = 0 self._xmlui_rows_idx.insert(self.row, idx) - self.resizeRows(self.row+1) + self.resizeRows(self.row + 1) def _xmluiGetSelectedWidgets(self): return [self.getWidget(self._xmlui_selected_row, col) for col in range(self.columns)] @@ -259,15 +258,14 @@ def _xmluiAppend(self, widget): if self.col == 0: - self.resize(self.row+1, 2) + self.resize(self.row + 1, 2) self.setWidget(self.row, self.col, widget) self.col += 1 if self.col == 2: - self.row +=1 + self.row += 1 self.col = 0 - class TabsContainer(LiberviaContainer, xmlui.TabsContainer, TabPanel): def __init__(self, parent): @@ -378,7 +376,7 @@ class XMLUI(xmlui.XMLUI, VerticalPanel): widget_factory = WidgetFactory() - def __init__(self, host, xml_data, title = None, flags = None): + def __init__(self, host, xml_data, title=None, flags=None): self.widget_factory._xmlui_main = self self.dom = NativeDOM() dom_parse = lambda xml_data: self.dom.parseString(xml_data) @@ -408,12 +406,12 @@ if self.type == 'form': hpanel = HorizontalPanel() hpanel.setStyleName('marginAuto') - hpanel.add(Button('Submit',self.onFormSubmitted)) + hpanel.add(Button('Submit', self.onFormSubmitted)) if not 'NO_CANCEL' in self.flags: - hpanel.add(Button('Cancel',self.onFormCancelled)) + hpanel.add(Button('Cancel', self.onFormCancelled)) self.add(hpanel) elif self.type == 'param': - assert(isinstance(self.children[0][0],TabPanel)) + assert(isinstance(self.children[0][0], TabPanel)) hpanel = HorizontalPanel() hpanel.add(Button('Save', self.onSaveParams)) hpanel.add(Button('Cancel', lambda ignore: self._xmluiClose()))
--- a/src/server/html_tools.py Tue May 20 07:22:10 2014 +0200 +++ b/src/server/html_tools.py Tue May 20 10:54:03 2014 +0200 @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. + def sanitizeHtml(text): """Sanitize HTML by escaping everything""" #this code comes from official python wiki: http://wiki.python.org/moin/EscapingHtml @@ -28,5 +29,4 @@ "<": "<", } - return "".join(html_escape_table.get(c,c) for c in text) - + return "".join(html_escape_table.get(c, c) for c in text)
--- a/src/server/server.py Tue May 20 07:22:10 2014 +0200 +++ b/src/server/server.py Tue May 20 10:54:03 2014 +0200 @@ -67,6 +67,7 @@ class SATSession(object): implements(ISATSession) + def __init__(self, session): self.profile = None self.jid = None @@ -93,15 +94,17 @@ if not self.__lock: server.Session.touch(self) + class ProtectedFile(File): """A File class which doens't show directory listing""" def directoryListing(self): return NoResource() + class SATActionIDHandler(object): """Manage SàT action action_id lifecycle""" - ID_LIFETIME = 30 #after this time (in seconds), action_id will be suppressed and action result will be ignored + ID_LIFETIME = 30 # after this time (in seconds), action_id will be suppressed and action result will be ignored def __init__(self): self.waiting_ids = {} @@ -120,7 +123,7 @@ def purgeID(self, action_tuple): """Called when an action_id has not be handled in time""" if action_tuple in self.waiting_ids: - log.warning ("action of action_id %s [%s] has not been managed, action_id is now ignored" % action_tuple) + log.warning("action of action_id %s [%s] has not been managed, action_id is now ignored" % action_tuple) del self.waiting_ids[action_tuple] def actionResultCb(self, answer_type, action_id, data, profile): @@ -131,11 +134,12 @@ del self.waiting_ids[action_tuple] callback(answer_type, action_id, data, *args, **kwargs) + class JSONRPCMethodManager(jsonrpc.JSONRPC): def __init__(self, sat_host): jsonrpc.JSONRPC.__init__(self) - self.sat_host=sat_host + self.sat_host = sat_host def asyncBridgeCall(self, method_name, *args, **kwargs): """Call an asynchrone bridge method and return a deferred @@ -174,7 +178,7 @@ if not profile: #user is not identified, we return a jsonrpc fault parsed = jsonrpclib.loads(request.content.read()) - fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia + fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, "Not allowed") # FIXME: define some standard error codes for libervia return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) return jsonrpc.JSONRPC.render(self, request) @@ -233,7 +237,6 @@ profile = ISATSession(self.session).profile self.sat_host.bridge.setPresence('', presence, {'': status}, profile) - def jsonrpc_sendMessage(self, to_jid, msg, subject, type_, options={}): """send message""" profile = ISATSession(self.session).profile @@ -343,7 +346,6 @@ d = self.asyncBridgeCall("getGroupBlogComments", service, node, profile) return d - def jsonrpc_getPresenceStatuses(self): """Get Presence information for connected contacts""" profile = ISATSession(self.session).profile @@ -361,6 +363,7 @@ log.error("Trying to get history from a different jid, maybe a hack attempt ?") return {} d = self.asyncBridgeCall("getHistory", from_jid, to_jid, size, between, profile) + def show(result_dbus): result = [] for line in result_dbus: @@ -429,8 +432,8 @@ def jsonrpc_getTarotCardsPaths(self): """Give the path of all the tarot cards""" _join = os.path.join - _media_dir = _join(self.sat_host.media_dir,'') - return map(lambda x: _join(C.MEDIA_DIR, x[len(_media_dir):]), glob.glob(_join(_media_dir, C.CARDS_DIR, '*_*.png'))); + _media_dir = _join(self.sat_host.media_dir, '') + return map(lambda x: _join(C.MEDIA_DIR, x[len(_media_dir):]), glob.glob(_join(_media_dir, C.CARDS_DIR, '*_*.png'))) def jsonrpc_tarotGameReady(self, player, referee): """Tell to the server that we are ready to start the game""" @@ -554,12 +557,12 @@ def __init__(self, sat_host): JSONRPCMethodManager.__init__(self, sat_host) - self.profiles_waiting={} - self.request=None + self.profiles_waiting = {} + self.request = None def getWaitingRequest(self, profile): """Tell if a profile is trying to log in""" - if self.profiles_waiting.has_key(profile): + if profile in self.profiles_waiting: return self.profiles_waiting[profile] else: return None @@ -581,7 +584,7 @@ profile = ISATSession(_session).profile if not profile: #user is not identified, we return a jsonrpc fault - fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia + fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, "Not allowed") # FIXME: define some standard error codes for libervia return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) self.request = request return jsonrpc.JSONRPC.render(self, request) @@ -743,8 +746,8 @@ def jsonrpc_connect(self): _session = self.request.getSession() profile = ISATSession(_session).profile - if self.profiles_waiting.has_key(profile): - raise jsonrpclib.Fault(1,'Already waiting') #FIXME: define some standard error codes for libervia + if profile in self.profiles_waiting: + raise jsonrpclib.Fault(1, 'Already waiting') # FIXME: define some standard error codes for libervia self.profiles_waiting[profile] = self.request self.sat_host.bridge.connect(profile) return server.NOT_DONE_YET @@ -801,8 +804,8 @@ def __init__(self, sat_host): Resource.__init__(self) - self.register=None - self.sat_host=sat_host + self.register = None + self.sat_host = sat_host self.signalDeferred = {} self.queue = {} @@ -814,13 +817,14 @@ @return: (signal, *signal_args)""" _session = self.request.getSession() profile = ISATSession(_session).profile - if profile in self.queue: #if we have signals to send in queue + if profile in self.queue: # if we have signals to send in queue if self.queue[profile]: return self.queue[profile].pop(0) else: #the queue is empty, we delete the profile from queue del self.queue[profile] - _session.lock() #we don't want the session to expire as long as this connection is active + _session.lock() # we don't want the session to expire as long as this connection is active + def unlock(signal, profile): _session.unlock() try: @@ -846,7 +850,7 @@ self.signalDeferred[profile].callback((function_name,args[:-1])) del self.signalDeferred[profile] else: - if not self.queue.has_key(profile): + if profile not in self.queue: self.queue[profile] = [] self.queue[profile].append((function_name, args[:-1])) return genericCb @@ -866,15 +870,14 @@ self.signalDeferred[profile].callback(("disconnected",)) del self.signalDeferred[profile] else: - if not self.queue.has_key(profile): + if profile not in self.queue: self.queue[profile] = [] self.queue[profile].append(("disconnected",)) - def connectionError(self, error_type, profile): - assert(self.register) #register must be plugged + assert(self.register) # register must be plugged request = self.register.getWaitingRequest(profile) - if request: #The user is trying to log in + if request: # The user is trying to log in if error_type == "AUTH_ERROR": _error_t = "AUTH ERROR" else: @@ -890,19 +893,20 @@ profile = ISATSession(_session).profile if not profile: #user is not identified, we return a jsonrpc fault - fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia + fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, "Not allowed") # FIXME: define some standard error codes for libervia return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) self.request = request return jsonrpc.JSONRPC.render(self, request) + class UploadManager(Resource): """This class manage the upload of a file It redirect the stream to SàT core backend""" isLeaf = True - NAME = 'path' #name use by the FileUpload + NAME = 'path' # name use by the FileUpload def __init__(self, sat_host): - self.sat_host=sat_host + self.sat_host = sat_host self.upload_dir = tempfile.mkdtemp() self.sat_host.addCleanup(shutil.rmtree, self.upload_dir) @@ -936,11 +940,11 @@ # be written in the futur. In addition, it is not yet possible to get progression informations # (see http://twistedmatrix.com/trac/ticket/288) - with open(filepath,'w') as f: + with open(filepath, 'w') as f: f.write(request.args[self.NAME][0]) def finish(d): - error = isinstance(d, Exception) or isinstance (d, Failure) + error = isinstance(d, Exception) or isinstance(d, Failure) request.write('KO' if error else 'OK') # TODO: would be great to re-use the original Exception class and message # but it is lost in the middle of the backtrace and encapsulated within @@ -1048,15 +1052,16 @@ _upload_radiocol = UploadManagerRadioCol(self) _upload_avatar = UploadManagerAvatar(self) self.signal_handler.plugRegister(_register) - self.sessions = {} #key = session value = user - self.prof_connected = set() #Profiles connected + self.sessions = {} # key = session value = user + self.prof_connected = set() # Profiles connected self.action_handler = SATActionIDHandler() ## bridge ## try: - self.bridge=DBusBridgeFrontend() + self.bridge = DBusBridgeFrontend() except BridgeExceptionNoService: print(u"Can't connect to SàT backend, are you sure it's launched ?") sys.exit(1) + def backendReady(dummy): self.bridge.register("connected", self.signal_handler.connected) self.bridge.register("disconnected", self.signal_handler.disconnected)