def test_domain_name(self): url1 = "https://github.com/joshcoales" assert Commons.get_domain_name(url1) == "github", "Failed to get domain from url1" url2 = "http://spangle.org.uk/things/stuff/hallo.html.com" assert Commons.get_domain_name(url2) == "spangle", "Failed to get domain from url2" url3 = "irc://irc.freenode.net:6666" assert Commons.get_domain_name(url3) == "freenode", "Failed to get domain from url3" url4 = "http://www.longurlmaker.com/go?id=143GetShortyShrtndspread%2Bout1tprotractedlongishYepItlofty1stretch" \ "100RedirxMyURL1Sitelutionsspread%2Bout56706Ne1kfar%2Breachingstretchenlarged8U76SimURL01URLvi00distan" \ "tr1towering46URLcutNe14m3q5stringy0elongatedremote7RubyURLRubyURL0300lasting52ny54blnk.inRedirx0t0aks" \ "tretchedst765330DigBigf14922f8014v03121qeURl.ied99FhURL1MyURLFhURL8sustainedlingeringrunning07bYATUC6" \ "8yU7618farawaystretchedxlfarawaySHurlcU760stretched01drangyccmstretchkrunningrremote52ganglingMyURL81" \ "outstretchedTraceURL5aenduring60Is.gd5stretch69660Miniliengangling112vYATUC01drawn%2Bout29extensive1U" \ "RLcutc03ShredURLfspread%2Boutoutstretched1EzURLTinyURLhigh0301URL7WapURL0u7Redirx5229NutshellURLdrawn" \ "%2Boutwcfy68rangy4longish4SitelutionsG8LFwdURLe1stretchNanoRef56running2StartURLspun%2BoutShortURL165" \ "MooURL4bTightURL00URLPieprolongedWapURLw0TightURL61runningdistantShorl8951hw2MooURLelongatek8lofty1Ti" \ "nyURLc1qMetamark920bgelongate19n103c1dTinyLinkcontinuedlnk.in96591DecentURL0afar%2Breaching81elongish" \ "504zremotec0l0e0adistants11high04DecentURL2stretchYATUCSnipURLstringys7b8deepTightURL1PiURLpa7elongat" \ "edix0101Shim0Is.gdfar%2BreachingB65f8ctoweringNutshellURLWapURL1v9runningRubyURLURl.ie0ganglingEasyUR" \ "L1ShortURL161stringy0h8extensivePiURL14prolongedEzURLt710distant1100rNanoRefh5311450ShrinkURLFwdURL1m" \ "stretched119ganglingURLCuttera11fFhURL1b6tallFwdURLdlengthy110spun%2Bout7lastingf49Fly29loftyf5jXil0s" \ "pread%2Bout4lengthyrangystretch8up0URL.co.uklingeringegURLHawk48zlengthyb3prolonged58loftyg18drawn%2B" \ "outURLCutterURLHawk01cShortlinkshigh4remote1StartURLprolongedURLHawk0z03Shortlinks54gURLvi18elongated" \ "EasyURL18elongated04WapURL1lofty51spread%2Bout1Redirx1A2N5411zfar%2Breachingf001prolonged01a4dstretch" \ "sustainedoutstretchedShortURL612TraceURLURLvi00lasting28ec1URLcutcstringy827klengthyk1141DigBig9fcSHu" \ "rl1Beam.toShorl0tstretchxURLCutterYepItnblasting080stretched1FhURL15rangy1x6600continuedShredURLblnk." \ "inelongated00413outstretched0090146stretched589z05stringyc8sdielongatelongish6kprolongedfar%2Breachin" \ "gf36ubaTinyURL1TinyLink341028017EasyURLd1runningfar%2Breaching06stretching1U76spun%2Bout1cstretch" assert Commons.get_domain_name(url4) == "longurlmaker", "Failed to get domain from url4" url5 = "http://domains.ninja" assert Commons.get_domain_name(url5) == "domains", "Failed to get domain from url5"
def connect_to_new_server_irc(self, line, user_obj, destination_obj): """ Processes arguments in order to connect to a new IRC server :type line: str :type user_obj: Destination.User :type destination_obj: Destination.Destination """ # Get some handy objects current_server = user_obj.get_server() hallo_obj = current_server.get_hallo() # Set all variables to none as default server_address, server_port = None, None server_name = None # Find the URL, if specified url_regex = re.compile("(^|\s)(irc://)?(([a-z.]+\.[a-z]+)(:([0-9]+))?)(\s|$)", re.IGNORECASE) url_search = url_regex.search(line) if url_search is not None: line = line.replace(url_search.group(0), " ") server_address = url_search.group(4).lower() try: server_port = int(url_search.group(6)) except (ValueError, TypeError): server_port = None # Find the server_address, if specified with equals notation server_address = Commons.find_parameter("server_address", line) or server_address # Find the server_port, if specified with equals notation server_port_param = Commons.find_parameter("server_port", line) if server_port_param is not None: try: server_port = int(server_port_param) except (ValueError, TypeError): return "Error, invalid port number." # Check server_address and server_port are set if server_address is None: return "Error, No server address specified." if server_port is None and isinstance(current_server, ServerIRC): server_port = current_server.get_server_port() if server_port is None: return "Error, No server port specified." # Get server name server_name = Commons.find_any_parameter(["server_name", "name"], line) or server_name # if server name is null, get it from server_address if server_name is None: server_name = Commons.get_domain_name(server_address) # Get other parameters, if set. auto_connect_str = Commons.find_parameter("auto_connect", line) auto_connect = True if auto_connect_str is None else Commons.string_to_bool(auto_connect_str) server_nick = Commons.find_any_parameter(["server_nick", "nick"], line) or current_server.get_nick() server_prefix_arg = Commons.find_any_parameter(["server_prefix", "prefix"], line) if not server_prefix_arg: server_prefix = current_server.prefix else: server_prefix = None if Commons.is_string_null(server_prefix_arg) else server_prefix_arg full_name = Commons.find_parameter("full_name", line) or current_server.get_full_name() nickserv_nick = "nickserv" nickserv_identity_command = "status" nickserv_identity_resp = "^status [^ ]+ 3$" nickserv_password = None if isinstance(current_server, ServerIRC): nickserv_nick = current_server.get_nickserv_nick() nickserv_identity_command = current_server.get_nickserv_ident_command() nickserv_identity_resp = current_server.get_nickserv_ident_response() nickserv_password = current_server.get_nickserv_pass() nickserv_nick = Commons.find_parameter("nickserv_nick", line) or nickserv_nick nickserv_identity_command = Commons.find_parameter("nickserv_identity_command", line) or nickserv_identity_command nickserv_identity_resp = Commons.find_parameter("nickserv_identity_resp", line) or nickserv_identity_resp nickserv_password = Commons.find_parameter("nickserv_password", line) or nickserv_password # Create this serverIRC object new_server_obj = ServerIRC(hallo_obj, server_name, server_address, server_port) new_server_obj.set_auto_connect(auto_connect) new_server_obj.set_nick(server_nick) new_server_obj.set_prefix(server_prefix) new_server_obj.set_full_name(full_name) new_server_obj.set_nickserv_nick(nickserv_nick) new_server_obj.set_nickserv_ident_command(nickserv_identity_command) new_server_obj.set_nickserv_ident_response(nickserv_identity_resp) new_server_obj.set_nickserv_pass(nickserv_password) # Add user with same name on new server to all the same groups as current user new_user_nick = Commons.find_any_parameter(["user", "god"], line) or user_obj.get_name() new_user = new_server_obj.get_user_by_name(new_user_nick) for group in user_obj.user_group_list: new_user.add_user_group(group) # Add the new object to Hallo's list hallo_obj.add_server(new_server_obj) # Connect to the new server object. Thread(target=new_server_obj.run).start() return "Connected to new IRC server: " + new_server_obj.get_name() + "."