コード例 #1
0
ファイル: client.py プロジェクト: Cloudxtreme/DFS-1
    def from_cache(filepath):
        """Try to retrieve a file from the cache, the mode isn't specified,
           it's up to the user to deal with it, otherwise we may have multiple
           instance of the same file open in different mode.

           filepath: the path of the file to retrieve from cache.

           Return None if the file isn't in the cache or if the cache expired.
        """

        if filepath in File._cache:
            f = File._cache[filepath]

            host, port = utils.get_host_port(_config['nameserver'])
            fs = utils.get_server(filepath, host, port)
            host, port = utils.get_host_port(fs)

            with closing(HTTPConnection(host, port)) as con:
                con.request('HEAD', filepath)

                if (f.last_modified == con.getresponse().getheader(
                        'Last-Modified')):
                    f.seek(0)
                    return f
                else:
                    del File._cache[filepath]

        return None
コード例 #2
0
 def __init__(self, f_path, mode='rtc'):
     self.mode = mode
     self.f_path = f_path
     host, port = utils.get_host_port(_config['nameserver'])
     self.srv = utils.get_server(f_path, host, port)
     if self.srv is None:
         print('error')
コード例 #3
0
ファイル: client.py プロジェクト: Alexis-D/DFS
    def from_cache(filepath):
        """Try to retrieve a file from the cache, the mode isn't specified,
           it's up to the user to deal with it, otherwise we may have multiple
           instance of the same file open in different mode.

           filepath: the path of the file to retrieve from cache.

           Return None if the file isn't in the cache or if the cache expired.
        """

        if filepath in File._cache:
            f = File._cache[filepath]

            host, port = utils.get_host_port(_config['nameserver'])
            fs = utils.get_server(filepath, host, port)
            host, port = utils.get_host_port(fs)

            with closing(HTTPConnection(host, port)) as con:
                con.request('HEAD', filepath)

                if (f.last_modified ==
                        con.getresponse().getheader('Last-Modified')):
                    f.seek(0)
                    return f
                else:
                    del File._cache[filepath]

        return None
コード例 #4
0
ファイル: XAIF.py プロジェクト: kanika901/lighthouse
 def submit1(self,xaif_string):
     try:
         host,port = get_server("r_xaif")
         self.init_socket(host,port)
         # send message header
         user_id = "XAIF"
         filename = "default"
         options = "no_options "+filename
         self.send_header([user_id,options,"1"])
         # send data
         self.send1(filename,xaif_string)
     except:
        print "error while submitting request"
        sys.exit(1)
     try:
         # receive response 
         nfiles = int(self.recv_header1())
         r_list = []
         for i in range(0,nfiles):
             f,d = self.recv1()
             r_list.append((f,d))
     except:
         print "error while collecting results"
         sys.exit(1)
     else:
         return r_list
コード例 #5
0
async def welcome_member(client, member):
    logging.info(f"Welcoming member {member_to_string(member)}.")

    welcome_survey_status = db.get_user_survey_progress_status_or_none(
        WELCOME_SURVEY_ID, member.id)
    if welcome_survey_status in [
            survey_status.FINISHED,
            survey_status.FINISHED_CHANNEL_DELETED,
    ]:
        logging.info(
            f"{member_to_string(member)} already finished welcome survey.")
        await survey.add_receive_role_if_exists(client, member,
                                                WELCOME_SURVEY_ID)
        return

    if welcome_survey_status == survey_status.IN_PROGRESS:
        logging.info(
            f"{member_to_string(member)} has already started survey once. Clearing old survey data."
        )
        db.clear_all_user_survey_progress(WELCOME_SURVEY_ID, member.id)

    channel = await survey.create_channel(get_server(client), member,
                                          f"vitaj {member.display_name}")

    intro_message = db.get_survey_intro_message(WELCOME_SURVEY_ID)
    await survey.send_welcome_message(channel, member, intro_message)

    db.create_user_survey_progress(WELCOME_SURVEY_ID, member.id, channel.id)
    await survey.send_next_question(channel, member, WELCOME_SURVEY_ID)
