Python types.FileType() Examples
The following are 29
code examples of types.FileType().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
types
, or try the search function
.
Example #1
Source File: mail.py From girlfriend with MIT License | 6 votes |
def __init__(self, attachment_file, mime_type, attachment_filename=None): """ :param attachment_file 作为附件的文件对象,可以是file对象或者StringIO对象, 如果是字符串,那么将作为文件路径进行加载 :param mime_type 附件的mime type,比如application/octet-stream :param attachment_filename 附件所使用的文件名 """ if attachment_filename is None: if isinstance(attachment_file, types.StringTypes): self._attachment_filename = os.path.split( attachment_file)[1] elif isinstance(attachment_file, types.FileType): self._attachment_filename = os.path.split( attachment_file.name)[1] else: raise InvalidArgumentException( u"必须制定attachement_filename参数作为附件文件名")
Example #2
Source File: xml_parser.py From libvirt-test-API with GNU General Public License v2.0 | 6 votes |
def parse(self, arg): out = None if sys.version_info[0] >= 3: from io import IOBase filetype = IOBase else: filetype = types.FileType if isinstance(arg, filetype): out = self.parsefile(arg) elif os.path.exists(arg): print("file: %s " % arg) out = self.parsefile(arg) else: streamstr = StringIO(arg) out = self.parsefile(streamstr) if out is not None: return out
Example #3
Source File: pydoc.py From medicare-demo with Apache License 2.0 | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if sys.platform.startswith('java'): return plainpager if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more %s' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #4
Source File: jsonobject.py From zstack-utility with Apache License 2.0 | 5 votes |
def _is_unsupported_type(obj): return isinstance(obj, (types.ComplexType, types.TupleType, types.FunctionType, types.LambdaType, types.GeneratorType, types.MethodType, types.UnboundMethodType, types.BuiltinFunctionType, types.BuiltinMethodType, types.FileType, types.XRangeType, types.TracebackType, types.FrameType, types.DictProxyType, types.NotImplementedType, types.GetSetDescriptorType, types.MemberDescriptorType))
Example #5
Source File: modjy_impl.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def deal_with_app_return(self, environ, start_response_callable, app_return): self.log.debug("Processing app return type: %s" % str(type(app_return))) if isinstance(app_return, types.StringTypes): raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) if type(app_return) is types.FileType: pass # TBD: What to do here? can't call fileno() if hasattr(app_return, '__len__') and callable(app_return.__len__): expected_pieces = app_return.__len__() else: expected_pieces = -1 try: try: ix = 0 for next_piece in app_return: if not isinstance(next_piece, types.StringTypes): raise NonStringOutput("Application returned iterable containing non-strings: %s" % str(type(next_piece))) if ix == 0: # The application may have called start_response in the first iteration if not start_response_callable.called: raise StartResponseNotCalled("Start_response callable was never called.") if not start_response_callable.content_length \ and expected_pieces == 1 \ and start_response_callable.write_callable.num_writes == 0: # Take the length of the first piece start_response_callable.set_content_length(len(next_piece)) start_response_callable.write_callable(next_piece) ix += 1 if ix == expected_pieces: break if expected_pieces != -1 and ix != expected_pieces: raise WrongLength("Iterator len() was wrong. Expected %d pieces: got %d" % (expected_pieces, ix) ) except AttributeError, ax: if str(ax) == "__getitem__": raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) else: raise ax except TypeError, tx: raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return)))
Example #6
Source File: pydoc.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if _is_windows and JLine2Pager.available(): return lambda text: JLine2Pager(text).page() if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if _is_windows: # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if _is_windows or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #7
Source File: pydoc.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if _is_windows and JLine2Pager.available(): return lambda text: JLine2Pager(text).page() if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if _is_windows: # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if _is_windows or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #8
Source File: pydoc.py From canape with GNU General Public License v3.0 | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #9
Source File: pydoc.py From unity-python with MIT License | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not hasattr(sys.stdin, "isatty"): return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #10
Source File: pydoc.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not hasattr(sys.stdin, "isatty"): return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #11
Source File: mypydoc.py From azure-linux-extensions with Apache License 2.0 | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #12
Source File: pydoc.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #13
Source File: modjy_impl.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def deal_with_app_return(self, environ, start_response_callable, app_return): self.log.debug("Processing app return type: %s" % str(type(app_return))) if isinstance(app_return, types.StringTypes): raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) if type(app_return) is types.FileType: pass # TBD: What to do here? can't call fileno() if hasattr(app_return, '__len__') and callable(app_return.__len__): expected_pieces = app_return.__len__() else: expected_pieces = -1 try: try: ix = 0 for next_piece in app_return: if not isinstance(next_piece, types.StringTypes): raise NonStringOutput("Application returned iterable containing non-strings: %s" % str(type(next_piece))) if ix == 0: # The application may have called start_response in the first iteration if not start_response_callable.called: raise StartResponseNotCalled("Start_response callable was never called.") if not start_response_callable.content_length \ and expected_pieces == 1 \ and start_response_callable.write_callable.num_writes == 0: # Take the length of the first piece start_response_callable.set_content_length(len(next_piece)) start_response_callable.write_callable(next_piece) ix += 1 if ix == expected_pieces: break if expected_pieces != -1 and ix != expected_pieces: raise WrongLength("Iterator len() was wrong. Expected %d pieces: got %d" % (expected_pieces, ix) ) except AttributeError, ax: if str(ax) == "__getitem__": raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) else: raise ax except TypeError, tx: raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return)))
Example #14
Source File: pydoc.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if _is_windows and JLine2Pager.available(): return lambda text: JLine2Pager(text).page() if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if _is_windows: # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if _is_windows or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #15
Source File: pydoc.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if _is_windows and JLine2Pager.available(): return lambda text: JLine2Pager(text).page() if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if _is_windows: # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if _is_windows or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #16
Source File: modjy_impl.py From medicare-demo with Apache License 2.0 | 5 votes |
def deal_with_app_return(self, environ, start_response_callable, app_return): self.log.debug("Processing app return type: %s" % str(type(app_return))) if isinstance(app_return, types.StringTypes): raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) if type(app_return) is types.FileType: pass # TBD: What to do here? can't call fileno() if hasattr(app_return, '__len__') and callable(app_return.__len__): expected_pieces = app_return.__len__() else: expected_pieces = -1 try: try: ix = 0 for next_piece in app_return: if not isinstance(next_piece, types.StringTypes): raise NonStringOutput("Application returned iterable containing non-strings: %s" % str(type(next_piece))) if ix == 0: # The application may have called start_response in the first iteration if not start_response_callable.called: raise StartResponseNotCalled("Start_response callable was never called.") if not start_response_callable.content_length \ and expected_pieces == 1 \ and start_response_callable.write_callable.num_writes == 0: # Take the length of the first piece start_response_callable.set_content_length(len(next_piece)) start_response_callable.write_callable(next_piece) ix += 1 if ix == expected_pieces: break if expected_pieces != -1 and ix != expected_pieces: raise WrongLength("Iterator len() was wrong. Expected %d pieces: got %d" % (expected_pieces, ix) ) except AttributeError, ax: if str(ax) == "__getitem__": raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) else: raise ax except TypeError, tx: raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return)))
Example #17
Source File: pydoc.py From meddle with MIT License | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #18
Source File: sandbox.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def _install_fake_file(config, python_lib_paths, path_override_hook): """Install a stub file implementation to enforce sandbox rules.""" stubs.FakeFile.set_allowed_paths(config.application_root, python_lib_paths[1:] + path_override_hook.extra_accessible_paths) stubs.FakeFile.set_skip_files(config.skip_files) stubs.FakeFile.set_static_files(config.static_files) __builtin__.file = stubs.FakeFile __builtin__.open = stubs.FakeFile types.FileType = stubs.FakeFile
Example #19
Source File: pydoc.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not hasattr(sys.stdin, "isatty"): return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #20
Source File: tika.py From tika-python with Apache License 2.0 | 5 votes |
def _is_file_object(f): try: file_types = (types.FileType, io.IOBase) except AttributeError: file_types = (io.IOBase,) return isinstance(f, file_types)
Example #21
Source File: mail.py From girlfriend with MIT License | 5 votes |
def _gen_payload(self): # 文件类型的情况 if isinstance(self._attachment_file, types.FileType): try: return self._attachment_file.read() finally: self._attachment_file.close() # 字符串路径的情况 elif isinstance(self._attachment_file, types.StringTypes): with open(self._attachment_file, "r") as f: return f.read() # StringIO or cStringIO else: self._attachment_file.seek(0) return self._attachment_file.read()
Example #22
Source File: utils.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def isNonPrimitiveInstance(x): return isinstance(x,types.InstanceType) or not isinstance(x,(float,int,long,type,tuple,list,dict,bool,unicode,str,buffer,complex,slice,types.NoneType, types.FunctionType,types.LambdaType,types.CodeType,types.GeneratorType, types.ClassType,types.UnboundMethodType,types.MethodType,types.BuiltinFunctionType, types.BuiltinMethodType,types.ModuleType,types.FileType,types.XRangeType, types.TracebackType,types.FrameType,types.EllipsisType,types.DictProxyType, types.NotImplementedType,types.GetSetDescriptorType,types.MemberDescriptorType ))
Example #23
Source File: pydoc.py From oss-ftp with MIT License | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not hasattr(sys.stdin, "isatty"): return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #24
Source File: c_spec.py From Computable with MIT License | 5 votes |
def init_info(self): common_base_converter.init_info(self) self.type_name = 'file' self.check_func = 'PyFile_Check' self.c_type = 'FILE*' self.return_type = self.c_type self.to_c_return = "PyFile_AsFile(py_obj)" self.headers = ['<stdio.h>'] self.matching_types = [types.FileType]
Example #25
Source File: pydoc.py From Computable with MIT License | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #26
Source File: pydoc.py From BinderFilter with MIT License | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #27
Source File: pydoc.py From ironpython2 with Apache License 2.0 | 5 votes |
def getpager(): """Decide what method to use for paging through text.""" if type(sys.stdout) is not types.FileType: return plainpager if not hasattr(sys.stdin, "isatty"): return plainpager if not sys.stdin.isatty() or not sys.stdout.isatty(): return plainpager if 'PAGER' in os.environ: if sys.platform == 'win32': # pipes completely broken in Windows return lambda text: tempfilepager(plain(text), os.environ['PAGER']) elif os.environ.get('TERM') in ('dumb', 'emacs'): return lambda text: pipepager(plain(text), os.environ['PAGER']) else: return lambda text: pipepager(text, os.environ['PAGER']) if os.environ.get('TERM') in ('dumb', 'emacs'): return plainpager if sys.platform == 'win32' or sys.platform.startswith('os2'): return lambda text: tempfilepager(plain(text), 'more <') if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0: return lambda text: pipepager(text, 'less') import tempfile (fd, filename) = tempfile.mkstemp() os.close(fd) try: if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0: return lambda text: pipepager(text, 'more') else: return ttypager finally: os.unlink(filename)
Example #28
Source File: reflect.py From BitTorrent with GNU General Public License v3.0 | 4 votes |
def objgrep(start, goal, eq=isLike, path='', paths=None, seen=None, showUnknowns=0, maxDepth=None): '''An insanely CPU-intensive process for finding stuff. ''' if paths is None: paths = [] if seen is None: seen = {} if eq(start, goal): paths.append(path) if seen.has_key(id(start)): if seen[id(start)] is start: return if maxDepth is not None: if maxDepth == 0: return maxDepth -= 1 seen[id(start)] = start if isinstance(start, types.DictionaryType): r = [] for k, v in start.items(): objgrep(k, goal, eq, path+'{'+repr(v)+'}', paths, seen, showUnknowns, maxDepth) objgrep(v, goal, eq, path+'['+repr(k)+']', paths, seen, showUnknowns, maxDepth) elif isinstance(start, types.ListType) or isinstance(start, types.TupleType): for idx in xrange(len(start)): objgrep(start[idx], goal, eq, path+'['+str(idx)+']', paths, seen, showUnknowns, maxDepth) elif isinstance(start, types.MethodType): objgrep(start.im_self, goal, eq, path+'.im_self', paths, seen, showUnknowns, maxDepth) objgrep(start.im_func, goal, eq, path+'.im_func', paths, seen, showUnknowns, maxDepth) objgrep(start.im_class, goal, eq, path+'.im_class', paths, seen, showUnknowns, maxDepth) elif hasattr(start, '__dict__'): for k, v in start.__dict__.items(): objgrep(v, goal, eq, path+'.'+k, paths, seen, showUnknowns, maxDepth) if isinstance(start, types.InstanceType): objgrep(start.__class__, goal, eq, path+'.__class__', paths, seen, showUnknowns, maxDepth) elif isinstance(start, weakref.ReferenceType): objgrep(start(), goal, eq, path+'()', paths, seen, showUnknowns, maxDepth) elif (isinstance(start, types.StringTypes+ (types.IntType, types.FunctionType, types.BuiltinMethodType, RegexType, types.FloatType, types.NoneType, types.FileType)) or type(start).__name__ in ('wrapper_descriptor', 'method_descriptor', 'member_descriptor', 'getset_descriptor')): pass elif showUnknowns: print 'unknown type', type(start), start return paths
Example #29
Source File: reflect.py From python-for-android with Apache License 2.0 | 4 votes |
def objgrep(start, goal, eq=isLike, path='', paths=None, seen=None, showUnknowns=0, maxDepth=None): '''An insanely CPU-intensive process for finding stuff. ''' if paths is None: paths = [] if seen is None: seen = {} if eq(start, goal): paths.append(path) if id(start) in seen: if seen[id(start)] is start: return if maxDepth is not None: if maxDepth == 0: return maxDepth -= 1 seen[id(start)] = start if isinstance(start, types.DictionaryType): for k, v in start.items(): objgrep(k, goal, eq, path+'{'+repr(v)+'}', paths, seen, showUnknowns, maxDepth) objgrep(v, goal, eq, path+'['+repr(k)+']', paths, seen, showUnknowns, maxDepth) elif isinstance(start, (list, tuple, deque)): for idx in xrange(len(start)): objgrep(start[idx], goal, eq, path+'['+str(idx)+']', paths, seen, showUnknowns, maxDepth) elif isinstance(start, types.MethodType): objgrep(start.im_self, goal, eq, path+'.im_self', paths, seen, showUnknowns, maxDepth) objgrep(start.im_func, goal, eq, path+'.im_func', paths, seen, showUnknowns, maxDepth) objgrep(start.im_class, goal, eq, path+'.im_class', paths, seen, showUnknowns, maxDepth) elif hasattr(start, '__dict__'): for k, v in start.__dict__.items(): objgrep(v, goal, eq, path+'.'+k, paths, seen, showUnknowns, maxDepth) if isinstance(start, types.InstanceType): objgrep(start.__class__, goal, eq, path+'.__class__', paths, seen, showUnknowns, maxDepth) elif isinstance(start, weakref.ReferenceType): objgrep(start(), goal, eq, path+'()', paths, seen, showUnknowns, maxDepth) elif (isinstance(start, types.StringTypes+ (types.IntType, types.FunctionType, types.BuiltinMethodType, RegexType, types.FloatType, types.NoneType, types.FileType)) or type(start).__name__ in ('wrapper_descriptor', 'method_descriptor', 'member_descriptor', 'getset_descriptor')): pass elif showUnknowns: print 'unknown type', type(start), start return paths