mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
platform-specific proxy pickup
This commit is contained in:
parent
1eaa6b9c1a
commit
d143a50358
1 changed files with 43 additions and 15 deletions
|
@ -7,7 +7,7 @@
|
|||
# - Saves in sqlite rather than a flat file so the config can't be corrupted
|
||||
|
||||
from aqt.qt import *
|
||||
import os, sys, time, random, cPickle, shutil, locale, re, atexit
|
||||
import os, sys, time, random, cPickle, shutil, locale, re, atexit, urllib
|
||||
from anki.db import DB
|
||||
from anki.utils import isMac, isWin, intTime, checksum
|
||||
from anki.lang import langs
|
||||
|
@ -139,20 +139,7 @@ computer."""))
|
|||
if name != "_global":
|
||||
self.name = name
|
||||
self.profile = prof
|
||||
# export proxy settings
|
||||
if prof['proxyHost'] == "off":
|
||||
# force off; override environment
|
||||
anki.sync.HTTP_PROXY = None
|
||||
elif prof['proxyHost']:
|
||||
url = prof['proxyHost']
|
||||
if url.lower().startswith("https"):
|
||||
method = "https"
|
||||
else:
|
||||
method = "http"
|
||||
anki.sync.HTTP_PROXY = ProxyInfo.from_url(url, method)
|
||||
else:
|
||||
# use environment
|
||||
anki.sync.HTTP_PROXY = ProxyInfo.from_environment()
|
||||
self.setupProxy()
|
||||
return True
|
||||
|
||||
def save(self):
|
||||
|
@ -298,3 +285,44 @@ create table if not exists profiles
|
|||
sql = "update profiles set data = ? where name = ?"
|
||||
self.db.execute(sql, cPickle.dumps(self.meta), "_global")
|
||||
self.db.commit()
|
||||
|
||||
# Proxy handling
|
||||
######################################################################
|
||||
|
||||
def setupProxy(self):
|
||||
prof = self.profile
|
||||
# export proxy settings
|
||||
if prof['proxyHost'] == "off":
|
||||
# force off; override environment
|
||||
anki.sync.HTTP_PROXY = None
|
||||
elif prof['proxyHost']:
|
||||
url = prof['proxyHost']
|
||||
anki.sync.HTTP_PROXY = ProxyInfo.from_url(
|
||||
url, self.proxyMethod(url))
|
||||
else:
|
||||
# set in env?
|
||||
p = ProxyInfo.from_environment()
|
||||
if not p:
|
||||
# platform-specific fetch
|
||||
url = None
|
||||
if isWin:
|
||||
r = urllib.getproxies_registry()
|
||||
if 'https' in r:
|
||||
url = r['https']
|
||||
elif 'http' in r:
|
||||
url = r['http']
|
||||
elif isMac:
|
||||
r = urllib.getproxies_macosx_sysconf()
|
||||
if 'https' in r:
|
||||
url = r['https']
|
||||
elif 'http' in r:
|
||||
url = r['http']
|
||||
if url:
|
||||
p = ProxyInfo.from_url(url, self.proxyMethod(url))
|
||||
anki.sync.HTTP_PROXY = p
|
||||
|
||||
def proxyMethod(self, url):
|
||||
if url.lower().startswith("https"):
|
||||
return "https"
|
||||
else:
|
||||
return "http"
|
||||
|
|
Loading…
Reference in a new issue