コード例 #1
0
ファイル: manager.py プロジェクト: AlexStef/stef-sublime-conf
    def buf_from_path(self, path, lang=None, env=None, encoding=None):
        # Detect and abort on large files - to avoid memory errors, bug 88487.
        # The maximum size is 1MB - someone uses source code that big?
        filestat = os.stat(path)
        if filestat.st_size > self.MAX_FILESIZE:
            log.warn(
                "File %r has size greater than 1MB (%d)", path, filestat.st_size)
            raise CodeIntelError('File too big. Size: %d bytes, path: %r' % (
                                 filestat.st_size, path))

        if lang is None or encoding is None:
            import textinfo
            ti = textinfo.textinfo_from_path(path, encoding=encoding,
                                             follow_symlinks=True)
            if lang is None:
                lang = (hasattr(ti.langinfo, "komodo_name")
                        and ti.langinfo.komodo_name
                        or ti.langinfo.name)
            if not ti.is_text:
                return self.binary_buf_from_path(path, lang, env)
            encoding = ti.encoding
            content = ti.text
        else:
            content = codecs.open(path, 'rb', encoding).read()

        # TODO: Re-instate this when have solution for CILE test failures
        #      that this causes.
        # if not isabs(path) and not path.startswith("<Unsaved>"):
        #    path = abspath(path)

        return self.buf_from_content(content, lang, env, path, encoding)
コード例 #2
0
    def buf_from_path(self, path, lang=None, env=None, encoding=None):
        # Detect and abort on large files - to avoid memory errors, bug 88487.
        # The maximum size is 1MB - someone uses source code that big?
        filestat = os.stat(path)
        if filestat.st_size > self.MAX_FILESIZE:
            log.warn("File %r has size greater than 1MB (%d)", path,
                     filestat.st_size)
            raise CodeIntelError('File too big. Size: %d bytes, path: %r' %
                                 (filestat.st_size, path))

        if lang is None or encoding is None:
            import textinfo
            ti = textinfo.textinfo_from_path(path,
                                             encoding=encoding,
                                             follow_symlinks=True)
            if lang is None:
                lang = (hasattr(ti.langinfo, "komodo_name")
                        and ti.langinfo.komodo_name or ti.langinfo.name)
            if not ti.is_text:
                return self.binary_buf_from_path(path, lang, env)
            encoding = ti.encoding
            content = ti.text
        else:
            try:
                content = codecs.open(path, 'rb', encoding).read()
            except:
                log.info("Unable to read %s (likely not a text file)" % path)
                content = ''

        #TODO: Re-instate this when have solution for CILE test failures
        #      that this causes.
        #if not isabs(path) and not path.startswith("<Unsaved>"):
        #    path = abspath(path)

        return self.buf_from_content(content, lang, env, path, encoding)
コード例 #3
0
ファイル: Makefile.py プロジェクト: zhuyue1314/KomodoEdit
 def _no_svn_eol_style_files(self, d):
     from os.path import split
     for path in self._files_in_svn(d):
         ti = textinfo.textinfo_from_path(path)
         if not ti.is_text:
             continue
         if "svn:eol-style" in _svn_proplist(*split(path)):
             continue
         yield path
コード例 #4
0
ファイル: Makefile.py プロジェクト: ball6847/openkomodo
 def _no_svn_eol_style_files(self, d):
     from os.path import split
     for path in self._files_in_svn(d):
         ti = textinfo.textinfo_from_path(path)
         if not ti.is_text:
             continue
         if "svn:eol-style" in _svn_proplist(*split(path)):
             continue
         yield path
コード例 #5
0
    def _test_one_file(self, path, opts, expected_ti):
        #print "_test_one_file", path, expected_ti

        actual_ti = textinfo.textinfo_from_path(path, **opts)
        for attr in expected_ti:
            self.assert_(hasattr(actual_ti, attr),
                "unexpected textinfo for '%s': expected '%s' attr, but "
                "there isn't one on %r" % (path, attr, actual_ti))
            self.assertEqual(
                getattr(actual_ti, attr), expected_ti[attr],
                "unexpected '%s' for '%s': expected %r, got %r"
                % (attr, path, expected_ti[attr], getattr(actual_ti, attr)))
コード例 #6
0
    def _test_one_file(self, path, opts, expected_ti):
        #print "_test_one_file", path, expected_ti

        actual_ti = textinfo.textinfo_from_path(path, **opts)
        for attr in expected_ti:
            self.assert_(
                hasattr(actual_ti, attr),
                "unexpected textinfo for '%s': expected '%s' attr, but "
                "there isn't one on %r" % (path, attr, actual_ti))
            self.assertEqual(
                getattr(actual_ti, attr), expected_ti[attr],
                "unexpected '%s' for '%s': expected %r, got %r" %
                (attr, path, expected_ti[attr], getattr(actual_ti, attr)))
コード例 #7
0
ファイル: manager.py プロジェクト: Defman21/KomodoEdit
    def buf_from_path(self, path, lang=None, env=None, encoding=None):
        if lang != "Ruby":
            path = os.path.normpath(path) # reduce ./, ../, etc.
            # TODO: Ruby handles relative imports really weirdly. If
            # `normpath()` is used in Ruby, many of the Rails tests will fail.
        # Detect and abort on large files - to avoid memory errors, bug 88487.
        # The maximum size is 1MB - someone uses source code that big?
        filestat = os.stat(path)
        if filestat.st_size > self.MAX_FILESIZE:
            log.warn("File %r has size greater than 1MB (%d)", path, filestat.st_size)
            raise CodeIntelError('File too big. Size: %d bytes, path: %r' % (
                                 filestat.st_size, path))

        if lang is None or encoding is None:
            import textinfo
            ti = textinfo.textinfo_from_path(path, encoding=encoding,
                    follow_symlinks=True)
            if lang is None:
                lang = (hasattr(ti.langinfo, "komodo_name")
                        and ti.langinfo.komodo_name
                        or ti.langinfo.name)
            if not ti.is_text:
                return self.binary_buf_from_path(path, lang, env)
            encoding = ti.encoding
            content = ti.text
        else:
            try:
                content = codecs.open(path, 'rb', encoding).read()
            except:
                log.info("Unable to read %s (likely not a text file)" % path)
                content = ''

        #TODO: Re-instate this when have solution for CILE test failures
        #      that this causes.
        #if not isabs(path) and not path.startswith("<Unsaved>"):
        #    path = abspath(path)

        return self.buf_from_content(content, lang, env, path, encoding)