Пример #1
0
 def test_find_emails1(self):
     test_file = self.get_test_loc('finder/email/3w-xxxx.c')
     expected = [
         '*****@*****.**', '*****@*****.**', '*****@*****.**'
     ]
     result = list(finder.find_emails(test_file))
     assert expected == result
Пример #2
0
def get_emails(location, threshold=50, test_slow_mode=False, test_error_mode=False, **kwargs):
    """
    Return a mapping with a single 'emails' key with a value that is a list of
    mappings for emails detected in the file at `location`.
    Return only up to `threshold` values. Return all values if `threshold` is 0.

    If test_mode is True, the scan will be slow for testing purpose and pause
    for one second.
    """
    if test_error_mode:
        raise ScancodeError('Triggered email failure')

    if test_slow_mode:
        import time
        time.sleep(1)

    from cluecode.finder import find_emails
    results = []

    found_emails = ((em, ln) for (em, ln) in find_emails(location) if em)
    if threshold:
        found_emails = islice(found_emails, threshold)

    for email, line_num in found_emails:
        result = OrderedDict()
        results.append(result)
        result['email'] = email
        result['start_line'] = line_num
        result['end_line'] = line_num
    return dict(emails=results)
Пример #3
0
 def test_find_emails2(self):
     test_file = self.get_test_loc('finder/email/jardiff.py')
     expected = [
         '*****@*****.**',
     ]
     result = list(finder.find_emails(test_file))
     assert expected == result
Пример #4
0
 def test_find_emails1(self):
     test_file = self.get_test_loc('finder/email/3w-xxxx.c')
     expected = ['*****@*****.**',
                 '*****@*****.**',
                 '*****@*****.**']
     result = list(finder.find_emails(test_file))
     assert expected == result
Пример #5
0
 def test_find_emails5(self):
     bogus = [
         '*****@*****.**',
     ]
     expected = []
     result = list(finder.find_emails(bogus))
     assert expected == result
Пример #6
0
def find_emails_tester(lines_or_location, with_lineno=False, unique=True):
    """
    Helper function for testing emails with or without line numbers.
    """
    result = list(finder.find_emails(lines_or_location, unique))
    if not with_lineno:
        result = [val for val, _ln in result]
    return result
Пример #7
0
def find_emails_tester(lines_or_location, with_lineno=False, unique=True):
    """
    Helper function for testing emails with or without line numbers.
    """
    result = list(finder.find_emails(lines_or_location, unique))
    if not with_lineno:
        result = [val for val, _ln in result]
    return result
Пример #8
0
def get_emails(location):
    """
    Yield mappings of emails detected in the file at `location`.
    """
    from cluecode.finder import find_emails
    for email, line_num  in find_emails(location):
        if not email:
            continue
        misc = OrderedDict()
        misc['email'] = email
        misc['start_line'] = line_num
        misc['end_line'] = line_num
        yield misc
Пример #9
0
def get_emails(location):
    """
    Yield mappings of emails detected in the file at `location`.
    """
    from cluecode.finder import find_emails
    for email, line_num in find_emails(location):
        if not email:
            continue
        misc = OrderedDict()
        misc['email'] = email
        misc['start_line'] = line_num
        misc['end_line'] = line_num
        yield misc
Пример #10
0
 def test_find_emails4(self):
     bogus = ['gpt@40000a00',
             'xml.@summary',
             'xml.@detail',
             '*****@*****.**',
             'xml.@noPasswordExists',
             'historyDataGrid.selectedItem.@serialNumber',
             'constant.@name',
             'constant.@type',
             'dac.dacDataGrid.selectedItem.@dbUsername',
             'dac.dacDataGrid.selectedItem.@hostName',
             'dac.dacDataGrid.selectedItem.@name',
             'dac.dacDataGrid.selectedItem.@description',
             'dac.dacDataGrid.selectedItem.@dbPassword', ]
     expected = []
     result = list(finder.find_emails(bogus))
     assert expected == result
