def __init__(self, name, creator=None, ts=None): new = ts == None #if we are making a new channel self.name = name self.ts = int(ts) if ts != None else int(time.time()) self.clients = {} self.metadata = {} self.lists = { LIST_BAN: CaseInsensitiveDict(), LIST_QUIET: CaseInsensitiveDict(), LIST_EXCEPT: CaseInsensitiveDict(), LIST_INVEX: CaseInsensitiveDict(), } self.limit = None self.key = None self.throttle = None self.properties = PROP_NONE if new: self.topic = Topic("", creator) self.metadata["CREATOR"] = creator.account if creator.account != "*" \ else creator.nick else: self.topic = Topic("", client.Client(nick="server"))
def create_engine(**kwargs): """Create database engine from kwargs. create_engine(engine='db.mysql', user='******', password='******') """ global db if db and db.driver: raise DBError("Database engine has already initialized!") kwargs = CaseInsensitiveDict(**kwargs) engine = kwargs.pop('ENGINE') if isinstance(engine, basestring): engine = load_module(engine) db = engine(**kwargs) return db
def __init__(self, poller): self.backref = {} self.clients = {} self.modules = {} self.channels = CaseInsensitiveDict() self.commands = CaseInsensitiveDict() self.poller = poller self.serverlinks = [] self.sname = "duta.yolo-swag.com" self.gecos = "Today's tech tomorrow" self.sid = "420" self.password = "******" self.netname = "ShadowNET" self.last_uid = 60466176 # 100000 in base 36
def __init__(self, request): super(WebServerRequest, self).__init__() self.setObjectName('WebServerRequest') self.m_request = request self.m_headerNames = list(request.headers) self.m_headers = CaseInsensitiveDict(request.headers) self.m_numHeaders = len(request.headers) do_action('WebServerRequestInit')
def handle_one_request(self): '''Handle a single HTTP request. A patch to the request handling: * This removes the functionality which calls do_X(), and simply calls our handleRequest() directly. * If do_X() didn't exist, a 501 unsupported method error would be returned. Since we patched that out as well, the user can actually handle when a request is or isn't valid through the code. * Then we handle the request and response. ''' try: self.raw_requestline = self.rfile.readline(65537) if len(self.raw_requestline) > 65536: self.requestline = '' self.request_version = '' self.command = '' self.send_error(414) return if not self.raw_requestline: self.close_connection = 1 return if not self.parse_request(): # An error code has been sent, just exit return # these variables must get (re)set on every request # for handleRequest(), due to the HTTP/1.1 nature of # keepalive, which seems to keep a constant running # instance of this class self.m_handleResponse = True self.m_headers = CaseInsensitiveDict() self.m_statusCode = 200 self.m_wfile = StringIO() self.handleRequest() # some methods handle the response on their own instead if self.m_handleResponse: self.handleResponse() self.wfile.flush( ) #actually send the response if not already done. except socket.timeout, e: #a read or a write timed out. Discard this connection self.log_error("Request timed out: %r", e) self.close_connection = 1 return
def __init__(self): super().__init__(command_prefix='yt ', description=config.description, pm_help=None, game=discord.Game(name='yt help')) self.all_commands = CaseInsensitiveDict(self.all_commands) self.add_check(_check) self.youtube_key = config.youtube_key self.session = aiohttp.ClientSession(loop=self.loop) self.process = psutil.Process() startup_extensions = [x.stem for x in Path('cogs').glob('*.py')] for extension in startup_extensions: try: self.load_extension(f'cogs.{extension}') except: print(f'Failed to load extension {extension}.') traceback.print_exc() self.loop.create_task(self.init())
class Parent: def __init__(self, poller): self.backref = {} self.clients = {} self.modules = {} self.channels = CaseInsensitiveDict() self.commands = CaseInsensitiveDict() self.poller = poller self.serverlinks = [] self.sname = "duta.yolo-swag.com" self.gecos = "Today's tech tomorrow" self.sid = "420" self.password = "******" self.netname = "ShadowNET" self.last_uid = 60466176 # 100000 in base 36 def legal_nick(self, nick): #TODO: FIXME return True def legal_ident(self, ident): #TODO: FIXME return True def gen_uid(self): uid = base36encode(self.last_uid) self.last_uid = self.last_uid + 1 return self.sid + uid def add_channel(self, chname, creator=None, ts=None): chans = [n.lower() for n in self.channels.keys()] if chname.lower not in chans: chan = channel.Channel(chname, creator, ts) self.channels[chname] = chan return chan else: return self.channels[chname] def add_client(self, client): if client.uid.startswith(self.sid): for server in self.serverlinks: server.burst_client(client) if client.uid not in self.clients.keys(): self.clients[client.uid] = client return client else: return False def add_command(self, impl): verb = impl.verb if verb not in self.commands: self.commands[verb] = impl def init_command(self, name): #HACK: TODO: replace me! mod = importlib.import_module("commands.client.%s" % name) mod.init_module(self) def init_commands(self): for command in ["login", "info", "join", "message"]: self.init_command(command) def quit_client(self, client, reason): for uplink in self.serverlinks: uplink.quit_client(client, reason) if client.uid.startswith(self.sid): client.send_line("ERROR :Closing link: killed: %s" % reason) client._send_line() clients = set() for channel in client.channels: clients.update([ e.client for e in channel.channel.clients.values() if e.client.local ]) del channel.channel.clients[client.uid] for myclient in clients: myclient.send_line(":%s QUIT :%s" % (client.uid, reason)) del self.clients[client.uid] del client def sendto_servers(self, message): for server in self.serverlinks: server.send_line(message)
def __init__(self, headers, defaults=False): self.version = "WARC/0.18" CaseInsensitiveDict.__init__(self, headers) if defaults: self.init_defaults()
class Parent: def __init__(self, poller): self.backref = {} self.clients = {} self.modules = {} self.channels = CaseInsensitiveDict() self.commands = CaseInsensitiveDict() self.poller = poller self.serverlinks = [] self.sname = "duta.yolo-swag.com" self.gecos = "Today's tech tomorrow" self.sid = "420" self.password = "******" self.netname = "ShadowNET" self.last_uid = 60466176 # 100000 in base 36 def legal_nick(self, nick): #TODO: FIXME return True def legal_ident(self, ident): #TODO: FIXME return True def gen_uid(self): uid = base36encode(self.last_uid) self.last_uid = self.last_uid + 1 return self.sid + uid def add_channel(self, chname, creator=None, ts=None): chans = [n.lower() for n in self.channels.keys()] if chname.lower not in chans: chan = channel.Channel(chname, creator, ts) self.channels[chname] = chan return chan else: return self.channels[chname] def add_client(self, client): if client.uid.startswith(self.sid): for server in self.serverlinks: server.burst_client(client) if client.uid not in self.clients.keys(): self.clients[client.uid] = client return client else: return False def add_command(self, impl): verb = impl.verb if verb not in self.commands: self.commands[verb] = impl def init_command(self, name): #HACK: TODO: replace me! mod = importlib.import_module("commands.client.%s" % name) mod.init_module(self) def init_commands(self): for command in ["login", "info", "join", "message"]: self.init_command(command) def quit_client(self, client, reason): for uplink in self.serverlinks: uplink.quit_client(client, reason) if client.uid.startswith(self.sid): client.send_line("ERROR :Closing link: killed: %s" % reason) client._send_line() clients = set() for channel in client.channels: clients.update([e.client for e in channel.channel.clients.values() if e.client.local]) del channel.channel.clients[client.uid] for myclient in clients: myclient.send_line(":%s QUIT :%s" % (client.uid, reason)) del self.clients[client.uid] del client def sendto_servers(self, message): for server in self.serverlinks: server.send_line(message)
def writeHead(self, code, headers): self.m_conn.m_statusCode = code self.m_conn.m_headers = CaseInsensitiveDict(headers)
def headers(self, headers): self.m_conn.m_headers = CaseInsensitiveDict(headers)
def request(self, method, url, header_auth=False, realm='', **req_kwargs): ''' A loose wrapper around Requests' :class:`~requests.sessions.Session` which injects OAuth 1.0/a parameters. :param method: A string representation of the HTTP method to be used. :type method: str :param url: The resource to be requested. :type url: str :param header_auth: Authentication via header, defaults to `False.` :type header_auth: bool :param realm: The auth header realm, defaults to ``""``. :type realm: str :param \*\*req_kwargs: Keyworded args to be passed down to Requests. :type \*\*req_kwargs: dict ''' req_kwargs.setdefault('headers', {}) req_kwargs['headers'] = CaseInsensitiveDict(req_kwargs['headers']) url = self._set_url(url) entity_method = method.upper() in ENTITY_METHODS if entity_method and not req_kwargs.get('files', None): req_kwargs['headers'].setdefault('Content-Type', FORM_URLENCODED) form_urlencoded = \ req_kwargs['headers'].get('Content-Type') == FORM_URLENCODED # inline string conversion if is_basestring(req_kwargs.get('params')): req_kwargs['params'] = dict(parse_qsl(req_kwargs['params'])) if is_basestring(req_kwargs.get('data')) and form_urlencoded: req_kwargs['data'] = dict(parse_qsl(req_kwargs['data'])) req_kwargs.setdefault('timeout', OAUTH1_DEFAULT_TIMEOUT) oauth_params = self._get_oauth_params(req_kwargs) # ensure we always create new instances of dictionary elements for key, value in req_kwargs.items(): if isinstance(value, dict): req_kwargs[key] = deepcopy(value) # sign the request oauth_params['oauth_signature'] = \ self.signature.sign(self.consumer_secret, self.access_token_secret, method, url, oauth_params, req_kwargs) if header_auth and 'oauth_signature' not in \ req_kwargs['headers'].get('Authorization', ''): req_kwargs['auth'] = OAuth1Auth(oauth_params, realm) elif entity_method and 'oauth_signature' not in \ (req_kwargs.get('data') or {}): req_kwargs['data'] = req_kwargs.get('data') or {} # If we have a urlencoded entity-body we should pass the OAuth # parameters on this body. However, if we do not, then we need to # pass these over the request URI, i.e. on params. # # See: # # http://tools.ietf.org/html/rfc5849#section-3.5.2 # # and: # # http://tools.ietf.org/html/rfc5849#section-3.5.3 if form_urlencoded: req_kwargs['data'].update(oauth_params) else: req_kwargs.setdefault('params', {}) req_kwargs['params'].update(oauth_params) elif 'oauth_signature' not in url: req_kwargs.setdefault('params', {}) req_kwargs['params'].update(oauth_params) return super(OAuth1Session, self).request(method, url, **req_kwargs)