コード例 #6
0
ファイル: oxford.py プロジェクト: lbugnon/PFC_DGIdb_src
 def handle_starttag(self, tag, attrs):
     if tag == "span" and ("class", "pdf-link-text") in attrs:
         for attr in self.a_attrs:
             if attr[0] == "href":
                 self.the_url = utils.get_server(
                     self.url) + urllib.parse.unquote(attr[1])
     if tag == "a":
         self.a_attrs = attrs
コード例 #7
0
ファイル: springer.py プロジェクト: lbugnon/PFC_DGIdb_src
 def handle_starttag(self, tag, attrs):
     if self.process and tag == "a" and ("data-track-action",
                                         "Pdf download") in attrs:
         for attr in attrs:
             if attr[0] == "href":
                 self.the_url = utils.get_server(
                     self.url) + urllib.parse.unquote(attr[1])
                 self.process = False
コード例 #8
0
ファイル: core.py プロジェクト: andresPanyakin/test
	def run(self,server=None, port=None):

		if server and port:
			ip_port = (server,port)
		else:
			ip_port = utils.get_server(self.__server,self.__port)
		self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
		self.log(logging.INFO, "Connecting to %s:%s..." % ip_port)
		self.connect(ip_port)
コード例 #9
0
ファイル: ClientServer.py プロジェクト: juyalnikita/DFS
 def cache(filepath):
    if filepath in File._cache:
        filec = File._cache[filepath] #stores filepath that is to be retrieved from cache
        host, port = utils.get_host_port(_config['nameserver'])
        fs = utils.get_server(filepath, host, port)
        host, port = utils.get_host_port(fs)
        
        with closing(HTTPConnection(host, port)) as con:
            con.request('HEAD', filepath)
          
            if (f.last_modified ==con.getresponse().getheader('Last-Modified')):
                return f
コード例 #10
0
    def __init__(self, filepath, mode='rtc'):
        print("FilePath", filepath)
        print("FilePath", mode)
        #self.mode = mode
        #self.filepath = filepath

        host, port = utils.get_host_port(_config['nameserver'])
        self.srv = utils.get_server(filepath, host, port)
        print(self.srv)

        print("FilePath", filepath)
        print("FilePath", mode)

        if self.srv is None:
            raise DFSIOError('Could not find a server that serves :', filepath)

        self.last_modified = None
        SpooledTemporaryFile.__init__(
            self, _config['max_size'],
            mode.replace('c', ''))  #mode 'c' meaning store in cache

        host, port = utils.get_host_port(_config['lockserver'])
        if utils.is_locked(filepath, host, port):
            raise DFSIOError('The file %s is locked.' % filepath)

        if 'w' not in mode:
            print(type(self.srv))
            host, port = utils.get_host_port(self.srv.decode('UTF-8'))
            with closing(HTTPConnection(host, port)) as con:
                con.request('GET', filepath)
                response = con.getresponse()
                self.last_modified = response.getheader('Last-Modified')
                status = response.status
                print(status)

                if status not in (200, 204):
                    raise DFSIOError('Error (%d) while opening file.' % status)

                if status != 204:
                    self.write(response.read())

                if 'r' in mode:
                    self.seek(0)

                self.lock_id = None

        if 'a' in mode or 'w' in mode:
            # automatically gets a lock if we're in write/append mode
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(filepath, host, port))

        if 'c' in mode:
            File._cache[filepath] = self
コード例 #11
0
ファイル: main.py プロジェクト: StreetOfCode/discord-bot
async def on_raw_reaction_remove(payload):
    guild = get_server(client)
    if payload.user_id != guild.me.id:
        if (survey_id := db.get_survey_id_from_user_survey_progress_or_none(
                payload.user_id, payload.channel_id)) is not None:
            if (question_id := db.get_survey_question_id_or_none(
                    payload.message_id)) is not None:
                await remove_reaction_on_survey_answer(
                    user_id=payload.user_id,
                    survey_id=survey_id,
                    question_id=question_id,
                    emoji=payload.emoji,
                )