Пример #11
0
 def test_find_emails4(self):
     bogus = [
         'gpt@40000a00',
         'xml.@summary',
         'xml.@detail',
         '*****@*****.**',
         'xml.@noPasswordExists',
         'historyDataGrid.selectedItem.@serialNumber',
         'constant.@name',
         'constant.@type',
         'dac.dacDataGrid.selectedItem.@dbUsername',
         'dac.dacDataGrid.selectedItem.@hostName',
         'dac.dacDataGrid.selectedItem.@name',
         'dac.dacDataGrid.selectedItem.@description',
         'dac.dacDataGrid.selectedItem.@dbPassword',
     ]
     expected = []
     result = list(finder.find_emails(bogus))
     assert expected == result
Пример #12
0
def update_ignorables(licensish, verbose=False, dump=True):
    """
    Collect, update and save the ignorable_* attributes of a `licensish` Rule or
    License object.
    """
    location = licensish.text_file

    if verbose:
        print('Processing:', 'file://' + location)

    if not exists(location):
        return licensish

    # collect and set ignorable copyrights, holders and authors
    from cluecode.copyrights import detect_copyrights
    copyrights = set()
    holders = set()
    authors = set()

    for dtype, value, _start, _end in detect_copyrights(location):
        if dtype == 'copyrights':
            copyrights.add(value)
        elif dtype == 'holders':
            holders.add(value)
        elif dtype == 'authors':
            authors.add(value)

    licensish.ignorable_copyrights = sorted(copyrights)
    licensish.ignorable_holders = sorted(holders)
    licensish.ignorable_authors = sorted(authors)

    # collect and set ignrable emails and urls
    from cluecode.finder import find_urls
    from cluecode.finder import find_emails

    urls = set(u for (u, _ln) in find_urls(location) if u)
    licensish.ignorable_urls = sorted(urls)

    emails = set(u for (u, _ln) in find_emails(location) if u)
    licensish.ignorable_emails = sorted(emails)
    if dump:
        licensish.dump()
    return licensish
Пример #13
0
def get_emails(location, threshold=50, **kwargs):
    """
    Return a mapping with a single 'emails' key with a value that is a list of
    mappings for emails detected in the file at `location`.
    Return only up to `threshold` values. Return all values if `threshold` is 0.
    """
    from cluecode.finder import find_emails
    results = []

    found_emails = ((em, ln) for (em, ln) in find_emails(location) if em)
    if threshold:
        found_emails = islice(found_emails, threshold)

    for email, line_num in found_emails:
        result = OrderedDict()
        results.append(result)
        result['email'] = email
        result['start_line'] = line_num
        result['end_line'] = line_num
    return dict(emails=results)
Пример #14
0
 def test_find_emails3(self):
     test_file = self.get_test_loc('finder/email/thomas.py')
     expected = ['*****@*****.**']
     result = list(finder.find_emails(test_file))
     assert expected == result
Пример #15
0
 def test_find_emails6(self):
     bogus = ['user@...', 'thomas@...', '*@example.com', 'user@localhost']
     expected = []
     result = list(finder.find_emails(bogus))
     assert expected == result
Пример #16
0
 def test_find_emails3(self):
     test_file = self.get_test_loc('finder/email/thomas.py')
     expected = ['*****@*****.**']
     result = list(finder.find_emails(test_file))
     assert expected == result
Пример #17
0
 def test_find_emails2(self):
     test_file = self.get_test_loc('finder/email/jardiff.py')
     expected = ['*****@*****.**', ]
     result = list(finder.find_emails(test_file))
     assert expected == result
Пример #18
0
 def test_find_emails6(self):
     bogus = ['user@...', 'thomas@...', '*@example.com', 'user@localhost']
     expected = []
     result = list(finder.find_emails(bogus))
     assert expected == result
Пример #19
0
 def test_find_emails5(self):
     bogus = ['*****@*****.**', ]
     expected = []
     result = list(finder.find_emails(bogus))
     assert expected == result