fix secure tab
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Make a package.
|
||||
|
||||
This file has no other functionality. Individual modules in this package
|
||||
are used for testing, often being run with 'python -m ...' in individual
|
||||
test cases (functions).
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
@@ -0,0 +1,9 @@
|
||||
from __future__ import print_function
|
||||
# This file makes this directory into a runnable package.
|
||||
# it exists to test 'python -m gevent.monkey monkey_package'
|
||||
# Note that the __file__ may differ slightly; starting with
|
||||
# Python 3.9, directly running it gets an abspath, but
|
||||
# using ``runpy`` doesn't.
|
||||
import os.path
|
||||
print(os.path.abspath(__file__))
|
||||
print(__name__)
|
||||
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Test for issue #1526:
|
||||
- dnspython is imported first;
|
||||
- no monkey-patching is done.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
|
||||
import dns # pylint:disable=import-error
|
||||
assert dns
|
||||
import gevent.socket as socket # pylint:disable=consider-using-from-import
|
||||
socket.getfqdn() # create the resolver
|
||||
|
||||
from gevent.resolver.dnspython import dns as gdns
|
||||
import dns.rdtypes # pylint:disable=import-error
|
||||
|
||||
assert dns is not gdns, (dns, gdns)
|
||||
assert dns.rdtypes is not gdns.rdtypes
|
||||
import sys
|
||||
print(sorted(sys.modules))
|
||||
@@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Test for issue #1526:
|
||||
- dnspython is imported first;
|
||||
- monkey-patching happens early
|
||||
"""
|
||||
from __future__ import print_function, absolute_import
|
||||
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
# pylint:disable=import-error
|
||||
import dns
|
||||
assert dns
|
||||
|
||||
import socket
|
||||
import sys
|
||||
|
||||
socket.getfqdn()
|
||||
|
||||
import gevent.resolver.dnspython
|
||||
from gevent.resolver.dnspython import dns as gdns
|
||||
from dns import rdtypes # NOT import dns.rdtypes
|
||||
|
||||
assert gevent.resolver.dnspython.dns is gdns
|
||||
assert gdns is not dns, (gdns, dns, "id dns", id(dns))
|
||||
assert gdns.rdtypes is not rdtypes, (gdns.rdtypes, rdtypes)
|
||||
assert hasattr(dns, 'rdtypes')
|
||||
print(sorted(sys.modules))
|
||||
@@ -0,0 +1,26 @@
|
||||
from __future__ import print_function
|
||||
import socket
|
||||
import sys
|
||||
import os.path
|
||||
if sys.argv[1] == 'patched':
|
||||
print('gevent' in repr(socket.socket))
|
||||
else:
|
||||
assert sys.argv[1] == 'stdlib'
|
||||
print('gevent' not in repr(socket.socket))
|
||||
print(os.path.abspath(__file__))
|
||||
|
||||
|
||||
|
||||
if sys.argv[1] == 'patched':
|
||||
# __package__ is handled differently, for some reason, and
|
||||
# runpy doesn't let us override it. When we call it, it
|
||||
# becomes ''. This appears to be against the documentation for
|
||||
# runpy, which says specifically "If the supplied path
|
||||
# directly references a script file (whether as source or as
|
||||
# precompiled byte code), then __file__ will be set to the
|
||||
# supplied path, and __spec__, __cached__, __loader__ and
|
||||
# __package__ will all be set to None."
|
||||
print(__package__ == '') # pylint:disable=compare-to-empty-string
|
||||
else:
|
||||
# but the interpreter sets it to None
|
||||
print(__package__ is None)
|
||||
@@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Test script file, to be used directly as a file.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
|
||||
# We need some global imports
|
||||
from textwrap import dedent
|
||||
|
||||
def use_import():
|
||||
return dedent(" text")
|
||||
|
||||
if __name__ == '__main__':
|
||||
import os.path
|
||||
print(os.path.abspath(__file__))
|
||||
print(__name__)
|
||||
print(use_import())
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
This file runs ``gevent.monkey.patch_all()``.
|
||||
|
||||
It is intended to be used by ``python -m gevent.monkey <this file>``
|
||||
to prove that monkey-patching twice doesn't have unfortunate sife effects (such as
|
||||
breaking the threadpool).
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
from gevent import monkey
|
||||
from gevent import get_hub
|
||||
|
||||
monkey.patch_all(thread=False, sys=True)
|
||||
|
||||
def thread_is_greenlet():
|
||||
from gevent.thread import get_ident as gr_ident
|
||||
std_thread_mod = 'thread' if bytes is str else '_thread'
|
||||
thr_ident = monkey.get_original(std_thread_mod, 'get_ident')
|
||||
return thr_ident() == gr_ident()
|
||||
|
||||
|
||||
is_greenlet = get_hub().threadpool.apply(thread_is_greenlet)
|
||||
print(is_greenlet)
|
||||
print(len(sys._current_frames()))
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
This file *does not* run ``gevent.monkey.patch_all()``.
|
||||
|
||||
It is intended to be used by ``python -m gevent.monkey <this file>``
|
||||
to prove that the threadpool and getting the original value of things
|
||||
works.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
from gevent import monkey
|
||||
from gevent import get_hub
|
||||
|
||||
from gevent.thread import get_ident as gr_ident
|
||||
|
||||
std_thread_mod = 'thread' if bytes is str else '_thread'
|
||||
thr_ident = monkey.get_original(std_thread_mod, 'get_ident')
|
||||
|
||||
print(thr_ident is gr_ident)
|
||||
|
||||
def thread_is_greenlet():
|
||||
return thr_ident() == gr_ident()
|
||||
|
||||
|
||||
is_greenlet = get_hub().threadpool.apply(thread_is_greenlet)
|
||||
print(is_greenlet)
|
||||
print(len(sys._current_frames()))
|
||||
Reference in New Issue
Block a user