コード例 #12
0
def unlink(path, lock_id=None):
    host, port = utils.get_host_port(_config['nameserver'])

    fs = utils.get_server(path, host, port)
    host, port = utils.get_host_port(fs)

    with closing(HTTPConnection(host, port)) as con:
        con.request('DELETE', path + '?lock_id=%s' % lock_id)

        status = con.getresponse().status

        if status != 200:
            pass
コード例 #13
0
ファイル: client.py プロジェクト: Cloudxtreme/DFS-1
    def __init__(self, filepath, mode='rtc'):
        """filepath: the path of the distant file
           mode: take the same argument as mode argument of the global
                 open() + optional flag c (which mean store in cache).
        """

        self.mode = mode
        self.filepath = filepath
        host, port = utils.get_host_port(_config['nameserver'])
        self.srv = utils.get_server(filepath, host, port)

        if self.srv is None:
            raise DFSIOError('Impossible to find a server that serve %s.' %
                             filepath)

        self.last_modified = None
        SpooledTemporaryFile.__init__(self, _config['max_size'],
                                      mode.replace('c', ''))

        host, port = utils.get_host_port(_config['lockserver'])
        if utils.is_locked(filepath, host, port):
            raise DFSIOError('The file %s is locked.' % filepath)

        if 'w' not in mode:
            host, port = utils.get_host_port(self.srv)
            with closing(HTTPConnection(host, port)) as con:
                con.request('GET', filepath)
                response = con.getresponse()
                self.last_modified = response.getheader('Last-Modified')
                status = response.status

                if status not in (200, 204):
                    raise DFSIOError('Error (%d) while opening file.' % status)

                if status != 204:
                    self.write(response.read())

                if 'r' in mode:
                    self.seek(0)

                self.lock_id = None

        if 'a' in mode or 'w' in mode:
            # automatically gets a lock if we're in write/append mode
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(filepath, host, port))

        if 'c' in mode:
            File._cache[filepath] = self
コード例 #14
0
ファイル: client.py プロジェクト: Alexis-D/DFS
    def __init__(self, filepath, mode='rtc'):
        """filepath: the path of the distant file
           mode: take the same argument as mode argument of the global
                 open() + optional flag c (which mean store in cache).
        """

        self.mode = mode
        self.filepath = filepath
        host, port = utils.get_host_port(_config['nameserver'])
        self.srv = utils.get_server(filepath, host, port)

        if self.srv is None:
            raise DFSIOError('Impossible to find a server that serve %s.'
                    % filepath)

        self.last_modified = None
        SpooledTemporaryFile.__init__(self, _config['max_size'], mode.replace('c', ''))

        host, port = utils.get_host_port(_config['lockserver'])
        if utils.is_locked(filepath, host, port):
            raise DFSIOError('The file %s is locked.' % filepath)

        if 'w' not in mode:
            host, port = utils.get_host_port(self.srv)
            with closing(HTTPConnection(host, port)) as con:
                con.request('GET', filepath)
                response = con.getresponse()
                self.last_modified = response.getheader('Last-Modified')
                status = response.status

                if status not in (200, 204):
                    raise DFSIOError('Error (%d) while opening file.' % status)

                if status != 204:
                    self.write(response.read())

                if 'r' in mode:
                    self.seek(0)

                self.lock_id = None

        if 'a' in mode or 'w' in mode:
            # automatically gets a lock if we're in write/append mode
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(filepath, host, port))

        if 'c' in mode:
            File._cache[filepath] = self
コード例 #15
0
 async def send_welcome_survey(self, ctx):
     """
     Only member with admin role can run this command
     Command sends welcome survey to all users who hasn't started survey and don't have admin role
     """
     sent_to = []
     logging.info("Executing send-welcome-survey command.")
     users_who_started_survey = db.get_all_user_ids_from_survey_progress(
         WELCOME_SURVEY_ID
     )
     for member in get_server(self.bot).members:
         if member != self.bot.user and member.id not in users_who_started_survey:
             if discord.utils.get(member.roles, id=ADMIN_ROLE_ID) is None:
                 await welcome_member(self.bot, member)
                 sent_to.append(member.display_name)
     await ctx.channel.send(f"Sent to {sent_to}")
