<commit_before>#  Copyright 2016 <NAME>
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#

import os
import requests
import json
import re
import ldap
from flask import Flask

from flask import render_template
from flask import request
from flask import url_for
from flask import redirect
from flask import jsonify
from flask import make_response
from flask import Response
from flask import session

from flask_sso import SSO

app = Flask(__name__)
app.config.update(
    RESTURL = 'https://technical.edugain.org/isFederatedCheck/?format=json&data=',
    GREYLISTFILE = os.path.join(os.path.dirname(__file__),'grey.txt'),
    EDUGAIN_CHECK = True,
    SSO_ATTRIBUTE_MAP = {
        'eppn': (True, 'username'),
        'cn': (True, 'fullname'),
        'mail': (True, 'email'),
        'isMemberOf': (False, 'isMemberOf')
    }
)
app.config.from_pyfile('settings_local.py', silent=True)

app.config.setdefault('SSO_ATTRIBUTE_MAP', app.config['SSO_ATTRIBUTE_MAP'])
app.config.setdefault('SSO_LOGIN_URL', '/login')
ext = SSO(app=app)

class LDAPInterface(object):
    """Handle communication with the LDAP server."""

    def __init__(self):
        """connect to ldap on init"""
        self.con = ldap.initialize(app.config['LDAP_URL'])
        self.con.simple_bind_s(app.config['LDAP_USER'],app.config['LDAP_PASS'])

    def __exit__(self, *err):
        """disconnects from ldap on exit"""
        self.con.unbind_s()

    def getallmails():
        return self.con.search_s(app.config['LDAP_MAIL_SEARCH_BASE'], ldap.SCOPE_SUBTREE, filterstr='(mail=*)', attrlist=["mail"])

    def load_list(self,ldapdn):
        """Load a list from an ldap entry.

        Args:
            ldapdn (str): The DN of the ldap entry to load.

        Returns:
            list of str: Sorted array of domains in specified list.
        """
        obj=self.con.search_s(ldapdn, ldap.SCOPE_BASE, attrlist=["cNAMERecord"])<commit_msg>syntax fix<commit_after>#  Copyright 2016 <NAME>
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#

import os
import requests
import json
import re
import ldap
from flask import Flask

from flask import render_template
from flask import request
from flask import url_for
from flask import redirect
from flask import jsonify
from flask import make_response
from flask import Response
from flask import session

from flask_sso import SSO

app = Flask(__name__)
app.config.update(
    RESTURL = 'https://technical.edugain.org/isFederatedCheck/?format=json&data=',
    GREYLISTFILE = os.path.join(os.path.dirname(__file__),'grey.txt'),
    EDUGAIN_CHECK = True,
    SSO_ATTRIBUTE_MAP = {
        'eppn': (True, 'username'),
        'cn': (True, 'fullname'),
        'mail': (True, 'email'),
        'isMemberOf': (False, 'isMemberOf')
    }
)
app.config.from_pyfile('settings_local.py', silent=True)

app.config.setdefault('SSO_ATTRIBUTE_MAP', app.config['SSO_ATTRIBUTE_MAP'])
app.config.setdefault('SSO_LOGIN_URL', '/login')
ext = SSO(app=app)

class LDAPInterface(object):
    """Handle communication with the LDAP server."""

    def __init__(self):
        """connect to ldap on init"""
        self.con = ldap.initialize(app.config['LDAP_URL'])
        self.con.simple_bind_s(app.config['LDAP_USER'],app.config['LDAP_PASS'])

    def __exit__(self, *err):
        """disconnects from ldap on exit"""
        self.con.unbind_s()

    def getallmails(self):
        return self.con.search_s(app.config['LDAP_MAIL_SEARCH_BASE'], ldap.SCOPE_SUBTREE, filterstr='(mail=*)', attrlist=["mail"])

    def load_list(self,ldapdn):
        """Load a list from an ldap entry.

        Args:
            ldapdn (str): The DN of the ldap entry to load.

        Returns:
            list of str: Sorted array of domains in specified list.
        """
        obj=self.con.search_s(ldapdn, ldap.SCOPE_BASE, attrlist=["cNAMERecord"])
{'fraction_non_alphanumeric': 0.11264699814318135, 'fraction_numerical': 0.003301010934598721, 'mean_word_length': 3.6795366795366795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1939763', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1507, 'n_words': 460}