Revert "Merge branch 'Ebag333-UnicodePaths' into development"

This reverts commit 8a6ef788b3, reversing
changes made to cf91ae7627.
This commit is contained in:
blitzman
2016-12-18 15:56:06 -05:00
parent 50c6133046
commit ff60538e21
6 changed files with 242 additions and 317 deletions

View File

@@ -1,17 +1,14 @@
import base64
import logging
import os
import re
import base64
import time
import zlib
import requests
from requests.adapters import HTTPAdapter
import config
from . import version
from compat import bytes_, text_
from errors import APIException
from . import version
from requests.adapters import HTTPAdapter
try:
from urllib.parse import urlparse, urlunparse, parse_qsl
@@ -27,7 +24,9 @@ try:
from urllib.parse import quote
except ImportError: # pragma: no cover
from urllib import quote
import logging
import re
import config
logger = logging.getLogger("pycrest.eve")
cache_re = re.compile(r'max-age=([0-9]+)')
@@ -52,13 +51,7 @@ class FileCache(APICache):
os.mkdir(self.path, 0o700)
def _getpath(self, key):
path = os.path.join(self.path, str(hash(key)) + '.cache')
if type(path) == str: # leave unicode ones alone
try:
path = path.decode('utf8')
except UnicodeDecodeError:
path = path.decode('windows-1252')
return path
return os.path.join(self.path, str(hash(key)) + '.cache')
def put(self, key, value):
with open(self._getpath(key), 'wb') as f:
@@ -118,7 +111,7 @@ class APIConnection(object):
})
session.headers.update(additional_headers)
session.mount('https://public-crest.eveonline.com',
HTTPAdapter())
HTTPAdapter())
self._session = session
if cache:
if isinstance(cache, APICache):
@@ -256,18 +249,19 @@ class EVE(APIConnection):
def temptoken_authorize(self, access_token=None, expires_in=0, refresh_token=None):
self.set_auth_values({'access_token': access_token,
'refresh_token': refresh_token,
'expires_in': expires_in})
'refresh_token': refresh_token,
'expires_in': expires_in})
class AuthedConnection(EVE):
def __call__(self):
if not self._data:
self._data = APIObject(self.get(self._endpoint), self)
return self._data
def whoami(self):
# if 'whoami' not in self._cache:
#if 'whoami' not in self._cache:
# print "Setting this whoami cache"
# self._cache['whoami'] = self.get("%s/verify" % self._oauth_endpoint)
return self.get("%s/verify" % self._oauth_endpoint)
@@ -287,7 +281,6 @@ class AuthedConnection(EVE):
self.refr_authorize(self.refresh_token)
return self._session.delete(resource, params=params)
class APIObject(object):
def __init__(self, parent, connection):
self._dict = {}

View File

