当前位置: 首页>>代码示例>>Python>>正文


Python types.FileType方法代码示例

本文整理汇总了Python中types.FileType方法的典型用法代码示例。如果您正苦于以下问题:Python types.FileType方法的具体用法?Python types.FileType怎么用?Python types.FileType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在types的用法示例。


在下文中一共展示了types.FileType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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参数作为附件文件名") 
开发者ID:chihongze,项目名称:girlfriend,代码行数:19,代码来源:mail.py

示例2: parse

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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 
开发者ID:libvirt,项目名称:libvirt-test-API,代码行数:19,代码来源:xml_parser.py

示例3: getpager

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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) 
开发者ID:glmcdona,项目名称:meddle,代码行数:32,代码来源:pydoc.py

示例4: getpager

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:34,代码来源:pydoc.py

示例5: init_info

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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] 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:c_spec.py

示例6: isNonPrimitiveInstance

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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
                    )) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:utils.py

示例7: _gen_payload

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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() 
开发者ID:chihongze,项目名称:girlfriend,代码行数:17,代码来源:mail.py

示例8: _is_file_object

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
def _is_file_object(f):
    try:
        file_types = (types.FileType, io.IOBase)
    except AttributeError:
        file_types = (io.IOBase,)

    return isinstance(f, file_types) 
开发者ID:chrismattmann,项目名称:tika-python,代码行数:9,代码来源:tika.py

示例9: _install_fake_file

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:12,代码来源:sandbox.py

示例10: getpager

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:34,代码来源:pydoc.py

示例11: deal_with_app_return

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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))) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:40,代码来源:modjy_impl.py

示例12: getpager

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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) 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:34,代码来源:pydoc.py

示例13: _is_unsupported_type

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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)) 
开发者ID:zstackio,项目名称:zstack-utility,代码行数:7,代码来源:jsonobject.py

示例14: objgrep

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:47,代码来源:reflect.py

示例15: objgrep

# 需要导入模块: import types [as 别名]
# 或者: from types import FileType [as 别名]
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 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:48,代码来源:reflect.py


注:本文中的types.FileType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。