<s> import json <EOL> try : <EOL> from urllib2 import urlopen , Request , HTTPError , URLError <EOL> except ImportError : <EOL> from urllib . request import urlopen , Request <EOL> from urllib . error import HTTPError , URLError <EOL> import threading <EOL> import webbrowser <EOL> from functools import partial <EOL> import sublime <EOL> from sublime_plugin import ApplicationCommand <EOL> class CanSwitchCommand ( ApplicationCommand ) : <EOL> URL = '<STR_LIT>' <EOL> def run ( self ) : <EOL> installed_packages = self . get_installed_packages ( ) <EOL> thread = threading . Thread ( target = partial ( self . perform_check , installed_packages ) ) <EOL> sublime . status_message ( '<STR_LIT>' ) <EOL> thread . start ( ) <EOL> def get_installed_packages ( self ) : <EOL> settings = sublime . load_settings ( '<STR_LIT>' ) <EOL> if not settings . has ( '<STR_LIT>' ) : <EOL> sublime . error_message ( "<STR_LIT>" ) <EOL> packages = settings . get ( '<STR_LIT>' , [ ] ) <EOL> if not packages : <EOL> sublime . error_message ( "<STR_LIT>" ) <EOL> return packages <EOL> def perform_check ( self , packages ) : <EOL> data = json . dumps ( { '<STR_LIT>' : packages } ) . encode ( '<STR_LIT:utf-8>' ) <EOL> req = Request ( self . URL , data , { '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' } ) <EOL> try : <EOL> res = urlopen ( req ) <EOL> except HTTPError as e : <EOL> sublime . error_message ( '<STR_LIT>' % e . code ) <EOL> return <EOL> except URLError as e : <EOL> sublime . error_message ( '<STR_LIT>' ) <EOL> return <EOL> location = res . info ( ) . get ( '<STR_LIT>' ) <EOL> webbrowser . open ( location ) </s>
