This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ericsnowcurrently/lint
Fix flake8 failures.
- Loading branch information
Showing
10 changed files
with
391 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See LICENSE in the project root for license information. | ||
# Licensed under the MIT License. See LICENSE in the project root | ||
# for license information. | ||
|
||
__author__ = "Microsoft Corporation <[email protected]>" | ||
__version__ = "4.0.0a1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See LICENSE in the project root for license information. | ||
# Licensed under the MIT License. See LICENSE in the project root | ||
# for license information. | ||
|
||
import pydevd | ||
|
||
import ptvsd.wrapper | ||
|
||
|
||
__author__ = "Microsoft Corporation <[email protected]>" | ||
__version__ = "4.0.0a1" | ||
|
||
|
||
if __name__ == '__main__': | ||
import ptvsd.wrapper | ||
import pydevd | ||
ptvsd.wrapper.install() | ||
pydevd.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See LICENSE in the project root for license information. | ||
# Licensed under the MIT License. See LICENSE in the project root | ||
# for license information. | ||
|
||
import sys | ||
|
||
import pydevd | ||
|
||
import ptvsd.wrapper | ||
|
||
|
||
__author__ = "Microsoft Corporation <[email protected]>" | ||
__version__ = "4.0.0a1" | ||
|
||
DONT_DEBUG = [] | ||
|
||
|
||
def debug(filename, port_num, debug_id, debug_options, run_as): | ||
import sys | ||
import ptvsd.wrapper | ||
import pydevd | ||
sys.argv[1:0] = ['--port', str(port_num), '--client', '127.0.0.1', '--file', filename] | ||
# TODO: docstring | ||
ptvsd.wrapper.install() | ||
sys.argv[1:0] = [ | ||
'--port', str(port_num), | ||
'--client', '127.0.0.1', | ||
'--file', filename, | ||
] | ||
pydevd.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,94 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See LICENSE in the project root for license information. | ||
# Licensed under the MIT License. See LICENSE in the project root | ||
# for license information. | ||
|
||
from __future__ import print_function, with_statement, absolute_import | ||
|
||
__author__ = "Microsoft Corporation <[email protected]>" | ||
__version__ = "4.0.0a1" | ||
|
||
import sys | ||
import threading | ||
import traceback | ||
from ptvsd.reraise import reraise | ||
|
||
|
||
__author__ = "Microsoft Corporation <[email protected]>" | ||
__version__ = "4.0.0a1" | ||
|
||
|
||
class Future(object): | ||
# TODO: docstring | ||
|
||
def __init__(self, loop): | ||
self._lock = threading.Lock() | ||
self._loop = loop | ||
self._done = False | ||
self._observed = False | ||
self._done_callbacks = [] | ||
self._exc_info = None | ||
|
||
def __del__(self): | ||
with self._lock: | ||
if self._done and self._exc_info and not self._observed: | ||
print('Unobserved exception in a Future:', file=sys.__stderr__) | ||
traceback.print_exception(self._exc_info[0], self._exc_info[1], self._exc_info[2], file=sys.__stderr__) | ||
traceback.print_exception(*self._exc_info, file=sys.__stderr__) | ||
|
||
def result(self): | ||
# TODO: docstring | ||
with self._lock: | ||
self._observed = True | ||
if self._exc_info: | ||
reraise(self._exc_info) | ||
return self._result | ||
|
||
def exc_info(self): | ||
# TODO: docstring | ||
with self._lock: | ||
self._observed = True | ||
return self._exc_info | ||
|
||
def set_result(self, result): | ||
# TODO: docstring | ||
with self._lock: | ||
self._result = result | ||
self._exc_info = None | ||
self._done = True | ||
callbacks = list(self._done_callbacks) | ||
|
||
def invoke_callbacks(): | ||
for cb in callbacks: | ||
cb(self) | ||
|
||
self._loop.call_soon(invoke_callbacks) | ||
|
||
def set_exc_info(self, exc_info): | ||
# TODO: docstring | ||
with self._lock: | ||
self._exc_info = exc_info | ||
self._done = True | ||
callbacks = list(self._done_callbacks) | ||
|
||
def invoke_callbacks(): | ||
for cb in callbacks: | ||
cb(self) | ||
|
||
self._loop.call_soon(invoke_callbacks) | ||
|
||
def add_done_callback(self, callback): | ||
# TODO: docstring | ||
with self._lock: | ||
done = self._done | ||
self._done_callbacks.append(callback) | ||
if done: | ||
callback(self) | ||
|
||
def remove_done_callback(self, callback): | ||
# TODO: docstring | ||
with self._lock: | ||
self._done_callbacks.remove(callback) | ||
|
||
|
||
class EventLoop(object): | ||
# TODO: docstring | ||
|
||
def __init__(self): | ||
self._queue = [] | ||
self._lock = threading.Lock() | ||
|
@@ -89,7 +107,7 @@ def run_forever(self): | |
self._event.clear() | ||
for (f, args) in queue: | ||
f(*args) | ||
|
||
def call_soon(self, f, *args): | ||
with self._lock: | ||
self._queue.append((f, args)) | ||
|
@@ -100,26 +118,32 @@ def call_soon_threadsafe(self, f, *args): | |
|
||
|
||
class Result(object): | ||
# TODO: docstring | ||
|
||
__slots__ = ['value'] | ||
|
||
def __init__(self, value): | ||
self.value = value | ||
|
||
|
||
def async(f): | ||
# TODO: docstring | ||
|
||
def g(self, loop, *args, **kwargs): | ||
it = f(self, *args, **kwargs) | ||
result = Future(loop) | ||
if it is None: | ||
result.set_result(None) | ||
return result | ||
|
||
def callback(fut): | ||
try: | ||
if fut is None: | ||
x = next(it) | ||
else: | ||
exc_info = fut.exc_info() | ||
if exc_info: | ||
x = it.throw(exc_info[0], exc_info[1], exc_info[2]) | ||
x = it.throw(*exc_info) | ||
else: | ||
x = it.send(fut.result()) | ||
except StopIteration: | ||
|
@@ -131,6 +155,7 @@ def callback(fut): | |
result.set_result(x.value) | ||
else: | ||
x.add_done_callback(callback) | ||
|
||
callback(None) | ||
return result | ||
return g |
Oops, something went wrong.