예제 #1
0
    def test_read_only_mode(self):
        with self.assertRaises(InvalidFileMode):
            BufferedReader('/tmp/foo', mode='a')

        with self.assertRaises(InvalidFileMode):
            BufferedReader('/tmp/foo', mode='ab')

        with self.assertRaises(InvalidFileMode):
            BufferedReader('/tmp/foo', mode='w')

        with self.assertRaises(InvalidFileMode):
            BufferedReader('/tmp/foo', mode='wb')
예제 #2
0
    def test_read_only_mode(self):
        with self.assertRaises(InvalidFileMode):
            BufferedReader("/tmp/foo", mode="a")

        with self.assertRaises(InvalidFileMode):
            BufferedReader("/tmp/foo", mode="ab")

        with self.assertRaises(InvalidFileMode):
            BufferedReader("/tmp/foo", mode="w")

        with self.assertRaises(InvalidFileMode):
            BufferedReader("/tmp/foo", mode="wb")
예제 #3
0
파일: find.py 프로젝트: vitorarins/salt
 def match(self, dirname, filename, fstat):
     if not stat.S_ISREG(fstat[stat.ST_MODE]):
         return None
     with BufferedReader(os.path.join(dirname, filename), mode='rb') as br:
         for chunk in br:
             if self.re.search(chunk):
                 return os.path.join(dirname, filename)
     return None
예제 #4
0
파일: find.py 프로젝트: virHappy/salt
 def match(self, dirname, filename, fstat):
     if not stat.S_ISREG(fstat[stat.ST_MODE]):
         return None
     dfilename = os.path.join(dirname, filename)
     with BufferedReader(dfilename, mode='rb') as bread:
         for chunk in bread:
             if self.regex.search(chunk):
                 return dfilename
     return None
예제 #5
0
 def find_value(text):
     stripped_text = text.strip()
     try:
         with BufferedReader(file_name) as breader:
             for chunk in breader:
                 if stripped_text in chunk:
                     return True
         return False
     except (IOError, OSError):
         return False
예제 #6
0
파일: find.py 프로젝트: lee-ch/slacker
 def match(self, dirname, filename, fstat):
     if not stat.S_ISREG(fstat[stat.ST_MODE]):
         return None
     dfilename = os.path.join(dirname, filename)
     # This could technically be done with ``open`` but if the file is large
     # it can cause resource usage issues, so buffer the output read in
     # memory
     with BufferedReader(dfilename, mode='rb') as bread:
         try:
             for chunk in bread:
                 if self.regex.search(chunk):
                     return dfilename
         except UnicodeDecodeError:
             next
     return None
예제 #7
0
파일: file.py 프로젝트: Gowtham523/salt
def contains_glob(path, glob):
    '''
    Return True if the given glob matches a string in the named file

    CLI Example::

        salt '*' /etc/foobar '*cheese*'
    '''
    if not os.path.exists(path):
        return False

    try:
        with BufferedReader(path) as br:
            for chunk in br:
                if fnmatch.fnmatch(chunk, glob):
                    return True
            return False
    except (IOError, OSError):
        return False
예제 #8
0
파일: file.py 프로젝트: Gowtham523/salt
def contains(path, text):
    '''
    Return True if the file at ``path`` contains ``text``

    CLI Example::

        salt '*' file.contains /etc/crontab 'mymaintenance.sh'

    .. versionadded:: 0.9.5
    '''
    if not os.path.exists(path):
        return False

    try:
        with BufferedReader(path) as br:
            for chunk in br:
                if text.strip() == chunk.strip():
                    return True
        return False
    except (IOError, OSError):
        return False
예제 #9
0
파일: file.py 프로젝트: Gowtham523/salt
def contains_regex(path, regex, lchar=''):
    '''
    Return True if the given regular expression matches anything in the text
    of a given file

    CLI Example::

        salt '*' /etc/crontab '^maint'
    '''
    if not os.path.exists(path):
        return False

    try:
        with BufferedReader(path) as br:
            for chunk in br:
                if lchar:
                    chunk = chunk.lstrip(lchar)
                if re.search(regex, chunk, re.MULTILINE):
                    return True
            return False
    except (IOError, OSError):
        return False