コード例 #16
0
def unique_sources(data_file):
    """data_file es un archivo de salida de base_pubmed.py, siendo cada línea 'pmid url'."""
    sources = {}
    with open(data_file) as f:
        for l in f:
            base_url = utils.get_server(l.split(" ")[1])
            if not base_url: continue
            if not base_url in sources:
                sources[base_url] = 0
            sources[base_url] += 1
        print("Fuentes distintas:", len(sources))
        print("Artículos en cada una:")
        for x in sorted(list(sources.items()),
                        key=lambda x: x[1],
                        reverse=True):
            print(x[0] + ":", x[1])
コード例 #17
0
def unlink(filepath, lock_id=None):
    """Delete the file from the filesystem.
       If lock_id is provided, it's used to delete the file."""

    host, port = utils.get_host_port(config['nameserver'])
    fs = utils.get_server(filepath, host, port)
    host, port = utils.get_host_port(fs)

    with closing(http.client(host, port)) as con:
        con.request('DELETE', filepath + '?lock_id=%s' % lock_id)

        status = con.getresponse().status

        if status != 200:
            raise DFSError('Error (%d) while deleting %s.' %
                           (status, filepath))
コード例 #18
0
ファイル: main.py プロジェクト: StreetOfCode/discord-bot
async def on_raw_reaction_add(payload):
    guild = get_server(client)
    if payload.member.id != guild.me.id:
        if (survey_id := db.get_survey_id_from_user_survey_progress_or_none(
                payload.member.id, payload.channel_id)) is not None:
            if (question_id := db.get_survey_question_id_or_none(
                    payload.message_id)) is not None:
                channel = await client.fetch_channel(payload.channel_id)
                message = await channel.fetch_message(payload.message_id)
                await add_reaction_on_survey_answer(
                    client=client,
                    member=payload.member,
                    survey_id=survey_id,
                    question_id=question_id,
                    emoji=payload.emoji,
                    message=message,
                )
コード例 #19
0
    async def send_survey(self, ctx, survey_id):
        """
        Only member with admin role can run this command
        Command sends survey (id of survey in first parameter) to all users who are survey-fans
        (They answered in welcome quiz that they are ok with sending more surveys)
        """

        logging.info(f"Executing send-survey command for survey_id {survey_id}")

        if db.check_survey_exists(survey_id):
            survey_fans = db.find_all_answer_alias_responders("survey-fan")
            users_who_started_survey = db.get_all_user_ids_from_survey_progress(
                survey_id
            )
            final_users_to_send_survey_to = list(
                set(survey_fans) - set(users_who_started_survey)
            )

            sent_to = []
            for user_id in final_users_to_send_survey_to:
                member = get_member(self.bot, user_id)
                if member is None:
                    # member does not longer exist
                    continue

                channel_name = f"{member.display_name}-{db.get_survey_channel_name_suffix(survey_id)}"
                channel = await create_channel(
                    get_server(self.bot), member, channel_name
                )

                intro_message = db.get_survey_intro_message(survey_id)
                await send_welcome_message(channel, member, intro_message)

                db.create_user_survey_progress(survey_id, member.id, channel.id)
                await send_next_question(channel, member, survey_id)

                sent_to.append(member.display_name)

            await ctx.channel.send(f"Sent to {sent_to}")

        else:
            logging.info(
                f"Calling send-survey command for survey_id {survey_id}, but this survey doesn't exist"
            )
            await ctx.channel.send(f"Survey with id {survey_id} wasn't found")
コード例 #20
0
def unlink(filepath, lock_id=None):
    """Delete the file from the filesystem (if possible).
       If lock_id is provided, it's used to delete the file."""

    # ns
    host, port = utils.get_host_port(_config['nameserver'])
    # fs
    fs = utils.get_server(filepath, host, port)
    host, port = utils.get_host_port(fs)

    with closing(HTTPConnection(host, port)) as con:
        con.request('DELETE', filepath + '?lock_id=%s' % lock_id)

        status = con.getresponse().status

        if status != 200:
            raise DFSIOError('Error (%d) while deleting %s.' %
                             (status, filepath))