@@ -1,4 +1,4 @@
# ===============================================================================
#===============================================================================
# Copyright (C) 2010 Diego Duclos
#
# This file is part of pyfa.
@@ -15,41 +15,33 @@
#
# You should have received a copy of the GNU General Public License
# along with pyfa. If not, see <http://www.gnu.org/licenses/>.
# ===============================================================================
#===============================================================================
import cPickle
import os.path
import config
import urllib2
import config
class SettingsProvider():
BASE_PATH = config.getSavePath("settings")
BASE_PATH = os.path.join(config.savePath, "settings")
settings = {}
_instance = None
@classmethod
def getInstance(cls):
if cls._instance is None:
if cls._instance == None:
cls._instance = SettingsProvider()
return cls._instance
def __init__(self):
if not os.path.exists(self.BASE_PATH):
os.mkdir(self.BASE_PATH)
os.mkdir(self.BASE_PATH);
def getSettings(self, area, defaults=None):
s = self.settings.get(area)
if s is None:
p = os.path.join(self.BASE_PATH, area)
if type(p) == str: # leave unicode ones alone
try:
p = p.decode('utf8')
except UnicodeDecodeError:
p = p.decode('windows-1252')
if not os.path.exists(p):
info = {}
@@ -79,7 +71,6 @@ class SettingsProvider():
for settings in self.settings.itervalues():
settings.save()
class Settings():
def __init__(self, location, info):
self.location = location
@@ -124,13 +115,13 @@ class NetworkSettings():
_instance = None
# constants for serviceNetworkDefaultSettings["mode"] parameter
PROXY_MODE_NONE = 0 # 0 - No proxy
PROXY_MODE_NONE = 0 # 0 - No proxy
PROXY_MODE_AUTODETECT = 1 # 1 - Auto-detected proxy settings
PROXY_MODE_MANUAL = 2 # 2 - Manual proxy settings
PROXY_MODE_MANUAL = 2 # 2 - Manual proxy settings
@classmethod
def getInstance(cls):
if cls._instance is None:
if cls._instance == None:
cls._instance = NetworkSettings()
return cls._instance
@@ -193,11 +184,12 @@ class NetworkSettings():
def setAccess(self, access):
self.serviceNetworkSettings["access"] = access
@staticmethod
def autodetect():
def autodetect(self):
proxy = None
proxAddr = proxPort = ""
proxydict = urllib2.ProxyHandler().proxies
txt = "Auto-detected: "
validPrefixes = ("http", "https")
@@ -245,57 +237,53 @@ class NetworkSettings():
self.serviceNetworkSettings["password"] = password
"""
Settings used by the HTML export feature.
"""
class HTMLExportSettings():
_instance = None
@classmethod
def getInstance(cls):
if cls._instance is None:
if cls._instance == None:
cls._instance = HTMLExportSettings()
return cls._instance
def __init__(self):
serviceHTMLExportDefaultSettings = {"enabled": False, "path": config.pyfaPath + os.sep + 'pyfaFits.html',
"minimal": False}
self.serviceHTMLExportSettings = SettingsProvider.getInstance().getSettings("pyfaServiceHTMLExportSettings",
serviceHTMLExportDefaultSettings)
serviceHTMLExportDefaultSettings = {"enabled": False, "path": config.pyfaPath + os.sep + 'pyfaFits.html', "minimal": False }
self.serviceHTMLExportSettings = SettingsProvider.getInstance().getSettings("pyfaServiceHTMLExportSettings", serviceHTMLExportDefaultSettings)
def getEnabled(self):
return self.serviceHTMLExportSettings["enabled"]
def setEnabled(self, enabled):
self.serviceHTMLExportSettings["enabled"] = enabled
def getMinimalEnabled(self):
return self.serviceHTMLExportSettings["minimal"]
def setMinimalEnabled(self, minimal):
self.serviceHTMLExportSettings["minimal"] = minimal
def getPath(self):
return self.serviceHTMLExportSettings["path"]
def setPath(self, path):
self.serviceHTMLExportSettings["path"] = path
"""
Settings used by update notification
"""
class UpdateSettings():
_instance = None
@classmethod
def getInstance(cls):
if cls._instance is None:
if cls._instance == None:
cls._instance = UpdateSettings()
return cls._instance
@@ -305,9 +293,8 @@ class UpdateSettings():
# Updates are completely suppressed via network settings
# prerelease - If True, suppress prerelease notifications
# version - Set to release tag that user does not want notifications for
serviceUpdateDefaultSettings = {"prerelease": True, 'version': None}
self.serviceUpdateSettings = SettingsProvider.getInstance().getSettings("pyfaServiceUpdateSettings",
serviceUpdateDefaultSettings)
serviceUpdateDefaultSettings = {"prerelease": True, 'version': None }
self.serviceUpdateSettings = SettingsProvider.getInstance().getSettings("pyfaServiceUpdateSettings", serviceUpdateDefaultSettings)
def get(self, type):
return self.serviceUpdateSettings[type]
@@ -315,7 +302,6 @@ class UpdateSettings():
def set(self, type, value):
self.serviceUpdateSettings[type] = value
class CRESTSettings():
_instance = None
@@ -327,13 +313,13 @@ class CRESTSettings():
return cls._instance
def __init__(self):
# mode
# 0 - Implicit authentication
# 1 - User-supplied client details
serviceCRESTDefaultSettings = {"mode": 0, "server": 0, "clientID": "", "clientSecret": "", "timeout": 60}
self.serviceCRESTSettings = SettingsProvider.getInstance().getSettings("pyfaServiceCRESTSettings",
serviceCRESTDefaultSettings)
self.serviceCRESTSettings = SettingsProvider.getInstance().getSettings("pyfaServiceCRESTSettings", serviceCRESTDefaultSettings)
def get(self, type):
return self.serviceCRESTSettings[type]
@@ -341,4 +327,5 @@ class CRESTSettings():
def set(self, type, value):
self.serviceCRESTSettings[type] = value
# @todo: migrate fit settings (from fit service) here?