Initial Python 3 compatible code

This commit is contained in:
2019-06-06 11:52:23 -05:00
parent d441536f01
commit ef689d04fc
146 changed files with 589 additions and 246 deletions

View File

@@ -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 = {}

View File

@@ -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:

View File

@@ -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
class InvalidSessionError(Exception): pass
class NonExistentSessionError(Exception): pass
class NotLoggedSessionError(BaseException): pass
class NotConfiguredSessionError(BaseException): pass
class RequireCredentialsSessionError(BaseException): pass
class AlreadyAuthorisedError(BaseException): pass

View File

@@ -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"

View File

@@ -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."""
""" 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

View File

@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################
from __future__ import unicode_literals
from sessions.twitter import utils
def is_long(tweet):

View File

@@ -17,6 +17,8 @@
#
############################################################
from __future__ import print_function
from __future__ import unicode_literals
from builtins import range
import logging
import requests
import keys

View File

@@ -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)

View File

@@ -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

View File

@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import wx
class authorisationDialog(wx.Dialog):