本文整理匯總了Python中nltk.compat.HTTPError方法的典型用法代碼示例。如果您正苦於以下問題:Python compat.HTTPError方法的具體用法?Python compat.HTTPError怎麽用?Python compat.HTTPError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nltk.compat
的用法示例。
在下文中一共展示了compat.HTTPError方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import HTTPError [as 別名]
def run(self):
print('NLTK Downloader')
while True:
self._simple_interactive_menu(
'd) Download', 'l) List', ' u) Update', 'c) Config', 'h) Help', 'q) Quit')
user_input = compat.raw_input('Downloader> ').strip()
if not user_input: print(); continue
command = user_input.lower().split()[0]
args = user_input.split()[1:]
try:
if command == 'l':
print()
self._ds.list(self._ds.download_dir, header=False,
more_prompt=True)
elif command == 'h':
self._simple_interactive_help()
elif command == 'c':
self._simple_interactive_config()
elif command in ('q', 'x'):
return
elif command == 'd':
self._simple_interactive_download(args)
elif command == 'u':
self._simple_interactive_update()
else:
print('Command %r unrecognized' % user_input)
except compat.HTTPError as e:
print('Error reading from server: %s'%e)
except compat.URLError as e:
print('Error connecting to server: %s'%e.reason)
# try checking if user_input is a package name, &
# downloading it?
print()
示例2: _refresh
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import HTTPError [as 別名]
def _refresh(self):
self._ds.clear_status_cache()
try:
self._fill_table()
except compat.HTTPError as e:
showerror('Error reading from server', e)
except compat.URLError as e:
showerror('Error connecting to server', e.reason)
self._table.select(0)
示例3: _set_download_dir
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import HTTPError [as 別名]
def _set_download_dir(self, download_dir):
if self._ds.download_dir == download_dir: return
# check if the dir exists, and if not, ask if we should create it?
# Clear our status cache, & re-check what's installed
self._ds.download_dir = download_dir
try:
self._fill_table()
except compat.HTTPError as e:
showerror('Error reading from server', e)
except compat.URLError as e:
showerror('Error connecting to server', e.reason)
self._show_info()
示例4: _prev_tab
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import HTTPError [as 別名]
def _prev_tab(self, *e):
for i, tab in enumerate(self._tab_names):
if tab.lower() == self._tab and i > 0:
self._tab = self._tab_names[i-1].lower()
try:
return self._fill_table()
except compat.HTTPError as e:
showerror('Error reading from server', e)
except compat.URLError as e:
showerror('Error connecting to server', e.reason)
示例5: _select_tab
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import HTTPError [as 別名]
def _select_tab(self, event):
self._tab = event.widget['text'].lower()
try:
self._fill_table()
except compat.HTTPError as e:
showerror('Error reading from server', e)
except compat.URLError as e:
showerror('Error connecting to server', e.reason)
示例6: __init__
# 需要導入模塊: from nltk import compat [as 別名]
# 或者: from nltk.compat import HTTPError [as 別名]
def __init__(self, dataserver, use_threads=True):
self._ds = dataserver
self._use_threads = use_threads
# For the threaded downloader:
self._download_lock = threading.Lock()
self._download_msg_queue = []
self._download_abort_queue = []
self._downloading = False
# For tkinter after callbacks:
self._afterid = {}
# A message log.
self._log_messages = []
self._log_indent = 0
self._log('NLTK Downloader Started!')
# Create the main window.
top = self.top = Tk()
top.geometry('+50+50')
top.title('NLTK Downloader')
top.configure(background=self._BACKDROP_COLOR[1])
# Set up some bindings now, in case anything goes wrong.
top.bind('<Control-q>', self.destroy)
top.bind('<Control-x>', self.destroy)
self._destroyed = False
self._column_vars = {}
# Initialize the GUI.
self._init_widgets()
self._init_menu()
try:
self._fill_table()
except compat.HTTPError as e:
showerror('Error reading from server', e)
except compat.URLError as e:
showerror('Error connecting to server', e.reason)
self._show_info()
self._select_columns()
self._table.select(0)
# Make sure we get notified when we're destroyed, so we can
# cancel any download in progress.
self._table.bind('<Destroy>', self._destroy)