本文整理汇总了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)