コード例 #21
0
ファイル: client.py プロジェクト: Alexis-D/DFS
def unlink(filepath, lock_id=None):
    """Delete the file from the filesystem (if possible).

       If lock_id is provided, it's used to delete the file."""

    # ns
    host, port = utils.get_host_port(_config['nameserver'])
    # fs
    fs = utils.get_server(filepath, host, port)
    host, port = utils.get_host_port(fs)

    with closing(HTTPConnection(host, port)) as con:
        con.request('DELETE', filepath + '?lock_id=%s' % lock_id)

        status = con.getresponse().status

        if status != 200:
            raise DFSIOError('Error (%d) while deleting %s.' %
                             (status, filepath))
コード例 #22
0
ファイル: ClientServer.py プロジェクト: juyalnikita/DFS
    def __init__(self, filepath, mode='rtc'):
        

        self.mode = mode
        self.filepath = filepath
        host, port = utils.get_host_port(_config['nameserver'])
        self.srv = utils.get_server(filepath, host, port)
        
        
        self.last_modified = None
        
        SpooledTemporaryFile.__init__(self, _config['max_size'], mode.replace('c',''))

        host, port = utils.get_host_port(_config['lockserver'])
        if utils.is_locked(filepath, host, port):
            raise DFSIOError('The file %s is locked.' % filepath)

        if 'w' not in mode:
            host, port = utils.get_host_port(self.srv)
            with closing(HTTPConnection(host, port)) as con:
                con.request('GET', filepath)
                response = con.getresponse()
                self.last_modified = response.getheader('Last-Modified')
                status = response.status

                if status not in (200, 204):
                    raise DFSIOError('Error (%d)while opening file.' % status)

                if status != 204:
                    self.write(response.read())

                if 'r' in mode:
                    self.seek(0)

                self.lock_id = None

        if 'a' in mode or 'w' in mode: # automatically lock file if appending or writing in file
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(filepath, host, port))

        if 'c' in mode:
            File._cache[filepath] = self        
コード例 #23
0
    def from_cache(filepath):
        """save file in local disk"""
        if filepath in File._cache:
            f = File._cache[filepath]

            host, port = utils.get_host_port(config['nameserver'])
            fs = utils.get_server(filepath, host, port)
            host, port = utils.get_host_port(fs)

            with closing(http.client(host, port)) as con:
                con.request('HEAD', filepath)

                if (f.last_modified == con.getresponse().getheader(
                        'Last-Modified')):
                    f.seek(0)
                    return f
                else:
                    del File._cache[filepath]

        return None
コード例 #24
0
    def __init__(self, client, ctx, location, hcchannel, raiderrole, rlrole,
                 is_US):
        self.client = client
        self.ctx = ctx
        self.guild_db = self.client.guild_db.get(self.ctx.guild.id)
        self.queuechannel = self.client.queue_links[hcchannel.category.id][0]
        self.category = self.client.queue_links[hcchannel.category.id][1]
        self.hcchannel = hcchannel
        self.raiderrole = raiderrole
        self.rlrole = rlrole
        self.location = location
        self.meetup = utils.get_server(is_US)
        self.raid_vc = None
        self.in_run = False
        self.max_patreons = 6

        self.raiderids = set()
        self.confirmed_raiders = {}
        self.confirmed_priority = {}
        self.raiderids.add(ctx.author.id)
        self.nitroboosters = []
        self.patreons = []
        self.last_edited = datetime.utcnow()
        self.awaiting_confirmations = set()

        self.firstpopperrole = self.guild_db[sql.gld_cols.firstpopperrole]
        self.secondpopperrole = self.guild_db[sql.gld_cols.secondpopperrole]
        self.thirdpopperrole = self.guild_db[sql.gld_cols.thirdpopperrole]
        self.firstrunerole = self.guild_db[sql.gld_cols.runepopper1role]
        self.secondrunerole = self.guild_db[sql.gld_cols.runepopper2role]
        self.firstruneearlyloc = True if self.guild_db[
            sql.gld_cols.runepopper1loc] == 1 else False
        self.secondruneearlyloc = True if self.guild_db[
            sql.gld_cols.runepopper2loc] == 1 else False
        self.firstpopperearlyloc = True if self.guild_db[
            sql.gld_cols.firstpopperearlyloc] == 1 else False
        self.secondpopperearlyloc = True if self.guild_db[
            sql.gld_cols.secondpopperearlyloc] == 1 else False
        self.thirdpopperearlyloc = True if self.guild_db[
            sql.gld_cols.thirdpopperearlyloc] == 1 else False
