From ef689d04fc9e3612c4e7062b867e2996c892addd Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Thu, 6 Jun 2019 11:52:23 -0500 Subject: [PATCH 1/3] Initial Python 3 compatible code --- src/application.py | 9 +- src/audio_services/__init__.py | 1 + src/audio_services/services.py | 1 + src/audio_services/youtube_utils.py | 1 + src/config.py | 5 +- src/controller/attach.py | 2 + src/controller/buffers/__init__.py | 3 +- src/controller/buffers/baseBuffers.py | 2 + src/controller/buffers/twitterBuffers.py | 7 +- src/controller/filterController.py | 4 +- src/controller/listsController.py | 2 + src/controller/mainController.py | 15 +- src/controller/messages.py | 14 +- src/controller/settings.py | 7 +- src/controller/trendingTopics.py | 2 + src/controller/user.py | 2 + src/controller/userActionsController.py | 2 + src/extra/AudioUploader/audioUploader.py | 5 +- src/extra/AudioUploader/transfer.py | 10 +- src/extra/AudioUploader/utils.py | 2 + .../AudioUploader/wx_transfer_dialogs.py | 1 + src/extra/AudioUploader/wx_ui.py | 1 + src/extra/SoundsTutorial/__init__.py | 1 + src/extra/SoundsTutorial/gtk_ui.py | 1 + src/extra/SoundsTutorial/reverse_sort.py | 1 + src/extra/SoundsTutorial/soundsTutorial.py | 2 + .../soundsTutorial_constants.py | 1 + src/extra/SoundsTutorial/wx_ui.py | 1 + src/extra/SpellChecker/__init__.py | 1 + src/extra/SpellChecker/spellchecker.py | 3 + src/extra/SpellChecker/twitterFilter.py | 1 + src/extra/SpellChecker/wx_ui.py | 1 + src/extra/autocompletionUsers/__init__.py | 1 + src/extra/autocompletionUsers/completion.py | 2 + src/extra/autocompletionUsers/manage.py | 2 + src/extra/autocompletionUsers/settings.py | 2 + src/extra/autocompletionUsers/storage.py | 2 + src/extra/autocompletionUsers/wx_manage.py | 1 + src/extra/autocompletionUsers/wx_menu.py | 1 + src/extra/autocompletionUsers/wx_settings.py | 1 + src/extra/ocr/OCRSpace.py | 2 + src/extra/ocr/__init__.py | 1 + src/extra/translator/__init__.py | 1 + src/extra/translator/translator.py | 2 + src/extra/translator/wx_ui.py | 1 + src/fixes/__init__.py | 1 + src/fixes/fix_arrow.py | 1 + src/fixes/fix_libloader.py | 1 + src/fixes/fix_requests.py | 1 + src/fixes/fix_urllib3_warnings.py | 7 +- src/fixes/fix_win32com.py | 1 + src/issueReporter/constants.py | 1 + src/issueReporter/issueReporter.py | 2 + src/issueReporter/wx_ui.py | 1 + src/keyboard_handler/__init__.py | 6 +- src/keyboard_handler/global_handler.py | 11 +- src/keyboard_handler/key_constants.py | 128 ++++++++++++++++++ src/keyboard_handler/main.py | 8 +- src/keyboard_handler/wx_handler.py | 39 ++++-- src/keys/__init__.py | 7 +- src/keys/linuxKeys.py | 1 + src/keystrokeEditor/__init__.py | 1 + src/keystrokeEditor/constants.py | 1 + src/keystrokeEditor/keystrokeEditor.py | 2 + src/keystrokeEditor/wx_ui.py | 1 + src/languageHandler.py | 43 +++--- src/logger.py | 24 ++-- src/main.py | 12 +- src/multiplatform_widgets/__init__.py | 1 + src/multiplatform_widgets/widgets.py | 5 +- src/mysc/autostart.py | 25 ++-- src/mysc/localization.py | 1 + src/mysc/repeating_timer.py | 1 + src/mysc/restart.py | 1 + src/mysc/thread_utils.py | 3 + src/notifier/__init__.py | 1 + src/notifier/linux.py | 2 + src/notifier/windows.py | 2 + src/paths.py | 110 +++++++-------- src/sessionmanager/__init__.py | 3 +- src/sessionmanager/gtkUI.py | 1 + src/sessionmanager/manager.py | 2 + src/sessionmanager/sessionManager.py | 13 +- src/sessionmanager/wxUI.py | 1 + src/sessions/__init__.py | 1 + src/sessions/base.py | 20 +-- src/sessions/session_exceptions.py | 14 +- src/sessions/twitter/compose.py | 16 ++- src/sessions/twitter/long_tweets/__init__.py | 3 +- src/sessions/twitter/long_tweets/tweets.py | 1 + src/sessions/twitter/long_tweets/twishort.py | 2 + src/sessions/twitter/session.py | 5 +- src/sessions/twitter/utils.py | 3 + src/sessions/twitter/wxUI.py | 1 + src/sound.py | 10 +- src/update/__init__.py | 1 + src/update/update.py | 1 + src/update/updater.py | 1 + src/update/utils.py | 2 + src/update/wxUpdater.py | 6 +- src/url_shortener/__init__.py | 3 +- src/url_shortener/__main__.py | 1 + src/url_shortener/shorteners/__init__.py | 19 +-- src/url_shortener/shorteners/acortame.py | 11 +- src/url_shortener/shorteners/clckru.py | 9 +- src/url_shortener/shorteners/hkcim.py | 9 +- src/url_shortener/shorteners/isgd.py | 9 +- src/url_shortener/shorteners/onjme.py | 9 +- src/url_shortener/shorteners/tinyarrows.py | 9 +- src/url_shortener/shorteners/tinyurl.py | 9 +- src/url_shortener/shorteners/url_shortener.py | 4 +- src/url_shortener/shorteners/xedcc.py | 9 +- src/widgetUtils/__init__.py | 1 + src/widgetUtils/gtkUtils.py | 3 + src/widgetUtils/wxUtils.py | 1 + src/wxUI/buffers/__init__.py | 1 + src/wxUI/buffers/base.py | 1 + src/wxUI/buffers/dm.py | 1 + src/wxUI/buffers/events.py | 1 + src/wxUI/buffers/favourites.py | 1 + src/wxUI/buffers/lists.py | 1 + src/wxUI/buffers/panels.py | 1 + src/wxUI/buffers/people.py | 1 + src/wxUI/buffers/trends.py | 1 + src/wxUI/buffers/tweet_searches.py | 1 + src/wxUI/buffers/user_searches.py | 1 + src/wxUI/commonMessageDialogs.py | 1 + src/wxUI/dialogs/__init__.py | 1 + src/wxUI/dialogs/attach.py | 1 + src/wxUI/dialogs/baseDialog.py | 1 + src/wxUI/dialogs/configuration.py | 4 +- src/wxUI/dialogs/filterDialogs.py | 1 + src/wxUI/dialogs/find.py | 1 + src/wxUI/dialogs/lists.py | 1 + src/wxUI/dialogs/message.py | 2 + src/wxUI/dialogs/search.py | 5 +- src/wxUI/dialogs/show_user.py | 1 + src/wxUI/dialogs/trends.py | 1 + src/wxUI/dialogs/update_profile.py | 1 + src/wxUI/dialogs/urlList.py | 1 + src/wxUI/dialogs/userActions.py | 1 + src/wxUI/dialogs/userSelection.py | 1 + src/wxUI/dialogs/utils.py | 1 + src/wxUI/menus.py | 1 + src/wxUI/sysTrayIcon.py | 1 + src/wxUI/view.py | 2 + 146 files changed, 589 insertions(+), 246 deletions(-) create mode 100644 src/keyboard_handler/key_constants.py diff --git a/src/application.py b/src/application.py index 7aae398c..121ba416 100644 --- a/src/application.py +++ b/src/application.py @@ -2,6 +2,7 @@ import datetime name = 'TWBlue' +short_name='twblue' snapshot = True if snapshot == False: version = "0.94" @@ -11,11 +12,11 @@ else: version = "14" update_url = 'https://twblue.es/updates/snapshot.php' mirror_update_url = 'https://raw.githubusercontent.com/manuelcortez/TWBlue/next-gen/updates/snapshots.json' -authors = [u"Manuel Cortéz", u"José Manuel Delicado"] +authors = ["Manuel Cortéz", "José Manuel Delicado"] authorEmail = "manuel@manuelcortez.net" -copyright = u"Copyright (C) 2013-2018, Manuel cortéz." -description = unicode(name+" is an app designed to use Twitter simply and efficiently while using minimal system resources. This app provides access to most Twitter features.") -translators = [u"Manuel Cortéz (English)", u"Mohammed Al Shara, Hatoun Felemban (Arabic)", u"Francisco Torres (Catalan)", u"Manuel cortéz (Spanish)", u"Sukil Etxenike Arizaleta (Basque)", u"Jani Kinnunen (finnish)", u"Rémy Ruiz (French)", u"Juan Buño (Galician)", u"Steffen Schultz (German)", u"Zvonimir Stanečić (Croatian)", u"Robert Osztolykan (Hungarian)", u"Christian Leo Mameli (Italian)", u"Riku (Japanese)", u"Paweł Masarczyk (Polish)", u"Odenilton Júnior Santos (Portuguese)", u"Florian Ionașcu, Nicușor Untilă (Romanian)", u"Natalia Hedlund, Valeria Kuznetsova (Russian)", u"Aleksandar Đurić (Serbian)", u"Burak Yüksek (Turkish)"] +copyright = "Copyright (C) 2013-2018, Manuel cortéz." +description = name+" is an app designed to use Twitter simply and efficiently while using minimal system resources. This app provides access to most Twitter features." +translators = ["Manuel Cortéz (English)", "Mohammed Al Shara, Hatoun Felemban (Arabic)", "Francisco Torres (Catalan)", "Manuel cortéz (Spanish)", "Sukil Etxenike Arizaleta (Basque)", "Jani Kinnunen (finnish)", "Rémy Ruiz (French)", "Juan Buño (Galician)", "Steffen Schultz (German)", "Zvonimir Stanečić (Croatian)", "Robert Osztolykan (Hungarian)", "Christian Leo Mameli (Italian)", "Riku (Japanese)", "Paweł Masarczyk (Polish)", "Odenilton Júnior Santos (Portuguese)", "Florian Ionașcu, Nicușor Untilă (Romanian)", "Natalia Hedlund, Valeria Kuznetsova (Russian)", "Aleksandar Đurić (Serbian)", "Burak Yüksek (Turkish)"] url = u"https://twblue.es" report_bugs_url = "https://github.com/manuelcortez/twblue/issues" supported_languages = [] \ No newline at end of file diff --git a/src/audio_services/__init__.py b/src/audio_services/__init__.py index 556257cc..4d092b4c 100644 --- a/src/audio_services/__init__.py +++ b/src/audio_services/__init__.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals from functools import wraps def matches_url(url): diff --git a/src/audio_services/services.py b/src/audio_services/services.py index 8c89e7cf..c5d1a8db 100644 --- a/src/audio_services/services.py +++ b/src/audio_services/services.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals from audio_services import matches_url import youtube_utils import requests diff --git a/src/audio_services/youtube_utils.py b/src/audio_services/youtube_utils.py index 94011513..92c8c3fa 100644 --- a/src/audio_services/youtube_utils.py +++ b/src/audio_services/youtube_utils.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import youtube_dl def get_video_url(url): diff --git a/src/config.py b/src/config.py index e55ec95b..4172f37b 100644 --- a/src/config.py +++ b/src/config.py @@ -1,4 +1,5 @@ # -*- coding: cp1252 -*- +import os import config_utils import paths import logging @@ -16,7 +17,7 @@ changed_keymap = False def setup (): global app log.debug("Loading global app settings...") - app = config_utils.load_config(paths.config_path(MAINFILE), paths.app_path(MAINSPEC)) + app = config_utils.load_config(os.path.join(paths.config_path(), MAINFILE), os.path.join(paths.app_path(), MAINSPEC)) log.debug("Loading keymap...") global keymap if float(platform.version()[:2]) >= 10 and app["app-settings"]["load_keymap"] == "default.keymap": @@ -24,4 +25,4 @@ def setup (): app.write() global changed_keymap changed_keymap = True - keymap = config_utils.load_config(paths.config_path("keymap.keymap"), paths.app_path("keymaps/"+app['app-settings']['load_keymap']), copy=False) + keymap = config_utils.load_config(os.path.join(paths.config_path(), "keymap.keymap"), os.path.join(paths.app_path(), "keymaps/"+app['app-settings']['load_keymap']), copy=False) diff --git a/src/controller/attach.py b/src/controller/attach.py index c2af23bb..666e55f3 100644 --- a/src/controller/attach.py +++ b/src/controller/attach.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import object import os import widgetUtils import logging diff --git a/src/controller/buffers/__init__.py b/src/controller/buffers/__init__.py index 4e795946..2900a6e9 100644 --- a/src/controller/buffers/__init__.py +++ b/src/controller/buffers/__init__.py @@ -4,4 +4,5 @@ Currently, the package contains the following modules: * baseBuffers: Define a set of functions and structure to be expected in all buffers. New buffers should inherit its classes from one of the classes present here. * twitterBuffers: All other code, specific to Twitter. -""" \ No newline at end of file +""" +from __future__ import unicode_literals \ No newline at end of file diff --git a/src/controller/buffers/baseBuffers.py b/src/controller/buffers/baseBuffers.py index 3af495cc..728a5e62 100644 --- a/src/controller/buffers/baseBuffers.py +++ b/src/controller/buffers/baseBuffers.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """ Common logic to all buffers in TWBlue.""" +from __future__ import unicode_literals +from builtins import object import logging import wx import output diff --git a/src/controller/buffers/twitterBuffers.py b/src/controller/buffers/twitterBuffers.py index 25f3a6be..96d72e66 100644 --- a/src/controller/buffers/twitterBuffers.py +++ b/src/controller/buffers/twitterBuffers.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import str +from builtins import range import time import platform if platform.system() == "Windows": @@ -67,7 +70,7 @@ class baseBufferController(baseBuffers.buffer): """ Get buffer name from a set of different techniques.""" # firstly let's take the easier buffers. basic_buffers = dict(home_timeline=_(u"Home"), mentions=_(u"Mentions"), direct_messages=_(u"Direct messages"), sent_direct_messages=_(u"Sent direct messages"), sent_tweets=_(u"Sent tweets"), favourites=_(u"Likes"), followers=_(u"Followers"), friends=_(u"Friends"), blocked=_(u"Blocked users"), muted=_(u"Muted users")) - if self.name in basic_buffers.keys(): + if self.name in list(basic_buffers.keys()): return basic_buffers[self.name] # Check user timelines elif hasattr(self, "username"): @@ -266,7 +269,7 @@ class baseBufferController(baseBuffers.buffer): def remove_tweet(self, id): if type(self.session.db[self.name]) == dict: return - for i in xrange(0, len(self.session.db[self.name])): + for i in range(0, len(self.session.db[self.name])): if self.session.db[self.name][i]["id"] == id: self.session.db[self.name].pop(i) self.remove_item(i) diff --git a/src/controller/filterController.py b/src/controller/filterController.py index 1ece0bf9..5f6fa6ed 100644 --- a/src/controller/filterController.py +++ b/src/controller/filterController.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import object import time import widgetUtils import application @@ -51,7 +53,7 @@ class filterManager(object): def insert_filters(self, filters): self.dialog.filters.clear() - for f in filters.keys(): + for f in list(filters.keys()): filterName = f buffer = filters[f]["in_buffer"] if filters[f]["if_word_exists"] == "True" and filters[f]["word"] != "": diff --git a/src/controller/listsController.py b/src/controller/listsController.py index f3d60ee0..19f8932a 100644 --- a/src/controller/listsController.py +++ b/src/controller/listsController.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import object import widgetUtils import output from wxUI.dialogs import lists diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 4f89c987..920e118f 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import str +from builtins import range +from builtins import object import platform system = platform.system() import application @@ -268,7 +271,7 @@ class Controller(object): self.start_buffers(sessions.sessions[i]) self.set_buffer_positions(sessions.sessions[i]) if config.app["app-settings"]["play_ready_sound"] == True: - sessions.sessions[sessions.sessions.keys()[0]].sound.play("ready.ogg") + sessions.sessions[list(sessions.sessions.keys())[0]].sound.play("ready.ogg") if config.app["app-settings"]["speak_ready_msg"] == True: output.speak(_(u"Ready")) self.started = True @@ -465,7 +468,7 @@ class Controller(object): output.speak(_(u"Empty buffer."), True) return start = page.buffer.list.get_selected() - for i in xrange(start, count): + for i in range(start, count): if string.lower() in page.buffer.list.get_text_column(i, 1).lower(): page.buffer.list.select_item(i) return output.speak(page.get_message(), True) @@ -969,8 +972,8 @@ class Controller(object): x = tweet["coordinates"]["coordinates"][0] y = tweet["coordinates"]["coordinates"][1] address = geocoder.reverse_geocode(y, x, language = languageHandler.curLang) - if event == None: output.speak(address[0].__str__().decode("utf-8")) - else: self.view.show_address(address[0].__str__().decode("utf-8")) + if event == None: output.speak(address[0].__str__()) + else: self.view.show_address(address[0].__str__()) else: output.speak(_(u"There are no coordinates in this tweet")) except GeocoderError: @@ -1580,7 +1583,7 @@ class Controller(object): elif "quoted_status" in tweet and "media" in tweet["quoted_status"]["entities"]: [media_list.append(i) for i in tweet["quoted_status"]["entities"]["media"] if i not in media_list] if len(media_list) > 1: - image_list = [_(u"Picture {0}").format(i,) for i in xrange(0, len(media_list))] + image_list = [_(u"Picture {0}").format(i,) for i in range(0, len(media_list))] dialog = dialogs.urlList.urlList(title=_(u"Select the picture")) if dialog.get_response() == widgetUtils.OK: img = media_list[dialog.get_item()] diff --git a/src/controller/messages.py b/src/controller/messages.py index 8668e6cd..249f58ea 100644 --- a/src/controller/messages.py +++ b/src/controller/messages.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import str +from builtins import range +from builtins import object import re import platform from . import attach @@ -173,14 +177,14 @@ class reply(tweet): def get_ids(self): excluded_ids = "" - for i in xrange(0, len(self.message.checkboxes)): + for i in range(0, len(self.message.checkboxes)): if self.message.checkboxes[i].GetValue() == False: excluded_ids = excluded_ids + "{0},".format(self.ids[i],) return excluded_ids def get_people(self): people = "" - for i in xrange(0, len(self.message.checkboxes)): + for i in range(0, len(self.message.checkboxes)): if self.message.checkboxes[i].GetValue() == True: people = people + "{0} ".format(self.message.checkboxes[i].GetLabel(),) return people @@ -205,7 +209,7 @@ class viewTweet(basicTweet): self.title = _(u"Tweet") image_description = [] text = "" - for i in xrange(0, len(tweetList)): + for i in range(0, len(tweetList)): # tweets with message keys are longer tweets, the message value is the full messaje taken from twishort. if "message" in tweetList[i] and tweetList[i]["is_quote_status"] == False: value = "message" @@ -231,7 +235,7 @@ class viewTweet(basicTweet): rt_count = str(tweet["retweet_count"]) favs_count = str(tweet["favorite_count"]) # Gets the client from where this tweet was made. - source = str(re.sub(r"(?s)<.*?>", "", tweet["source"].encode("utf-8"))) + source = re.sub(r"(?s)<.*?>", "", tweet["source"]) original_date = arrow.get(tweet["created_at"], "ddd MMM DD H:m:s Z YYYY", locale="en") date = original_date.replace(seconds=utc_offset).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage()) if text == "": @@ -255,7 +259,7 @@ class viewTweet(basicTweet): for z in tweet["retweeted_status"]["extended_entities"]["media"]: if "ext_alt_text" in z and z["ext_alt_text"] != None: image_description.append(z["ext_alt_text"]) - self.message = message.viewTweet(text, rt_count, favs_count, source.decode("utf-8"), date) + self.message = message.viewTweet(text, rt_count, favs_count, source, date) self.message.set_title(len(text)) [self.message.set_image_description(i) for i in image_description] else: diff --git a/src/controller/settings.py b/src/controller/settings.py index c8828085..f91c1511 100644 --- a/src/controller/settings.py +++ b/src/controller/settings.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import str +from builtins import object import os import webbrowser import sound_lib @@ -49,7 +52,7 @@ class globalSettingsController(object): id = self.codes.index(config.app["app-settings"]["language"]) self.kmfriendlies=[] self.kmnames=[] - for k,v in self.kmmap.items(): + for k,v in list(self.kmmap.items()): self.kmfriendlies.append(k) self.kmnames.append(v) self.kmid=self.kmnames.index(config.app['app-settings']['load_keymap']) @@ -291,7 +294,7 @@ class accountSettingsController(globalSettingsController): all_buffers['muted']=_(u"Muted users") list_buffers = [] hidden_buffers=[] - all_buffers_keys = all_buffers.keys() + all_buffers_keys = list(all_buffers.keys()) # Check buffers shown first. for i in self.config["general"]["buffer_order"]: if i in all_buffers_keys: diff --git a/src/controller/trendingTopics.py b/src/controller/trendingTopics.py index 7b181b9b..4982c7d7 100644 --- a/src/controller/trendingTopics.py +++ b/src/controller/trendingTopics.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import object from wxUI.dialogs import trends import widgetUtils diff --git a/src/controller/user.py b/src/controller/user.py index 187febdd..6149a1bc 100644 --- a/src/controller/user.py +++ b/src/controller/user.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import object import wx import webbrowser import widgetUtils diff --git a/src/controller/userActionsController.py b/src/controller/userActionsController.py index f3f40ded..b77f321e 100644 --- a/src/controller/userActionsController.py +++ b/src/controller/userActionsController.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import object import re import widgetUtils import output diff --git a/src/extra/AudioUploader/audioUploader.py b/src/extra/AudioUploader/audioUploader.py index 824c64c4..7f23fbbd 100644 --- a/src/extra/AudioUploader/audioUploader.py +++ b/src/extra/AudioUploader/audioUploader.py @@ -17,6 +17,9 @@ # ############################################################ from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import str +from builtins import object import widgetUtils from . import wx_ui from . import wx_transfer_dialogs @@ -132,7 +135,7 @@ class audioUploader(object): def _play(self): output.speak(_(u"Playing...")) # try: - self.playing = sound_lib.stream.FileStream(file=unicode(self.file), flags=sound_lib.stream.BASS_UNICODE) + self.playing = sound_lib.stream.FileStream(file=str(self.file), flags=sound_lib.stream.BASS_UNICODE) self.playing.play() self.dialog.set("play", _(u"&Stop")) try: diff --git a/src/extra/AudioUploader/transfer.py b/src/extra/AudioUploader/transfer.py index d5671977..a567f753 100644 --- a/src/extra/AudioUploader/transfer.py +++ b/src/extra/AudioUploader/transfer.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals +from builtins import object +from past.utils import old_div import sys import threading import time @@ -21,7 +25,7 @@ class Upload(object): self.background_thread = None self.transfer_rate = 0 self.local_filename=os.path.basename(self.filename) - if isinstance(self.local_filename, unicode): + if isinstance(self.local_filename, str): self.local_filename=self.local_filename.encode(sys.getfilesystemencoding()) self.fin=open(self.filename, 'rb') self.m = MultipartEncoder(fields={field:(self.local_filename, self.fin, "application/octet-stream")}) @@ -45,10 +49,10 @@ class Upload(object): self.transfer_rate = 0 else: progress["percent"] = int((float(progress["current"]) / progress["total"]) * 100) - self.transfer_rate = progress["current"] / self.elapsed_time() + self.transfer_rate = old_div(progress["current"], self.elapsed_time()) progress["speed"] = '%s/s' % convert_bytes(self.transfer_rate) if self.transfer_rate: - progress["eta"] = (progress["total"] - progress["current"]) / self.transfer_rate + progress["eta"] = old_div((progress["total"] - progress["current"]), self.transfer_rate) else: progress["eta"] = 0 pub.sendMessage("uploading", data=progress) diff --git a/src/extra/AudioUploader/utils.py b/src/extra/AudioUploader/utils.py index 9a20ab26..9ec89156 100644 --- a/src/extra/AudioUploader/utils.py +++ b/src/extra/AudioUploader/utils.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import str def convert_bytes(n): K, M, G, T, P = 1 << 10, 1 << 20, 1 << 30, 1 << 40, 1 << 50 if n >= P: diff --git a/src/extra/AudioUploader/wx_transfer_dialogs.py b/src/extra/AudioUploader/wx_transfer_dialogs.py index c3fc01fa..b70d343e 100644 --- a/src/extra/AudioUploader/wx_transfer_dialogs.py +++ b/src/extra/AudioUploader/wx_transfer_dialogs.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import wx from .utils import * import widgetUtils diff --git a/src/extra/AudioUploader/wx_ui.py b/src/extra/AudioUploader/wx_ui.py index 01d82b58..05fdbcc7 100644 --- a/src/extra/AudioUploader/wx_ui.py +++ b/src/extra/AudioUploader/wx_ui.py @@ -16,6 +16,7 @@ # along with this program. If not, see . # ############################################################ +from __future__ import unicode_literals import wx import widgetUtils import output diff --git a/src/extra/SoundsTutorial/__init__.py b/src/extra/SoundsTutorial/__init__.py index 20d563a6..622e037d 100644 --- a/src/extra/SoundsTutorial/__init__.py +++ b/src/extra/SoundsTutorial/__init__.py @@ -1,2 +1,3 @@ from __future__ import absolute_import +from __future__ import unicode_literals from .soundsTutorial import soundsTutorial diff --git a/src/extra/SoundsTutorial/gtk_ui.py b/src/extra/SoundsTutorial/gtk_ui.py index 4dda6d1e..450498a5 100644 --- a/src/extra/SoundsTutorial/gtk_ui.py +++ b/src/extra/SoundsTutorial/gtk_ui.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals from gi.repository import Gtk import widgetUtils diff --git a/src/extra/SoundsTutorial/reverse_sort.py b/src/extra/SoundsTutorial/reverse_sort.py index 854582a9..1094113e 100644 --- a/src/extra/SoundsTutorial/reverse_sort.py +++ b/src/extra/SoundsTutorial/reverse_sort.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals #Reverse sort, by Bill Dengler for use in TWBlue http://twblue.es def invert_tuples(t): "Invert a list of tuples, so that the 0th element becomes the -1th, and the -1th becomes the 0th." diff --git a/src/extra/SoundsTutorial/soundsTutorial.py b/src/extra/SoundsTutorial/soundsTutorial.py index fd835410..58b23590 100644 --- a/src/extra/SoundsTutorial/soundsTutorial.py +++ b/src/extra/SoundsTutorial/soundsTutorial.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import object import platform import widgetUtils import os diff --git a/src/extra/SoundsTutorial/soundsTutorial_constants.py b/src/extra/SoundsTutorial/soundsTutorial_constants.py index 667e2373..e28612dc 100644 --- a/src/extra/SoundsTutorial/soundsTutorial_constants.py +++ b/src/extra/SoundsTutorial/soundsTutorial_constants.py @@ -1,5 +1,6 @@ #-*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals #-*- coding: utf-8 -*- from . import reverse_sort import application diff --git a/src/extra/SoundsTutorial/wx_ui.py b/src/extra/SoundsTutorial/wx_ui.py index d3480add..ac2b0373 100644 --- a/src/extra/SoundsTutorial/wx_ui.py +++ b/src/extra/SoundsTutorial/wx_ui.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx import widgetUtils diff --git a/src/extra/SpellChecker/__init__.py b/src/extra/SpellChecker/__init__.py index 4edff483..f1eb69de 100644 --- a/src/extra/SpellChecker/__init__.py +++ b/src/extra/SpellChecker/__init__.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import unicode_literals from . import spellchecker import platform if platform.system() == "Windows": diff --git a/src/extra/SpellChecker/spellchecker.py b/src/extra/SpellChecker/spellchecker.py index cb3ce50d..b9d1110d 100644 --- a/src/extra/SpellChecker/spellchecker.py +++ b/src/extra/SpellChecker/spellchecker.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import next +from builtins import object import os import logging from . import wx_ui diff --git a/src/extra/SpellChecker/twitterFilter.py b/src/extra/SpellChecker/twitterFilter.py index f5e308c3..98e53aee 100644 --- a/src/extra/SpellChecker/twitterFilter.py +++ b/src/extra/SpellChecker/twitterFilter.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import re from enchant.tokenize import Filter diff --git a/src/extra/SpellChecker/wx_ui.py b/src/extra/SpellChecker/wx_ui.py index 24911f77..3a13e9f1 100644 --- a/src/extra/SpellChecker/wx_ui.py +++ b/src/extra/SpellChecker/wx_ui.py @@ -16,6 +16,7 @@ # along with this program. If not, see . # ############################################################ +from __future__ import unicode_literals import wx import application diff --git a/src/extra/autocompletionUsers/__init__.py b/src/extra/autocompletionUsers/__init__.py index 888d9511..cceb68cc 100644 --- a/src/extra/autocompletionUsers/__init__.py +++ b/src/extra/autocompletionUsers/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals # -*- coding: utf-8 -*- from . import completion, settings \ No newline at end of file diff --git a/src/extra/autocompletionUsers/completion.py b/src/extra/autocompletionUsers/completion.py index 7dedc525..562788cb 100644 --- a/src/extra/autocompletionUsers/completion.py +++ b/src/extra/autocompletionUsers/completion.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import object import output from . import storage from . import wx_menu diff --git a/src/extra/autocompletionUsers/manage.py b/src/extra/autocompletionUsers/manage.py index a42ef607..ba3a224c 100644 --- a/src/extra/autocompletionUsers/manage.py +++ b/src/extra/autocompletionUsers/manage.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals # -*- coding: utf-8 -*- +from builtins import object from . import storage import widgetUtils from . import wx_manage diff --git a/src/extra/autocompletionUsers/settings.py b/src/extra/autocompletionUsers/settings.py index 5b682850..d14ba62b 100644 --- a/src/extra/autocompletionUsers/settings.py +++ b/src/extra/autocompletionUsers/settings.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals # -*- coding: utf-8 -*- +from builtins import object from . import storage import widgetUtils from . import wx_settings diff --git a/src/extra/autocompletionUsers/storage.py b/src/extra/autocompletionUsers/storage.py index ed9896b2..1bb54a88 100644 --- a/src/extra/autocompletionUsers/storage.py +++ b/src/extra/autocompletionUsers/storage.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import object import sqlite3, paths class storage(object): diff --git a/src/extra/autocompletionUsers/wx_manage.py b/src/extra/autocompletionUsers/wx_manage.py index 789d2419..dad0d0dd 100644 --- a/src/extra/autocompletionUsers/wx_manage.py +++ b/src/extra/autocompletionUsers/wx_manage.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx import widgetUtils from multiplatform_widgets import widgets diff --git a/src/extra/autocompletionUsers/wx_menu.py b/src/extra/autocompletionUsers/wx_menu.py index 55d81458..bf94e7f0 100644 --- a/src/extra/autocompletionUsers/wx_menu.py +++ b/src/extra/autocompletionUsers/wx_menu.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx class menu(wx.Menu): diff --git a/src/extra/autocompletionUsers/wx_settings.py b/src/extra/autocompletionUsers/wx_settings.py index 068decf6..e5520d4f 100644 --- a/src/extra/autocompletionUsers/wx_settings.py +++ b/src/extra/autocompletionUsers/wx_settings.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx import widgetUtils import application diff --git a/src/extra/ocr/OCRSpace.py b/src/extra/ocr/OCRSpace.py index 0b4f4821..ec7e21a1 100644 --- a/src/extra/ocr/OCRSpace.py +++ b/src/extra/ocr/OCRSpace.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- """ original module taken and modified from https://github.com/ctoth/cloudOCR""" +from __future__ import unicode_literals +from builtins import object import requests translatable_langs = [_(u"Detect automatically"), _(u"Danish"), _(u"Dutch"), _(u"English"), _(u"Finnish"), _(u"French"), _(u"German"), _(u"Hungarian"), _(u"Korean"), _(u"Italian"), _(u"Japanese"), _(u"Polish"), _(u"Portuguese"), _(u"Russian"), _(u"Spanish"), _(u"Turkish")] diff --git a/src/extra/ocr/__init__.py b/src/extra/ocr/__init__.py index b39f07d2..48e76b1a 100644 --- a/src/extra/ocr/__init__.py +++ b/src/extra/ocr/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals # -*- coding: utf-8 -*- from . import OCRSpace \ No newline at end of file diff --git a/src/extra/translator/__init__.py b/src/extra/translator/__init__.py index 9296eede..4b1845ea 100644 --- a/src/extra/translator/__init__.py +++ b/src/extra/translator/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals from . import translator import platform if platform.system() == "Windows": diff --git a/src/extra/translator/translator.py b/src/extra/translator/translator.py index 7852741c..f390fbf2 100644 --- a/src/extra/translator/translator.py +++ b/src/extra/translator/translator.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import zip from yandex_translate import YandexTranslate def translate(text="", target="en"): diff --git a/src/extra/translator/wx_ui.py b/src/extra/translator/wx_ui.py index 43b1c684..14d2a88e 100644 --- a/src/extra/translator/wx_ui.py +++ b/src/extra/translator/wx_ui.py @@ -17,6 +17,7 @@ # ############################################################ from __future__ import absolute_import +from __future__ import unicode_literals # -*- coding: utf-8 -*- ############################################################ # Copyright (c) 2013, 2014 Manuel Eduardo Cortéz Vallejo diff --git a/src/fixes/__init__.py b/src/fixes/__init__.py index f0cf76d9..9d2ad8d0 100644 --- a/src/fixes/__init__.py +++ b/src/fixes/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """ This module contains some bugfixes for packages used in TWBlue.""" from __future__ import absolute_import +from __future__ import unicode_literals import sys from . import fix_arrow # A few new locales for Three languages in arrow. from . import fix_libloader # Regenerates comcache properly. diff --git a/src/fixes/fix_arrow.py b/src/fixes/fix_arrow.py index 839a87fe..aef8581e 100644 --- a/src/fixes/fix_arrow.py +++ b/src/fixes/fix_arrow.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals from arrow import locales from arrow.locales import Locale diff --git a/src/fixes/fix_libloader.py b/src/fixes/fix_libloader.py index f084e701..db214ed4 100644 --- a/src/fixes/fix_libloader.py +++ b/src/fixes/fix_libloader.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import logging import win32com import paths diff --git a/src/fixes/fix_requests.py b/src/fixes/fix_requests.py index ec63e741..7a5d66f6 100644 --- a/src/fixes/fix_requests.py +++ b/src/fixes/fix_requests.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals from requests import certs, utils, adapters import paths import config diff --git a/src/fixes/fix_urllib3_warnings.py b/src/fixes/fix_urllib3_warnings.py index 21a7c577..63ca2615 100644 --- a/src/fixes/fix_urllib3_warnings.py +++ b/src/fixes/fix_urllib3_warnings.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() from requests.packages import urllib3 from requests.packages.urllib3 import fields import six -import urllib +import urllib.request, urllib.parse, urllib.error def fix(): urllib3.disable_warnings() @@ -19,6 +22,6 @@ def patched_format_header_param(name, value): return result if not six.PY3 and isinstance(value, six.text_type): # Python 2: value = value.encode('utf-8') - value=urllib.quote(value, safe='') + value=urllib.parse.quote(value, safe='') value = '%s=%s' % (name, value) return value diff --git a/src/fixes/fix_win32com.py b/src/fixes/fix_win32com.py index 5ae96cb7..a135c90a 100644 --- a/src/fixes/fix_win32com.py +++ b/src/fixes/fix_win32com.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals import win32com.client def fix(): if win32com.client.gencache.is_readonly == True: diff --git a/src/issueReporter/constants.py b/src/issueReporter/constants.py index c228d285..3c254c53 100644 --- a/src/issueReporter/constants.py +++ b/src/issueReporter/constants.py @@ -16,6 +16,7 @@ # along with this program. If not, see . # ############################################################ +from __future__ import unicode_literals categories = ["General"] reproducibilities = ["always", "sometimes", "random", "have not tried", "unable to duplicate"] severities = ["block", "crash", "major", "minor", "tweak", "text", "trivial", "feature"] diff --git a/src/issueReporter/issueReporter.py b/src/issueReporter/issueReporter.py index 21a1b809..a4d074eb 100644 --- a/src/issueReporter/issueReporter.py +++ b/src/issueReporter/issueReporter.py @@ -16,6 +16,8 @@ # along with this program. If not, see . # ############################################################ +from __future__ import unicode_literals +from builtins import object import keys import wx import wx_ui diff --git a/src/issueReporter/wx_ui.py b/src/issueReporter/wx_ui.py index 3d2855e6..46ee715c 100644 --- a/src/issueReporter/wx_ui.py +++ b/src/issueReporter/wx_ui.py @@ -16,6 +16,7 @@ # along with this program. If not, see . # ############################################################ +from __future__ import unicode_literals import wx import widgetUtils import application diff --git a/src/keyboard_handler/__init__.py b/src/keyboard_handler/__init__.py index 144513d0..37e27619 100644 --- a/src/keyboard_handler/__init__.py +++ b/src/keyboard_handler/__init__.py @@ -1,3 +1,3 @@ -from main import KeyboardHandler, KeyboardHandlerError -#from wx_handler import WXKeyboardHandler -__all__ = ["KeyboardHandler", "KeyboardHandlerError", "WXKeyboardHandler", "WXPanelKeyboardHandler"] +from __future__ import absolute_import +from .main import KeyboardHandler, KeyboardHandlerError +__all__ = ["KeyboardHandler", "KeyboardHandlerError", ] diff --git a/src/keyboard_handler/global_handler.py b/src/keyboard_handler/global_handler.py index 2e798f71..d07062ac 100644 --- a/src/keyboard_handler/global_handler.py +++ b/src/keyboard_handler/global_handler.py @@ -1,7 +1,8 @@ +from __future__ import absolute_import import platform if platform.system() == 'Linux': - from linux import LinuxKeyboardHandler as GlobalKeyboardHandler -elif platform.system() == 'Windows': - from wx_handler import WXKeyboardHandler as GlobalKeyboardHandler -elif platform.system() == 'Darwin': - from osx import OSXKeyboardHandler as GlobalKeyboardHandler + from .linux import LinuxKeyboardHandler as GlobalKeyboardHandler +else: + from .wx_handler import WXKeyboardHandler as GlobalKeyboardHandler +#elif platform.system() == 'Darwin': + #from osx import OSXKeyboardHandler as GlobalKeyboardHandler diff --git a/src/keyboard_handler/key_constants.py b/src/keyboard_handler/key_constants.py new file mode 100644 index 00000000..c40491d4 --- /dev/null +++ b/src/keyboard_handler/key_constants.py @@ -0,0 +1,128 @@ +keys = { + 'accept': 30, + 'add': 107, + 'apps': 93, + 'attn': 246, + 'back': 8, + 'browser_back': 166, + 'browser_forward': 167, + 'cancel': 3, + 'capital': 20, + 'clear': 12, + 'control': 17, + 'convert': 28, + 'crsel': 247, + 'decimal': 110, + 'delete': 46, + 'divide': 111, + 'down': 40, + 'end': 35, + 'ereof': 249, + 'escape': 27, + 'execute': 43, + 'exsel': 248, + 'f1': 112, + 'f10': 121, + 'f11': 122, + 'f12': 123, + 'f13': 124, + 'f14': 125, + 'f15': 126, + 'f16': 127, + 'f17': 128, + 'f18': 129, + 'f19': 130, + 'f2': 113, + 'f20': 131, + 'f21': 132, + 'f22': 133, + 'f23': 134, + 'f24': 135, + 'f3': 114, + 'f4': 115, + 'f5': 116, + 'f6': 117, + 'f7': 118, + 'f8': 119, + 'f9': 120, + 'final': 24, + 'hangeul': 21, + 'hangul': 21, + 'hanja': 25, + 'help': 47, + 'home': 36, + 'insert': 45, + 'junja': 23, + 'kana': 21, + 'kanji': 25, + 'lbutton': 1, + 'lcontrol': 162, + 'left': 37, + 'lmenu': 164, + 'lshift': 160, + 'lwin': 91, + 'mbutton': 4, + 'media_next_track': 176, + 'media_play_pause': 179, + 'media_prev_track': 177, + 'menu': 18, + 'modechange': 31, + 'multiply': 106, + 'next': 34, + 'noname': 252, + 'nonconvert': 29, + 'numlock': 144, + 'numpad0': 96, + 'numpad1': 97, + 'numpad2': 98, + 'numpad3': 99, + 'numpad4': 100, + 'numpad5': 101, + 'numpad6': 102, + 'numpad7': 103, + 'numpad8': 104, + 'numpad9': 105, + 'oem_clear': 254, + 'pa1': 253, + 'pagedown': 34, + 'pageup': 33, + 'pause': 19, + 'play': 250, + 'print': 42, + 'prior': 33, + 'processkey': 229, + 'rbutton': 2, + 'rcontrol': 163, + 'return': 13, + 'right': 39, + 'rmenu': 165, + 'rshift': 161, + 'rwin': 92, + 'scroll': 145, + 'select': 41, + 'separator': 108, + 'shift': 16, + 'snapshot': 44, + 'space': 32, + 'subtract': 109, + 'tab': 9, + 'up': 38, + 'volume_down': 174, + 'volume_mute': 173, + 'volume_up': 175, + 'xbutton1': 5, + 'xbutton2': 6, + 'zoom': 251, + '/': 191, + ';': 218, + '[': 219, + '\\': 220, + ']': 221, + '\'': 222, + '=': 187, + '-': 189, + ';': 186, +} + +modifiers = {'alt': 1, 'control': 2, 'shift': 4, 'win': 8} + diff --git a/src/keyboard_handler/main.py b/src/keyboard_handler/main.py index ea040f73..000ee65d 100644 --- a/src/keyboard_handler/main.py +++ b/src/keyboard_handler/main.py @@ -18,17 +18,17 @@ class KeyboardHandler(object): def register_key (self, key, function): if key in self.active_keys: - raise KeyboardHandlerError, "Key %s is already registered to a function" % key + raise KeyboardHandlerError("Key %s is already registered to a function" % key) if not callable(function): - raise TypeError, "Must provide a callable to be invoked upon keypress" + raise TypeError("Must provide a callable to be invoked upon keypress") self.active_keys[key] = function def unregister_key (self, key, function): try: if self.active_keys[key] != function: - raise KeyboardHandlerError, "key %s is not registered to that function" % key + raise KeyboardHandlerError("key %s is not registered to that function" % key) except KeyError: - raise KeyboardHandlerError, "Key %s not currently registered" + raise KeyboardHandlerError("Key %s not currently registered" % key) del(self.active_keys[key]) def unregister_all_keys(self): diff --git a/src/keyboard_handler/wx_handler.py b/src/keyboard_handler/wx_handler.py index 55c24208..80609116 100644 --- a/src/keyboard_handler/wx_handler.py +++ b/src/keyboard_handler/wx_handler.py @@ -1,11 +1,14 @@ +from __future__ import absolute_import import functools +import logging +logger = logging.getLogger("keyboard_handler") import wx -import platform -from main import KeyboardHandler + +from .main import KeyboardHandler, KeyboardHandlerError +from . import key_constants __all__ = ['WXKeyboardHandler', 'WXControlKeyboardHandler'] - def call_after(func): def wrapper(*args, **kwargs): wx.CallAfter(func, *args, **kwargs) @@ -34,6 +37,7 @@ class BaseWXKeyboardHandler(KeyboardHandler): return (mods, keystroke[-1]) def keycode_from_key(self, key): + result = None if key in self.replacement_mods: result = self.replacement_mods[key] elif key in self.replacement_keys: @@ -42,33 +46,40 @@ class BaseWXKeyboardHandler(KeyboardHandler): result -= 277 elif len(key) == 1: result = ord(key.upper()) - print "result: ", result + if result is None: + raise KeyboardHandlerError("Could not translate key %r into a valid keycode." % key) return result + +class WXKeyboardHandler(BaseWXKeyboardHandler): -#try: -if platform.system() == "Windows": - from windows import WindowsKeyboardHandler as keyboard_handler -elif platform.system() == "Linux": - from linux import LinuxKeyboardHandler as keyboard_handler -elif platform.system() == "Darwin": - from osx import OSXKeyboardHandler as keyboard_handler - -class WXKeyboardHandler(keyboard_handler): def __init__ (self, parent, *args, **kwargs): super(WXKeyboardHandler, self).__init__(*args, **kwargs) self.parent = parent self.key_ids = {} + self.replacement_keys = key_constants.keys + self.replacement_mods = key_constants.modifiers @call_after def register_key(self, key, function): super(WXKeyboardHandler, self).register_key(key, function) key_id = wx.NewId() parsed = self.parse_key(key) - self.parent.RegisterHotKey(key_id, *parsed) + res = self.parent.RegisterHotKey(key_id, *parsed) + if not res: + logger.warn("Failed to register hotkey: %s for function %r", key, function) self.parent.Bind(wx.EVT_HOTKEY, lambda evt: self.process_key(evt, key_id), id=key_id) self.key_ids[key] = key_id + return res + + def parse_key (self, keystroke, separator="+"): + keystroke = str(keystroke) #We don't want unicode + keystroke = [self.keycode_from_key(i) for i in keystroke.split(separator)] + mods = 0 + for i in keystroke[:-1]: + mods = mods | i #or everything together + return (mods, keystroke[-1]) @call_after def unregister_key (self, key, function): diff --git a/src/keys/__init__.py b/src/keys/__init__.py index af724223..aa08bfc8 100644 --- a/src/keys/__init__.py +++ b/src/keys/__init__.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals from builtins import object +import os import application import platform -import exceptions from ctypes import c_char_p from libloader import load_library import paths @@ -13,9 +14,9 @@ import paths # lib = load_library("snapshot_api_keys64", x64_path=paths.app_path("keys/lib")) #else: if platform.architecture()[0][:2] == "32": - lib = load_library("stable_api_keys32", x86_path=paths.app_path("keys/lib")) + lib = load_library("stable_api_keys32", x86_path=os.path.join(paths.app_path(), "keys", "lib")) else: - lib = load_library("stable_api_keys64", x64_path=paths.app_path("keys/lib")) + lib = load_library("stable_api_keys64", x64_path=os.path.join(paths.app_path(), "keys", "lib")) # import linuxKeys # lib = linuxKeys diff --git a/src/keys/linuxKeys.py b/src/keys/linuxKeys.py index f0212ddc..0baef390 100644 --- a/src/keys/linuxKeys.py +++ b/src/keys/linuxKeys.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals def get_api_key(): return "8pDLbyOW3saYnvSZ4uLFg\0" diff --git a/src/keystrokeEditor/__init__.py b/src/keystrokeEditor/__init__.py index c76ba54e..b8cf7680 100644 --- a/src/keystrokeEditor/__init__.py +++ b/src/keystrokeEditor/__init__.py @@ -1,2 +1,3 @@ from __future__ import absolute_import +from __future__ import unicode_literals from .keystrokeEditor import KeystrokeEditor \ No newline at end of file diff --git a/src/keystrokeEditor/constants.py b/src/keystrokeEditor/constants.py index 7474d2cd..47cc0e97 100644 --- a/src/keystrokeEditor/constants.py +++ b/src/keystrokeEditor/constants.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals actions = { "up": _(u"Go up in the current buffer"), "down": _(u"Go down in the current buffer"), diff --git a/src/keystrokeEditor/keystrokeEditor.py b/src/keystrokeEditor/keystrokeEditor.py index c56b4cd0..215ed404 100644 --- a/src/keystrokeEditor/keystrokeEditor.py +++ b/src/keystrokeEditor/keystrokeEditor.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import object import widgetUtils import config from . import wx_ui diff --git a/src/keystrokeEditor/wx_ui.py b/src/keystrokeEditor/wx_ui.py index dbd922d1..7fd7c5c0 100644 --- a/src/keystrokeEditor/wx_ui.py +++ b/src/keystrokeEditor/wx_ui.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx from multiplatform_widgets import widgets from wxUI.dialogs import baseDialog diff --git a/src/languageHandler.py b/src/languageHandler.py index 971d071b..d17aa61b 100644 --- a/src/languageHandler.py +++ b/src/languageHandler.py @@ -1,16 +1,17 @@ -import __builtin__ +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +from builtins import zip +from builtins import str +import builtins import os import sys import ctypes import locale -# add mapping for Serbian (latin) language -locale.windows_locale[9242]='sr_RS' import gettext import paths import platform - -# A fix for the mac locales -#if platform.system() == 'Darwin': +import application #a few Windows locale constants LOCALE_SLANGUAGE=0x2 @@ -29,12 +30,12 @@ def localeNameToWindowsLCID(localeName): func_LocaleNameToLCID=getattr(ctypes.windll.kernel32,'LocaleNameToLCID',None) if func_LocaleNameToLCID is not None: localeName=localeName.replace('_','-') - LCID=func_LocaleNameToLCID(unicode(localeName),0) + LCID=func_LocaleNameToLCID(str(localeName),0) else: #Windows doesn't have this functionality, manually search Python's windows_locale dictionary for the LCID localeName=locale.normalize(localeName) if '.' in localeName: localeName=localeName.split('.')[0] - LCList=[x[0] for x in locale.windows_locale.iteritems() if x[1]==localeName] + LCList=[x[0] for x in locale.windows_locale.items() if x[1]==localeName] if len(LCList)>0: LCID=LCList[0] else: @@ -72,7 +73,6 @@ def getLanguageDescription(language): "ne":pgettext("languageName","Nepali"), "sr":pgettext("languageName","Serbian (Latin)"), "ja":pgettext("languageName","Japanese"), - "ro":pgettext("languageName","Romanian"), }.get(language,None) return desc @@ -82,7 +82,7 @@ def getAvailableLanguages(): """ #Make a list of all the locales found in NVDA's locale dir l=[x for x in os.listdir(paths.locale_path()) if not x.startswith('.')] - l=[x for x in l if os.path.isfile(paths.locale_path('%s/LC_MESSAGES/twblue.mo' % x))] + l=[x for x in l if os.path.isfile(os.path.join(paths.locale_path(), '%s/LC_MESSAGES/%s.po' % (x, application.short_name)))] #Make sure that en (english) is in the list as it may not have any locale files, but is default if 'en' not in l: l.append('en') @@ -98,7 +98,7 @@ def getAvailableLanguages(): # Translators: the label for the Windows default NVDA interface language. d.append(_("User default")) #return a zipped up version of both the lists (a list with tuples of locale,label) - return zip(l,d) + return list(zip(l,d)) def makePgettext(translations): """Obtaina pgettext function for use with a gettext translations instance. @@ -108,15 +108,15 @@ def makePgettext(translations): """ if isinstance(translations, gettext.GNUTranslations): def pgettext(context, message): - message = unicode(message) + message = str(message) try: # Look up the message with its context. - return translations._catalog[u"%s\x04%s" % (context, message)] + return translations._catalog["%s\x04%s" % (context, message)] except KeyError: return message else: def pgettext(context, message): - return unicode(message) + return str(message) return pgettext def setLanguage(lang): @@ -132,7 +132,7 @@ def setLanguage(lang): localeName = Foundation.NSLocale.currentLocale().identifier() elif system == "Linux": localeName = locale.getdefaultlocale()[0] - trans=gettext.translation('twblue', localedir=paths.locale_path(), languages=[localeName]) + trans=gettext.translation(application.short_name, localedir=paths.locale_path(), languages=[localeName]) curLang=localeName # else: # localeName=locale.getdefaultlocale()[0] @@ -140,7 +140,7 @@ def setLanguage(lang): # curLang=localeName else: - trans=gettext.translation("twblue", localedir=paths.locale_path(), languages=[lang]) + trans=gettext.translation(application.short_name, localedir=paths.locale_path(), languages=[lang]) curLang=lang localeChanged=False #Try setting Python's locale to lang @@ -164,9 +164,12 @@ def setLanguage(lang): LCID=localeNameToWindowsLCID(lang) ctypes.windll.kernel32.SetThreadLocale(LCID) except IOError: - trans=gettext.translation("twblue",fallback=True) + trans=gettext.translation(application.short_name, fallback=True) curLang="en" - trans.install(unicode=True) + if sys.version[0] == "3": + trans.install() + else: + trans.install(unicode=True) # Install our pgettext function. # __builtin__.__dict__["pgettext"] = makePgettext(trans) @@ -192,8 +195,7 @@ def langToWindowsLocale(lang): languages = {"en": "eng", "ar": "ara", "ca": "cat", - "da": "dan", - "de": "deu", +"de": "deu", "es": "esp", "fi": "fin", "fr": "fre_FRA", @@ -205,7 +207,6 @@ def langToWindowsLocale(lang): "ja": "jpn", "pl": "plk", "pt": "ptb", - "ro": "rom", "ru": "rus", "tr": "trk", "sr": "eng", diff --git a/src/logger.py b/src/logger.py index 4820a28e..7fd0d601 100644 --- a/src/logger.py +++ b/src/logger.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import os import logging from logging.handlers import RotatingFileHandler import paths @@ -7,33 +8,30 @@ import sys APP_LOG_FILE = 'debug.log' ERROR_LOG_FILE = "error.log" MESSAGE_FORMAT = "%(asctime)s %(name)s %(levelname)s: %(message)s" -DATE_FORMAT = u"%d/%m/%Y %H:%M:%S" +DATE_FORMAT = "%d/%m/%Y %H:%M:%S" -formatter = logging.Formatter(MESSAGE_FORMAT.decode("utf-8"), datefmt=DATE_FORMAT) +formatter = logging.Formatter(MESSAGE_FORMAT, datefmt=DATE_FORMAT) requests_log = logging.getLogger("requests") requests_log.setLevel(logging.WARNING) -oauthlib_log = logging.getLogger("oauthlib") -oauthlib_log.setLevel(logging.WARNING) -requests_oauthlib_log = logging.getLogger("requests_oauthlib") -requests_oauthlib_log.setLevel(logging.WARNING) -suds_log = logging.getLogger("suds") -suds_log.setLevel(logging.WARNING) -server_log = logging.getLogger("BaseHTTPServer") -server_log.setLevel(logging.WARNING) - +urllib3 = logging.getLogger("urllib3") +urllib3.setLevel(logging.WARNING) +requests_oauthlib = logging.getLogger("requests_oauthlib") +requests_oauthlib.setLevel(logging.WARNING) +oauthlib = logging.getLogger("oauthlib") +oauthlib.setLevel(logging.WARNING) logger = logging.getLogger() logger.setLevel(logging.DEBUG) #handlers -app_handler = RotatingFileHandler(paths.logs_path(APP_LOG_FILE), mode="w") +app_handler = RotatingFileHandler(os.path.join(paths.logs_path(), APP_LOG_FILE), mode="w", encoding="utf-8") app_handler.setFormatter(formatter) app_handler.setLevel(logging.DEBUG) logger.addHandler(app_handler) -error_handler = logging.FileHandler(paths.logs_path(ERROR_LOG_FILE), mode="w") +error_handler = logging.FileHandler(os.path.join(paths.logs_path(), ERROR_LOG_FILE), mode="w", encoding="utf-8") error_handler.setFormatter(formatter) error_handler.setLevel(logging.ERROR) logger.addHandler(error_handler) diff --git a/src/main.py b/src/main.py index 85cd97f4..aced9034 100644 --- a/src/main.py +++ b/src/main.py @@ -17,7 +17,8 @@ if system == "Windows": import languageHandler import paths #check if TWBlue is installed (Windows only) -if os.path.exists(paths.app_path(u"Uninstall.exe")): +# ToDo: Remove this soon as this is done already when importing the paths module. +if os.path.exists(os.path.join(paths.app_path(), "Uninstall.exe")): paths.mode="installed" import commandline import config @@ -37,8 +38,8 @@ if system == "Windows": stderr_temp=sys.stderr #if it's a binary version if hasattr(sys, 'frozen'): - sys.stderr = open(paths.logs_path("stderr.log"), 'w') - sys.stdout = open(paths.logs_path("stdout.log"), 'w') + sys.stderr = open(os.path.join(paths.logs_path(), "stderr.log"), 'w') + sys.stdout = open(os.path.join(paths.logs_path(), "stdout.log"), 'w') else: sys.stdout=stdout sys.stderr=stderr @@ -47,8 +48,8 @@ if system == "Windows": arch="x86" if platform.architecture()[0][:2] == "64": arch="x64" - os.environ['PYTHON_VLC_MODULE_PATH']=str(os.path.abspath(paths.app_path("..", "windows-dependencies", arch))) - os.environ['PYTHON_VLC_LIB_PATH']=str(os.path.abspath(paths.app_path("..", "windows-dependencies", arch, "libvlc.dll"))) + os.environ['PYTHON_VLC_MODULE_PATH']=os.path.abspath(os.path.join(paths.app_path(), "..", "windows-dependencies", arch)) + os.environ['PYTHON_VLC_LIB_PATH']=os.path.abspath(os.path.join(paths.app_path(), "..", "windows-dependencies", arch, "libvlc.dll")) #the final log files have been opened succesfully, let's close the temporary files stdout_temp.close() stderr_temp.close() @@ -72,6 +73,7 @@ def setup(): fixes.setup() output.setup() keys.setup() + from controller import settings from controller import mainController from sessionmanager import sessionManager app = widgetUtils.mainLoopObject() diff --git a/src/multiplatform_widgets/__init__.py b/src/multiplatform_widgets/__init__.py index b282b4e9..fe9bf3f2 100644 --- a/src/multiplatform_widgets/__init__.py +++ b/src/multiplatform_widgets/__init__.py @@ -1,2 +1,3 @@ from __future__ import absolute_import +from __future__ import unicode_literals from . import widgets \ No newline at end of file diff --git a/src/multiplatform_widgets/widgets.py b/src/multiplatform_widgets/widgets.py index 10c29166..5693c245 100644 --- a/src/multiplatform_widgets/widgets.py +++ b/src/multiplatform_widgets/widgets.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import range +from builtins import object import wx import platform import logging @@ -27,7 +30,7 @@ class list(object): def create_list(self, parent): if self.system == "Windows": self.list = wx.ListCtrl(parent, -1, **self.listArguments) - for i in xrange(0, len(self.columns)): + for i in range(0, len(self.columns)): self.list.InsertColumn(i, u"%s" % (self.columns[i])) else: self.list = wx.ListBox(parent, -1, choices=[]) diff --git a/src/mysc/autostart.py b/src/mysc/autostart.py index 9447540f..01a555f2 100644 --- a/src/mysc/autostart.py +++ b/src/mysc/autostart.py @@ -1,19 +1,23 @@ -import _winreg +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +from builtins import str +import winreg import os import sys from platform_utils import paths -RUN_REGKEY = ur"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" +RUN_REGKEY = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" def is_installed(app_subkey): """Checks if the currently running copy is installed or portable variant. Requires the name of the application subkey found under the uninstall section in Windows registry.""" try: - key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s" % app_subkey) - inst_dir = _winreg.QueryValueEx(key,"InstallLocation")[0] + key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s" % app_subkey) + inst_dir = winreg.QueryValueEx(key,"InstallLocation")[0] except WindowsError: return False - _winreg.CloseKey(key) + winreg.CloseKey(key) try: return os.stat(inst_dir) == os.stat(paths.app_path()) except WindowsError: @@ -23,19 +27,18 @@ def getAutoStart(app_name): """Queries if the automatic startup should be set for the application or not, depending on it's current state.""" try: - key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, RUN_REGKEY) - val = _winreg.QueryValueEx(key, unicode(app_name))[0] + key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, RUN_REGKEY) + val = winreg.QueryValueEx(key, str(app_name))[0] return os.stat(val) == os.stat(sys.argv[0]) except (WindowsError, OSError): return False def setAutoStart(app_name, enable=True): """Configures automatic startup for the application, if the enable argument is set to True. If set to False, deletes the application AutoStart value.""" - print paths.get_executable() if getAutoStart(app_name) == enable: return - key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, RUN_REGKEY, 0, _winreg.KEY_WRITE) + key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, RUN_REGKEY, 0, winreg.KEY_WRITE) if enable: - _winreg.SetValueEx(key, unicode(app_name), None, _winreg.REG_SZ, paths.get_executable()) + winreg.SetValueEx(key, str(app_name), None, winreg.REG_SZ, paths.get_executable()) else: - _winreg.DeleteValue(key, unicode(app_name)) + winreg.DeleteValue(key, str(app_name)) diff --git a/src/mysc/localization.py b/src/mysc/localization.py index c05b417f..01a7357d 100644 --- a/src/mysc/localization.py +++ b/src/mysc/localization.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals import os import languageHandler import logging diff --git a/src/mysc/repeating_timer.py b/src/mysc/repeating_timer.py index 0f1bd5bc..41b4a5c5 100644 --- a/src/mysc/repeating_timer.py +++ b/src/mysc/repeating_timer.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals import threading import logging log = logging.getLogger("mysc.repeating_timer") diff --git a/src/mysc/restart.py b/src/mysc/restart.py index c6db1e11..400ef530 100644 --- a/src/mysc/restart.py +++ b/src/mysc/restart.py @@ -1,4 +1,5 @@ # -*- coding: cp1252 +from __future__ import unicode_literals import sys, os def restart_program(): diff --git a/src/mysc/thread_utils.py b/src/mysc/thread_utils.py index 40c633b2..932f53c9 100644 --- a/src/mysc/thread_utils.py +++ b/src/mysc/thread_utils.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() import logging log = logging.getLogger("mysc.thread_utils") import threading diff --git a/src/notifier/__init__.py b/src/notifier/__init__.py index 5eaab0ec..6283342c 100644 --- a/src/notifier/__init__.py +++ b/src/notifier/__init__.py @@ -2,6 +2,7 @@ """ A cross platform notification system. Under Linux, the wx.NotificationMessage does not show a notification on the taskbar, so we decided to use dbus for showing notifications for linux and wx for Windows.""" from __future__ import absolute_import +from __future__ import unicode_literals import platform notify = None diff --git a/src/notifier/linux.py b/src/notifier/linux.py index 42da5f21..18d78203 100644 --- a/src/notifier/linux.py +++ b/src/notifier/linux.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import object import dbus import application diff --git a/src/notifier/windows.py b/src/notifier/windows.py index 5e1dd320..af7b22cc 100644 --- a/src/notifier/windows.py +++ b/src/notifier/windows.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import object import wx class notification(object): diff --git a/src/paths.py b/src/paths.py index 84f3ef13..61f454b2 100644 --- a/src/paths.py +++ b/src/paths.py @@ -1,85 +1,67 @@ # -*- coding: utf-8 -*- +import sys import platform import os -import sys -import logging +import glob from platform_utils import paths as paths_ -from functools import wraps - mode = "portable" directory = None +fsencoding = sys.getfilesystemencoding() -log = logging.getLogger("paths") +if len(glob.glob("Uninstall.exe")) > 0: # installed copy + mode= "installed" -def merge_paths(func): - @wraps(func) - def merge_paths_wrapper(*a): - return unicode(os.path.join(func(), *a)) - return merge_paths_wrapper - -@merge_paths def app_path(): - return paths_.app_path() + return paths_.app_path() -@merge_paths def config_path(): - global mode, directory - if mode == "portable": - if directory != None: path = os.path.join(directory, "config") - elif directory == None: path = app_path(u"config") - elif mode == "installed": - path = data_path(u"config") - if not os.path.exists(path): - log.debug("%s path does not exist, creating..." % (path,)) - os.mkdir(path) - return path + global mode, directory + if mode == "portable": + if directory != None: path = os.path.join(directory, "config") + elif directory == None: path = os.path.join(app_path(), "config") + elif mode == "installed": + path = os.path.join(data_path(), "config") + if not os.path.exists(path): +# log.debug("%s path does not exist, creating..." % (path,)) + os.mkdir(path) + return path -@merge_paths def logs_path(): - global mode, directory - if mode == "portable": - if directory != None: path = os.path.join(directory, "logs") - elif directory == None: path = app_path(u"logs") - elif mode == "installed": - path = data_path(u"logs") - if not os.path.exists(path): - log.debug("%s path does not exist, creating..." % (path,)) - os.mkdir(path) - return path + global mode, directory + if mode == "portable": + if directory != None: path = os.path.join(directory, "logs") + elif directory == None: path = os.path.join(app_path(), "logs") + elif mode == "installed": + path = os.path.join(data_path(), "logs") + if not os.path.exists(path): +# log.debug("%s path does not exist, creating..." % (path,)) + os.mkdir(path) + return path -@merge_paths -def data_path(app_name='TW blue'): -# if platform.system() == "Windows": -# import shlobj -# data_path = os.path.join(shlobj.SHGetFolderPath(0, shlobj.CSIDL_APPDATA), app_name) -# else: - if platform.system() == "Windows": - import winpaths - data_path = os.path.join(winpaths.get_appdata(), app_name) - else: - data_path = os.path.join(os.environ['HOME'], ".%s" % app_name) - if not os.path.exists(data_path): - os.mkdir(data_path) - return data_path +def data_path(app_name='socializer'): + if platform.system() == "Windows": + data_path = os.path.join(os.getenv("AppData"), app_name) + else: + data_path = os.path.join(os.environ['HOME'], ".%s" % app_name) + if not os.path.exists(data_path): + os.mkdir(data_path) + return data_path -@merge_paths def locale_path(): - return app_path(u"locales") + return os.path.join(app_path(), "locales") -@merge_paths def sound_path(): - return app_path(u"sounds") + return os.path.join(app_path(), "sounds") -@merge_paths def com_path(): - global mode, directory - if mode == "portable": - if directory != None: path = os.path.join(directory, "com_cache") - elif directory == None: path = app_path(u"com_cache") - elif mode == "installed": - path = data_path(u"com_cache") - if not os.path.exists(path): - log.debug("%s path does not exist, creating..." % (path,)) - os.mkdir(path) - return path + global mode, directory + if mode == "portable": + if directory != None: path = os.path.join(directory, "com_cache") + elif directory == None: path = os.path.join(app_path(), "com_cache") + elif mode == "installed": + path = os.path.join(data_path(), "com_cache") + if not os.path.exists(path): +# log.debug("%s path does not exist, creating..." % (path,)) + os.mkdir(path) + return path diff --git a/src/sessionmanager/__init__.py b/src/sessionmanager/__init__.py index e89280a3..77b12468 100644 --- a/src/sessionmanager/__init__.py +++ b/src/sessionmanager/__init__.py @@ -6,4 +6,5 @@ Contents of this package: session_exceptions: Some useful exceptions when there is an error. manager: Handles multiple sessions, setting the configuration files and check if the session is valid. Part of the model. session: Creates a twitter session for an user. The other part of the model. -""" \ No newline at end of file +""" +from __future__ import unicode_literals \ No newline at end of file diff --git a/src/sessionmanager/gtkUI.py b/src/sessionmanager/gtkUI.py index b6a709e6..aa0b4a18 100644 --- a/src/sessionmanager/gtkUI.py +++ b/src/sessionmanager/gtkUI.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals from gi.repository import Gtk import widgetUtils diff --git a/src/sessionmanager/manager.py b/src/sessionmanager/manager.py index ffdc0e18..847db4e0 100644 --- a/src/sessionmanager/manager.py +++ b/src/sessionmanager/manager.py @@ -1,5 +1,7 @@ # -*- coding: cp1252 -*- #from config_utils import Configuration, ConfigurationResetException +from __future__ import unicode_literals +from builtins import object import config import paths import os diff --git a/src/sessionmanager/sessionManager.py b/src/sessionmanager/sessionManager.py index a3cacd5c..91d26beb 100644 --- a/src/sessionmanager/sessionManager.py +++ b/src/sessionmanager/sessionManager.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import str +from builtins import object import shutil import widgetUtils import platform @@ -43,14 +46,14 @@ class sessionManagerController(object): log.debug("Filling the sessions list.") self.sessions = [] for i in os.listdir(paths.config_path()): - if os.path.isdir(paths.config_path(i)) and i not in reserved_dirs: + if os.path.isdir(os.path.join(paths.config_path(), i)) and i not in reserved_dirs: log.debug("Adding session %s" % (i,)) - strconfig = "%s/session.conf" % (paths.config_path(i)) + strconfig = "%s/session.conf" % (os.path.join(paths.config_path(), i)) config_test = config_utils.load_config(strconfig) if len(config_test) == 0: try: log.debug("Deleting session %s" % (i,)) - shutil.rmtree(paths.config_path(i)) + shutil.rmtree(os.path.join(paths.config_path(), i)) continue except: output.speak("An exception was raised while attempting to clean malformed session data. See the error log for details. If this message persists, contact the developers.",True) @@ -63,7 +66,7 @@ class sessionManagerController(object): else: try: log.debug("Deleting session %s" % (i,)) - shutil.rmtree(paths.config_path(i)) + shutil.rmtree(os.path.join(paths.config_path(), i)) except: output.speak("An exception was raised while attempting to clean malformed session data. See the error log for details. If this message persists, contact the developers.",True) os.exception("Exception thrown while removing malformed session") @@ -110,7 +113,7 @@ class sessionManagerController(object): self.view.remove_session(self.view.get_selected()) self.removed_sessions.append(selected_account) self.sessions.remove(selected_account) - shutil.rmtree(path=paths.config_path(selected_account), ignore_errors=True) + shutil.rmtree(path=os.path.join(paths.config_path(), selected_account), ignore_errors=True) def configuration(self, *args, **kwargs): diff --git a/src/sessionmanager/wxUI.py b/src/sessionmanager/wxUI.py index cdf4d1c5..51b7ac9d 100644 --- a/src/sessionmanager/wxUI.py +++ b/src/sessionmanager/wxUI.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx from multiplatform_widgets import widgets import application diff --git a/src/sessions/__init__.py b/src/sessions/__init__.py index ce93af08..4ab464c0 100644 --- a/src/sessions/__init__.py +++ b/src/sessions/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """ this package contains code related to Sessions. In TWBlue, a session module defines everything a social network needs to be used in the program.""" +from __future__ import unicode_literals # let's define a global object for storing sessions across the program. sessions = {} \ No newline at end of file diff --git a/src/sessions/base.py b/src/sessions/base.py index 418f5875..bed2d953 100644 --- a/src/sessions/base.py +++ b/src/sessions/base.py @@ -1,6 +1,10 @@ # -*- coding: utf-8 -*- """ A base class to be derived in possible new sessions for TWBlue and services.""" from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import str +from builtins import object +import os import paths import output import time @@ -53,7 +57,7 @@ class baseSession(object): """ Get settings for a session.""" file_ = "%s/session.conf" % (self.session_id,) log.debug("Creating config file %s" % (file_,)) - self.settings = config_utils.load_config(paths.config_path(file_), paths.app_path("Conf.defaults")) + self.settings = config_utils.load_config(os.path.join(paths.config_path(), file_), os.path.join(paths.app_path(), "Conf.defaults")) self.init_sound() self.deshelve() @@ -71,7 +75,7 @@ class baseSession(object): def shelve(self): """Shelve the database to allow for persistance.""" - shelfname=paths.config_path(str(self.session_id)+"/cache.db") + shelfname=os.path.join(paths.config_path(), str(self.session_id)+"/cache.db") if self.settings["general"]["persist_size"] == 0: if os.path.exists(shelfname): os.remove(shelfname) @@ -79,9 +83,9 @@ class baseSession(object): try: if not os.path.exists(shelfname): output.speak("Generating database, this might take a while.",True) - shelf=shelve.open(paths.config_path(shelfname),'c') - for key,value in self.db.items(): - if type(key) != str and type(key) != unicode: + shelf=shelve.open(os.path.join(paths.config_path(), shelfname),'c') + for key,value in list(self.db.items()): + if type(key) != str and type(key) != str: output.speak("Uh oh, while shelving the database, a key of type " + str(type(key)) + " has been found. It will be converted to type str, but this will cause all sorts of problems on deshelve. Please bring this to the attention of the " + application.name + " developers immediately. More information about the error will be written to the error log.",True) log.error("Uh oh, " + str(key) + " is of type " + str(type(key)) + "!") # Convert unicode objects to UTF-8 strings before shelve these objects. @@ -97,14 +101,14 @@ class baseSession(object): def deshelve(self): """Import a shelved database.""" - shelfname=paths.config_path(str(self.session_id)+"/cache.db") + shelfname=os.path.join(paths.config_path(), str(self.session_id)+"/cache.db") if self.settings["general"]["persist_size"] == 0: if os.path.exists(shelfname): os.remove(shelfname) return try: - shelf=shelve.open(paths.config_path(shelfname),'c') - for key,value in shelf.items(): + shelf=shelve.open(os.path.join(paths.config_path(), shelfname),'c') + for key,value in list(shelf.items()): self.db[key]=value shelf.close() except: diff --git a/src/sessions/session_exceptions.py b/src/sessions/session_exceptions.py index fd7cfc79..e45f843a 100644 --- a/src/sessions/session_exceptions.py +++ b/src/sessions/session_exceptions.py @@ -1,9 +1,9 @@ # -*- coding: cp1252 -*- -import exceptions +from __future__ import unicode_literals -class InvalidSessionError(exceptions.Exception): pass -class NonExistentSessionError(exceptions.Exception): pass -class NotLoggedSessionError(exceptions.BaseException): pass -class NotConfiguredSessionError(exceptions.BaseException): pass -class RequireCredentialsSessionError(exceptions.BaseException): pass -class AlreadyAuthorisedError(exceptions.BaseException): pass \ No newline at end of file +class InvalidSessionError(Exception): pass +class NonExistentSessionError(Exception): pass +class NotLoggedSessionError(BaseException): pass +class NotConfiguredSessionError(BaseException): pass +class RequireCredentialsSessionError(BaseException): pass +class AlreadyAuthorisedError(BaseException): pass \ No newline at end of file diff --git a/src/sessions/twitter/compose.py b/src/sessions/twitter/compose.py index 554f95de..575c57df 100644 --- a/src/sessions/twitter/compose.py +++ b/src/sessions/twitter/compose.py @@ -1,10 +1,16 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +from builtins import str +from builtins import chr +from builtins import range import platform system = platform.system() from . import utils import re -import htmlentitydefs +import html.entities import time import output import languageHandler @@ -22,10 +28,10 @@ def StripChars(s): If we match &blah; and it's not found, &blah; will be returned. if we match #\d+, unichr(digits) will be returned. Else, a unicode string will be returned.""" - if match.group(1).startswith('#'): return unichr(int(match.group(1)[1:])) - replacement = htmlentitydefs.entitydefs.get(match.group(1), "&%s;" % match.group(1)) - return replacement.decode('iso-8859-1') - return unicode(entity_re.sub(matchFunc, s)) + if match.group(1).startswith('#'): return chr(int(match.group(1)[1:])) + replacement = html.entities.entitydefs.get(match.group(1), "&%s;" % match.group(1)) + return replacement + return str(entity_re.sub(matchFunc, s)) chars = "abcdefghijklmnopqrstuvwxyz" diff --git a/src/sessions/twitter/long_tweets/__init__.py b/src/sessions/twitter/long_tweets/__init__.py index 2a1b38e8..20e9c4c4 100644 --- a/src/sessions/twitter/long_tweets/__init__.py +++ b/src/sessions/twitter/long_tweets/__init__.py @@ -1,2 +1,3 @@ # -*- coding: utf-8 -*- -""" this package holds different modules to extract information regarding long tweets. A long tweet contains more than one tweet (such a quoted tweet), or is made via services like twishort.""" \ No newline at end of file +""" this package holds different modules to extract information regarding long tweets. A long tweet contains more than one tweet (such a quoted tweet), or is made via services like twishort.""" +from __future__ import unicode_literals \ No newline at end of file diff --git a/src/sessions/twitter/long_tweets/tweets.py b/src/sessions/twitter/long_tweets/tweets.py index 5445f8fa..44b898a9 100644 --- a/src/sessions/twitter/long_tweets/tweets.py +++ b/src/sessions/twitter/long_tweets/tweets.py @@ -16,6 +16,7 @@ # along with this program. If not, see . # ############################################################ +from __future__ import unicode_literals from sessions.twitter import utils def is_long(tweet): diff --git a/src/sessions/twitter/long_tweets/twishort.py b/src/sessions/twitter/long_tweets/twishort.py index 46481828..076b3871 100644 --- a/src/sessions/twitter/long_tweets/twishort.py +++ b/src/sessions/twitter/long_tweets/twishort.py @@ -17,6 +17,8 @@ # ############################################################ from __future__ import print_function +from __future__ import unicode_literals +from builtins import range import logging import requests import keys diff --git a/src/sessions/twitter/session.py b/src/sessions/twitter/session.py index be1a3fdd..5161a4c8 100644 --- a/src/sessions/twitter/session.py +++ b/src/sessions/twitter/session.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- """ This is the main session needed to access all Twitter Features.""" from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import range import os import time import logging @@ -368,6 +370,7 @@ class Session(base.baseSession): else: return quoted_tweet original_tweet = self.check_long_tweet(original_tweet) + if "full_text" in original_tweet: value = "full_text" elif "message" in original_tweet: @@ -430,7 +433,7 @@ class Session(base.baseSession): self.db["users"][user["id_str"]] = user return user["id_str"] else: - for i in self.db["users"].keys(): + for i in list(self.db["users"].keys()): if self.db["users"][i]["screen_name"] == screen_name: return self.db["users"][i]["id_str"] user = utils.if_user_exists(self.twitter, screen_name) diff --git a/src/sessions/twitter/utils.py b/src/sessions/twitter/utils.py index 2c22ced4..51629c10 100644 --- a/src/sessions/twitter/utils.py +++ b/src/sessions/twitter/utils.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import print_function +from __future__ import unicode_literals +from builtins import str +from builtins import range import url_shortener, re import output from twython import TwythonError diff --git a/src/sessions/twitter/wxUI.py b/src/sessions/twitter/wxUI.py index 9ad4a782..787e6581 100644 --- a/src/sessions/twitter/wxUI.py +++ b/src/sessions/twitter/wxUI.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx class authorisationDialog(wx.Dialog): diff --git a/src/sound.py b/src/sound.py index 68b3f039..859001c7 100644 --- a/src/sound.py +++ b/src/sound.py @@ -36,7 +36,7 @@ def setup(): def recode_audio(filename, quality=4.5): global system - if system == "Windows": subprocess.call(r'"%s" -q %r "%s"' % (paths.app_path('oggenc2.exe'), quality, filename)) + if system == "Windows": subprocess.call(r'"%s" -q %r "%s"' % (os.path.join(paths.app_path(), 'oggenc2.exe'), quality, filename)) def recording(filename): # try: @@ -51,12 +51,12 @@ class soundSystem(object): def check_soundpack(self): """ Checks if the folder where live the current soundpack exists.""" self.soundpack_OK = False - if os.path.exists(paths.sound_path(self.config["current_soundpack"])): - self.path = paths.sound_path(self.config["current_soundpack"]) + if os.path.exists(os.path.join(paths.sound_path(), self.config["current_soundpack"])): + self.path = os.path.join(paths.sound_path(), self.config["current_soundpack"]) self.soundpack_OK = True - elif os.path.exists(paths.sound_path("default")): + elif os.path.exists(os.path.join(paths.sound_path(), "default")): log.error("The soundpack does not exist, using default...") - self.path = paths.sound_path("default") + self.path = os.path.join(paths.sound_path(), "default") self.soundpack_OK = True else: log.error("The current soundpack could not be found and the default soundpack has been deleted, " + application.name + " will not play sounds.") diff --git a/src/update/__init__.py b/src/update/__init__.py index cff6566c..3c5275a4 100644 --- a/src/update/__init__.py +++ b/src/update/__init__.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals import glob import os.path import platform diff --git a/src/update/update.py b/src/update/update.py index f905edc2..ce5cfced 100644 --- a/src/update/update.py +++ b/src/update/update.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals from logging import getLogger logger = getLogger('update') diff --git a/src/update/updater.py b/src/update/updater.py index 5b19da2d..9cc20af2 100644 --- a/src/update/updater.py +++ b/src/update/updater.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import application from . import update import platform diff --git a/src/update/utils.py b/src/update/utils.py index 9a20ab26..9ec89156 100644 --- a/src/update/utils.py +++ b/src/update/utils.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import str def convert_bytes(n): K, M, G, T, P = 1 << 10, 1 << 20, 1 << 30, 1 << 40, 1 << 50 if n >= P: diff --git a/src/update/wxUpdater.py b/src/update/wxUpdater.py index b3f3f34e..437e0a41 100644 --- a/src/update/wxUpdater.py +++ b/src/update/wxUpdater.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals +from builtins import str +from past.utils import old_div import wx import application from . import utils @@ -25,7 +29,7 @@ def progress_callback(total_downloaded, total_size): if total_downloaded == total_size: progress_dialog.Destroy() else: - progress_dialog.Update((total_downloaded*100)/total_size, _(u"Updating... %s of %s") % (str(utils.convert_bytes(total_downloaded)), str(utils.convert_bytes(total_size)))) + progress_dialog.Update(old_div((total_downloaded*100),total_size), _(u"Updating... %s of %s") % (str(utils.convert_bytes(total_downloaded)), str(utils.convert_bytes(total_size)))) def update_finished(): ms = wx.MessageDialog(None, _(u"The update has been downloaded and installed successfully. Press OK to continue."), _(u"Done!")).ShowModal() \ No newline at end of file diff --git a/src/url_shortener/__init__.py b/src/url_shortener/__init__.py index d1819cbc..c543cbfa 100644 --- a/src/url_shortener/__init__.py +++ b/src/url_shortener/__init__.py @@ -1,2 +1,3 @@ -import shorteners +from __future__ import unicode_literals +from . import shorteners from __main__ import * diff --git a/src/url_shortener/__main__.py b/src/url_shortener/__main__.py index 216761d4..8c41d766 100644 --- a/src/url_shortener/__main__.py +++ b/src/url_shortener/__main__.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals from functools import wraps import shorteners diff --git a/src/url_shortener/shorteners/__init__.py b/src/url_shortener/shorteners/__init__.py index fc1bfc14..aa0b763d 100644 --- a/src/url_shortener/shorteners/__init__.py +++ b/src/url_shortener/shorteners/__init__.py @@ -1,10 +1,11 @@ -from url_shortener import URLShortener -from hkcim import HKCShortener -from isgd import IsgdShortener -from onjme import OnjmeShortener -from tinyarrows import TinyArrowsShortener -from tinyurl import TinyurlShortener -from xedcc import XedccShortener -from clckru import ClckruShortener -from acortame import AcortameShortener +from __future__ import unicode_literals +from .url_shortener import URLShortener +from .hkcim import HKCShortener +from . isgd import IsgdShortener +from . onjme import OnjmeShortener +from . tinyarrows import TinyArrowsShortener +from . tinyurl import TinyurlShortener +from . xedcc import XedccShortener +from . clckru import ClckruShortener +from . acortame import AcortameShortener __all__ = ["HKCShortener", "IsgdShortener", "OnjmeShortener", "TinyArrowsShortener", "TinyurlShortener", "XedccShortener", "ClckruShortener", "AcortameShortener"] diff --git a/src/url_shortener/shorteners/acortame.py b/src/url_shortener/shorteners/acortame.py index 4cd274d2..fda92ce5 100644 --- a/src/url_shortener/shorteners/acortame.py +++ b/src/url_shortener/shorteners/acortame.py @@ -1,6 +1,9 @@ -from url_shortener import URLShortener +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +from . url_shortener import URLShortener import requests -import urllib +import urllib.request, urllib.parse, urllib.error class AcortameShortener (URLShortener): def __init__(self, *args, **kwargs): self.name = "acorta.me" @@ -8,7 +11,7 @@ class AcortameShortener (URLShortener): def _shorten (self, url): answer = url - api = requests.get ("https://acorta.me/api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) + api = requests.get ("https://acorta.me/api.php?action=shorturl&format=simple&url=" + urllib.parse.quote(url)) if api.status_code == 200: answer = api.text return answer @@ -21,7 +24,7 @@ class AcortameShortener (URLShortener): #use generic expand method return super(AcortameShortener, self).unshorten(url) answer = url - api = requests.get ("https://acorta.me/api.php?action=expand&format=simple&shorturl=" + urllib.quote(url)) + api = requests.get ("https://acorta.me/api.php?action=expand&format=simple&shorturl=" + urllib.parse.quote(url)) if api.status_code == 200: answer = api.text return answer diff --git a/src/url_shortener/shorteners/clckru.py b/src/url_shortener/shorteners/clckru.py index ba1d8bb2..9d6ce136 100644 --- a/src/url_shortener/shorteners/clckru.py +++ b/src/url_shortener/shorteners/clckru.py @@ -1,6 +1,9 @@ -import urllib +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +import urllib.request, urllib.parse, urllib.error import requests -from url_shortener import URLShortener +from . url_shortener import URLShortener class ClckruShortener (URLShortener): @@ -10,7 +13,7 @@ class ClckruShortener (URLShortener): def _shorten (self, url): answer = url - api = requests.get ("http://clck.ru/--?url=" + urllib.quote(url)) + api = requests.get ("http://clck.ru/--?url=" + urllib.parse.quote(url)) if api.status_code == 200: answer = api.text return answer diff --git a/src/url_shortener/shorteners/hkcim.py b/src/url_shortener/shorteners/hkcim.py index 4c27ec82..43b4d608 100644 --- a/src/url_shortener/shorteners/hkcim.py +++ b/src/url_shortener/shorteners/hkcim.py @@ -1,6 +1,9 @@ -import urllib +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +import urllib.request, urllib.parse, urllib.error import requests -from url_shortener import URLShortener +from . url_shortener import URLShortener class HKCShortener (URLShortener): def __init__ (self, *args, **kwargs): @@ -9,7 +12,7 @@ class HKCShortener (URLShortener): def _shorten (self, url): answer = url - api = requests.get ("http://hkc.im/yourls-api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) + api = requests.get ("http://hkc.im/yourls-api.php?action=shorturl&format=simple&url=" + urllib.parse.quote(url)) if api.status_code == 200: answer = api.text return answer diff --git a/src/url_shortener/shorteners/isgd.py b/src/url_shortener/shorteners/isgd.py index ce46890f..006089de 100644 --- a/src/url_shortener/shorteners/isgd.py +++ b/src/url_shortener/shorteners/isgd.py @@ -1,6 +1,9 @@ -import urllib +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +import urllib.request, urllib.parse, urllib.error import requests -from url_shortener import URLShortener +from . url_shortener import URLShortener class IsgdShortener (URLShortener): @@ -10,7 +13,7 @@ class IsgdShortener (URLShortener): def _shorten (self, url): answer = url - api = requests.get ("http://is.gd/api.php?longurl=" + urllib.quote(url)) + api = requests.get ("http://is.gd/api.php?longurl=" + urllib.parse.quote(url)) if api.status_code == 200: answer = api.text return answer diff --git a/src/url_shortener/shorteners/onjme.py b/src/url_shortener/shorteners/onjme.py index 1a2ec992..c2da3043 100644 --- a/src/url_shortener/shorteners/onjme.py +++ b/src/url_shortener/shorteners/onjme.py @@ -1,6 +1,9 @@ -import urllib +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +import urllib.request, urllib.parse, urllib.error import requests -from url_shortener import URLShortener +from . url_shortener import URLShortener class OnjmeShortener (URLShortener): def __init__ (self, *args, **kwargs): @@ -9,7 +12,7 @@ class OnjmeShortener (URLShortener): def _shorten (self, url): answer = url - api = requests.get ("http://onj.me/yourls-api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) + api = requests.get ("http://onj.me/yourls-api.php?action=shorturl&format=simple&url=" + urllib.parse.quote(url)) if api.status_code == 200: answer = api.text return answer diff --git a/src/url_shortener/shorteners/tinyarrows.py b/src/url_shortener/shorteners/tinyarrows.py index cce2847c..a544d7be 100644 --- a/src/url_shortener/shorteners/tinyarrows.py +++ b/src/url_shortener/shorteners/tinyarrows.py @@ -1,6 +1,9 @@ -import urllib +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +import urllib.request, urllib.parse, urllib.error import requests -from url_shortener import URLShortener +from . url_shortener import URLShortener class TinyArrowsShortener (URLShortener): def __init__ (self, *args, **kwargs): @@ -9,7 +12,7 @@ class TinyArrowsShortener (URLShortener): def _shorten (self, url): answer = url - api = requests.get("http://tinyarro.ws/api-create.php?utfpure=1&url=%s" % urllib.quote(url)) + api = requests.get("http://tinyarro.ws/api-create.php?utfpure=1&url=%s" % urllib.parse.quote(url)) if api.status_code == 200: answer = api.text return answer.decode('UTF-8') diff --git a/src/url_shortener/shorteners/tinyurl.py b/src/url_shortener/shorteners/tinyurl.py index 79a7012e..a762ff4e 100644 --- a/src/url_shortener/shorteners/tinyurl.py +++ b/src/url_shortener/shorteners/tinyurl.py @@ -1,6 +1,9 @@ -from url_shortener import URLShortener +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +from .url_shortener import URLShortener import requests -import urllib +import urllib.request, urllib.parse, urllib.error class TinyurlShortener (URLShortener): def __init__(self, *args, **kwargs): self.name = "TinyURL.com" @@ -8,7 +11,7 @@ class TinyurlShortener (URLShortener): def _shorten (self, url): answer = url - api = requests.get ("http://tinyurl.com/api-create.php?url=" + urllib.quote(url)) + api = requests.get ("http://tinyurl.com/api-create.php?url=" + urllib.parse.quote(url)) if api.status_code == 200: answer = api.text return answer diff --git a/src/url_shortener/shorteners/url_shortener.py b/src/url_shortener/shorteners/url_shortener.py index 3c5fd94e..dad0e355 100644 --- a/src/url_shortener/shorteners/url_shortener.py +++ b/src/url_shortener/shorteners/url_shortener.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals +from builtins import object import requests class URLShortener (object): @@ -22,7 +24,7 @@ class URLShortener (object): def unshorten(self, url): try: r=requests.head(url) - if 'location' in r.headers.keys(): + if 'location' in list(r.headers.keys()): if 'dropbox.com' in r.headers['location']: return handle_dropbox(r.headers['location']) else: diff --git a/src/url_shortener/shorteners/xedcc.py b/src/url_shortener/shorteners/xedcc.py index 6741604e..8b2d2fb5 100644 --- a/src/url_shortener/shorteners/xedcc.py +++ b/src/url_shortener/shorteners/xedcc.py @@ -1,6 +1,9 @@ -import urllib +from __future__ import unicode_literals +from future import standard_library +standard_library.install_aliases() +import urllib.request, urllib.parse, urllib.error import requests -from url_shortener import URLShortener +from . url_shortener import URLShortener class XedccShortener (URLShortener): def __init__ (self, *args, **kwargs): @@ -9,7 +12,7 @@ class XedccShortener (URLShortener): def _shorten (self, url): answer = url - api = requests.get ("http://xed.cc/yourls-api.php?action=shorturl&format=simple&url=" + urllib.quote(url)) + api = requests.get ("http://xed.cc/yourls-api.php?action=shorturl&format=simple&url=" + urllib.parse.quote(url)) if api.status_code == 200: answer = api.text return answer diff --git a/src/widgetUtils/__init__.py b/src/widgetUtils/__init__.py index 0a15dadd..86202b09 100644 --- a/src/widgetUtils/__init__.py +++ b/src/widgetUtils/__init__.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import unicode_literals import platform if platform.system() == "Windows": from .wxUtils import * diff --git a/src/widgetUtils/gtkUtils.py b/src/widgetUtils/gtkUtils.py index 8b19f238..bec88129 100644 --- a/src/widgetUtils/gtkUtils.py +++ b/src/widgetUtils/gtkUtils.py @@ -1,3 +1,6 @@ +from __future__ import unicode_literals +from builtins import range +from builtins import object from gi.repository import Gtk, Gdk from gi.repository import GObject diff --git a/src/widgetUtils/wxUtils.py b/src/widgetUtils/wxUtils.py index 79577960..5a17c5a7 100644 --- a/src/widgetUtils/wxUtils.py +++ b/src/widgetUtils/wxUtils.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals import wx import wx.adv import paths diff --git a/src/wxUI/buffers/__init__.py b/src/wxUI/buffers/__init__.py index d62019d7..cc9de3f1 100644 --- a/src/wxUI/buffers/__init__.py +++ b/src/wxUI/buffers/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals from .base import basePanel from .dm import dmPanel from .events import eventsPanel diff --git a/src/wxUI/buffers/base.py b/src/wxUI/buffers/base.py index 03c74e85..32287f9d 100644 --- a/src/wxUI/buffers/base.py +++ b/src/wxUI/buffers/base.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx from multiplatform_widgets import widgets diff --git a/src/wxUI/buffers/dm.py b/src/wxUI/buffers/dm.py index 774433ed..13ea457f 100644 --- a/src/wxUI/buffers/dm.py +++ b/src/wxUI/buffers/dm.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import wx from .base import basePanel diff --git a/src/wxUI/buffers/events.py b/src/wxUI/buffers/events.py index 929d5c91..aaa9411c 100644 --- a/src/wxUI/buffers/events.py +++ b/src/wxUI/buffers/events.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx from multiplatform_widgets import widgets diff --git a/src/wxUI/buffers/favourites.py b/src/wxUI/buffers/favourites.py index 5dd91a05..cc61e303 100644 --- a/src/wxUI/buffers/favourites.py +++ b/src/wxUI/buffers/favourites.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import wx from .base import basePanel diff --git a/src/wxUI/buffers/lists.py b/src/wxUI/buffers/lists.py index baf6c95a..9c31e95c 100644 --- a/src/wxUI/buffers/lists.py +++ b/src/wxUI/buffers/lists.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import wx from .base import basePanel diff --git a/src/wxUI/buffers/panels.py b/src/wxUI/buffers/panels.py index ce96d1f7..5bd02498 100644 --- a/src/wxUI/buffers/panels.py +++ b/src/wxUI/buffers/panels.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx from multiplatform_widgets import widgets diff --git a/src/wxUI/buffers/people.py b/src/wxUI/buffers/people.py index 47e5cf17..25490be4 100644 --- a/src/wxUI/buffers/people.py +++ b/src/wxUI/buffers/people.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import wx from multiplatform_widgets import widgets from .base import basePanel diff --git a/src/wxUI/buffers/trends.py b/src/wxUI/buffers/trends.py index f055ce69..51058e78 100644 --- a/src/wxUI/buffers/trends.py +++ b/src/wxUI/buffers/trends.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx from multiplatform_widgets import widgets diff --git a/src/wxUI/buffers/tweet_searches.py b/src/wxUI/buffers/tweet_searches.py index ad0c7aa0..6862e482 100644 --- a/src/wxUI/buffers/tweet_searches.py +++ b/src/wxUI/buffers/tweet_searches.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import wx from .base import basePanel diff --git a/src/wxUI/buffers/user_searches.py b/src/wxUI/buffers/user_searches.py index c1ff9745..651c2a55 100644 --- a/src/wxUI/buffers/user_searches.py +++ b/src/wxUI/buffers/user_searches.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import wx from .tweet_searches import searchPanel from multiplatform_widgets import widgets diff --git a/src/wxUI/commonMessageDialogs.py b/src/wxUI/commonMessageDialogs.py index b3d748d5..8288af68 100644 --- a/src/wxUI/commonMessageDialogs.py +++ b/src/wxUI/commonMessageDialogs.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx import application diff --git a/src/wxUI/dialogs/__init__.py b/src/wxUI/dialogs/__init__.py index 3605a2d1..a34f1b2f 100644 --- a/src/wxUI/dialogs/__init__.py +++ b/src/wxUI/dialogs/__init__.py @@ -1,2 +1,3 @@ from __future__ import absolute_import +from __future__ import unicode_literals from . import baseDialog, trends, configuration, lists, message, search, find, show_user, update_profile, urlList, userSelection, utils, filterDialogs diff --git a/src/wxUI/dialogs/attach.py b/src/wxUI/dialogs/attach.py index 50da4743..37ac6f21 100644 --- a/src/wxUI/dialogs/attach.py +++ b/src/wxUI/dialogs/attach.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """ Attach dialog. Taken from socializer: https://github.com/manuelcortez/socializer""" +from __future__ import unicode_literals import wx import widgetUtils from multiplatform_widgets import widgets diff --git a/src/wxUI/dialogs/baseDialog.py b/src/wxUI/dialogs/baseDialog.py index b48a194b..01fe8b49 100644 --- a/src/wxUI/dialogs/baseDialog.py +++ b/src/wxUI/dialogs/baseDialog.py @@ -1,3 +1,4 @@ +from __future__ import unicode_literals import wx class BaseWXDialog(wx.Dialog): diff --git a/src/wxUI/dialogs/configuration.py b/src/wxUI/dialogs/configuration.py index dcafb0ec..31f936d9 100644 --- a/src/wxUI/dialogs/configuration.py +++ b/src/wxUI/dialogs/configuration.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals +from builtins import range import logging as original_logger import wx import application @@ -228,7 +230,7 @@ class other_buffers(wx.Panel): output.speak(self.buffers.get_text_column(current, 2),True) def get_list(self): buffers_list = [] - for i in xrange(0, self.buffers.get_count()): + for i in range(0, self.buffers.get_count()): if self.buffers.get_text_column(i, 2) == _(u"Show"): buffers_list.append(self.buffers.get_text_column(i, 0)) return buffers_list diff --git a/src/wxUI/dialogs/filterDialogs.py b/src/wxUI/dialogs/filterDialogs.py index 608ec2c8..edff9d6a 100644 --- a/src/wxUI/dialogs/filterDialogs.py +++ b/src/wxUI/dialogs/filterDialogs.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals # -*- coding: utf-8 -*- from . import baseDialog import wx diff --git a/src/wxUI/dialogs/find.py b/src/wxUI/dialogs/find.py index 0b18ea20..73a3dd6f 100644 --- a/src/wxUI/dialogs/find.py +++ b/src/wxUI/dialogs/find.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals # -*- coding: utf-8 -*- from . import baseDialog import wx diff --git a/src/wxUI/dialogs/lists.py b/src/wxUI/dialogs/lists.py index 5fb7d57f..4dbf55a8 100644 --- a/src/wxUI/dialogs/lists.py +++ b/src/wxUI/dialogs/lists.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx import widgetUtils from multiplatform_widgets import widgets diff --git a/src/wxUI/dialogs/message.py b/src/wxUI/dialogs/message.py index c22cebfc..50e380d7 100644 --- a/src/wxUI/dialogs/message.py +++ b/src/wxUI/dialogs/message.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import str import wx import widgetUtils diff --git a/src/wxUI/dialogs/search.py b/src/wxUI/dialogs/search.py index 34992613..13cc45ce 100644 --- a/src/wxUI/dialogs/search.py +++ b/src/wxUI/dialogs/search.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import widgetUtils from . import baseDialog import wx @@ -27,7 +28,7 @@ class searchDialog(baseDialog.BaseWXDialog): radioSizer.Add(self.users, 0, wx.ALL, 5) sizer.Add(radioSizer, 0, wx.ALL, 5) lang = wx.StaticText(panel, -1, _(u"&Language for results: ")) - langs = [x for x in translator.translator.languages.values()] + langs = [x for x in list(translator.translator.languages.values())] langs.insert(0, _(u"any")) self.lang = wx.ComboBox(panel, -1, choices=langs, value=langs[0], style = wx.CB_READONLY) langBox = wx.BoxSizer(wx.HORIZONTAL) @@ -54,7 +55,7 @@ class searchDialog(baseDialog.BaseWXDialog): l = self.lang.GetStringSelection() if l == _(u"any"): return "" - for langcode, langname in translator.translator.languages.iteritems(): + for langcode, langname in translator.translator.languages.items(): if langname == l: return langcode diff --git a/src/wxUI/dialogs/show_user.py b/src/wxUI/dialogs/show_user.py index 2fb8d4ca..1c7be5b4 100644 --- a/src/wxUI/dialogs/show_user.py +++ b/src/wxUI/dialogs/show_user.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import wx from . import baseDialog diff --git a/src/wxUI/dialogs/trends.py b/src/wxUI/dialogs/trends.py index fa591b36..1a670b1c 100644 --- a/src/wxUI/dialogs/trends.py +++ b/src/wxUI/dialogs/trends.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals # -*- coding: utf-8 -*- from . import baseDialog import wx diff --git a/src/wxUI/dialogs/update_profile.py b/src/wxUI/dialogs/update_profile.py index ea248bc3..ba1cb541 100644 --- a/src/wxUI/dialogs/update_profile.py +++ b/src/wxUI/dialogs/update_profile.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import +from __future__ import unicode_literals import wx from . import baseDialog diff --git a/src/wxUI/dialogs/urlList.py b/src/wxUI/dialogs/urlList.py index ee5f0fdc..16012f57 100644 --- a/src/wxUI/dialogs/urlList.py +++ b/src/wxUI/dialogs/urlList.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx class urlList(wx.Dialog): diff --git a/src/wxUI/dialogs/userActions.py b/src/wxUI/dialogs/userActions.py index e0fecb6c..c60f24bf 100644 --- a/src/wxUI/dialogs/userActions.py +++ b/src/wxUI/dialogs/userActions.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx class UserActionsDialog(wx.Dialog): diff --git a/src/wxUI/dialogs/userSelection.py b/src/wxUI/dialogs/userSelection.py index 76924cb5..30dc67d3 100644 --- a/src/wxUI/dialogs/userSelection.py +++ b/src/wxUI/dialogs/userSelection.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx class selectUserDialog(wx.Dialog): diff --git a/src/wxUI/dialogs/utils.py b/src/wxUI/dialogs/utils.py index 0adb20ca..36bdc8a8 100644 --- a/src/wxUI/dialogs/utils.py +++ b/src/wxUI/dialogs/utils.py @@ -17,6 +17,7 @@ # ############################################################ from __future__ import absolute_import +from __future__ import unicode_literals import wx from . import baseDialog diff --git a/src/wxUI/menus.py b/src/wxUI/menus.py index 164035bd..70fbd7fa 100644 --- a/src/wxUI/menus.py +++ b/src/wxUI/menus.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals import wx class basePanelMenu(wx.Menu): diff --git a/src/wxUI/sysTrayIcon.py b/src/wxUI/sysTrayIcon.py index 2ceffa25..81efcd10 100644 --- a/src/wxUI/sysTrayIcon.py +++ b/src/wxUI/sysTrayIcon.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """ A systray for TW Blue """ +from __future__ import unicode_literals ############################################################ # Copyright (c) 2014 José Manuel Delicado Alcolea # diff --git a/src/wxUI/view.py b/src/wxUI/view.py index 33596dff..2729f6bf 100644 --- a/src/wxUI/view.py +++ b/src/wxUI/view.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals +from builtins import range import wx import wx.adv import application From a4f20872b0e9d533f2feda6563e214f60d6ce29d Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Thu, 6 Jun 2019 13:03:17 -0500 Subject: [PATCH 2/3] Install latest pypubsub for Python 3 instead of the 3.3.0 version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index fb4d7be4..a3c3527e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ requests oauthlib requests-oauthlib requests-toolbelt -pypubsub==3.3.0 +pypubsub pygeocoder arrow python-dateutil From ebd8e42154136af903c2a98eb26d225e9bddfef0 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Thu, 6 Jun 2019 13:06:51 -0500 Subject: [PATCH 3/3] Install a newer accessible_output2 package --- requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index a3c3527e..261b9d6b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,6 +27,5 @@ backports.functools_lru_cache git+https://github.com/manuelcortez/twython git+https://github.com/manuelcortez/libloader git+https://github.com/manuelcortez/platform_utils -git+https://github.com/Mohamed00/accessible_output2 -#git+https://github.com/manuelcortez/accessible_output2 +git+https://github.com/manuelcortez/accessible_output2 git+https://github.com/chrisnorman7/sound_lib \ No newline at end of file