コード例 #25
0
    def __init__(self, path, mode='rtc'):

        self.mode = mode
        self.path = path
        host, port = utils.get_host_port(_config['nameserver'])
        self.srv = utils.get_server(path, host, port)

        if self.srv is None:
            pass

        self.last_modified = None
        SpooledTemporaryFile.__init__(self, _config['max_size'],
                                      mode.replace('c', ''))

        host, port = utils.get_host_port(_config['lockserver'])
        if utils.is_locked(path, host, port):
            pass

        if 'w' not in mode:
            host, port = utils.get_host_port(self.srv)
            with closing(HTTPConnection(host, port)) as con:
                con.request('GET', path)
                response = con.getresponse()
                self.last_modified = response.getheader('Last-Modified')
                status = response.status

                if status != 204:
                    self.write(response.read())

                if 'r' in mode:
                    self.seek(0)

                self.lock_id = None

        if 'a' in mode or 'w' in mode:
            host, port = utils.get_host_port(_config['lockserver'])
            self.lock_id = int(utils.get_lock(path, host, port))

        if 'c' in mode:
            File._cache[path] = self
コード例 #26
0
ファイル: httpapi.py プロジェクト: jibanli/sloth
 def set_server(self, servername):
     server = utils.get_server(servername)
     self.__server = 'http://%s:%d' % (server['ip'], server['port'])
     self.__session = requests.Session()
コード例 #27
0
ファイル: httpapi.py プロジェクト: jibanli/sloth
 def __init__(self, servername, username):
     server = utils.get_server(servername)
     self.__server = 'http://%s:%d' % (server['ip'], server['port'])
     user = utils.get_user(username)
     self.__auth = (user['username'], user['password'])
     self.__session = requests.Session()
コード例 #28
0
ファイル: adic_client.py プロジェクト: aMiss-aWry/ADserver
#!/usr/bin/python
# ADIC client program
#
# usage is the same as for "adiC" with additional
# required option "--username", e.g.:
# adic_client.py --username=nobody -vd gradient f.c
#
import sys, glob, socket
from ADIC import ADIC_Client
from utils import uniq, get_username, include_files, get_server, string

adic = ADIC_Client()
username, args = get_username(sys.argv[1:])
options,files = adic.check_options(args)
reduce(lambda x, y: x+y,map(glob.glob, files),[])      # expand unix wildcards 
files = uniq(include_files(files,adic.LanguageClass))  # add include files
try:
    host,port = get_server("r_adic")
except socket.error:
    sys.exit(1)
else:
    print adic.submit_request(host,port,username,string.join(options),files)

コード例 #29
0
ファイル: adic_client.py プロジェクト: kanika901/lighthouse
#!/usr/bin/python
# ADIC client program
#
# usage is the same as for "adiC" with additional
# required option "--username", e.g.:
# adic_client.py --username=nobody -vd gradient f.c
#
import sys, glob, socket
from ADIC import ADIC_Client
from utils import uniq, get_username, include_files, get_server, string

adic = ADIC_Client()
username, args = get_username(sys.argv[1:])
options, files = adic.check_options(args)
reduce(lambda x, y: x + y, map(glob.glob, files), [])  # expand unix wildcards
files = uniq(include_files(files, adic.LanguageClass))  # add include files
try:
    host, port = get_server("r_adic")
except socket.error:
    sys.exit(1)
else:
    print adic.submit_request(host, port, username, string.join(options),
                              files)
コード例 #30
0
def setUpModule():
    global server_ip
    server_ip = utils.get_server()