def process_output(self, output, model_type): lines = output.split('\n') svg_start = -1 is_node = False b = Borg() for i in range(len(lines)): line = lines[i] if svg_start == -1: if lines[i].find('<svg') > -1: svg_start = i if line.find('class="node"') > -1: is_node = True line = substitute(b.staticDir,"",line) line = substitute("<!--.*?-->", "", line) if line.find('fill="none"') > -1 and is_node: line = line.replace('fill="none"', 'fill="white"') is_node = False line = correctHref(line, model_type) lines[i] = line if svg_start > -1: lines = lines[svg_start:] svg_text = '\n'.join(lines) svg_output = prettifySVG(svg_text) return svg_output
def process_output(self, output, model_type): lines = output.split('\n') svg_start = -1 is_node = False b = Borg() for i in range(len(lines)): line = lines[i] if svg_start == -1: if lines[i].find('<svg') > -1: svg_start = i if line.find('class="node"') > -1: is_node = True line = substitute(b.staticDir, "", line) line = substitute("<!--.*?-->", "", line) if line.find('fill="none"') > -1 and is_node: is_node = False line = correctHref(line, model_type) line = embedImage(line) line = correctTableLabel(line) lines[i] = line if svg_start > -1: lines = lines[svg_start:] svg_text = '\n'.join(lines) svg_output = prettifySVG(svg_text) return svg_output
def mission_statements(self): """Return the list of mission statements.""" return [ substitute(r'<\/?b>', '', statement.get_attribute('innerHTML')) for statement in self.find_elements( *self._mission_statement_locator) ]
def convert_to_integer(roman_numeral: str) -> int: """Convert a Roman numeral to a decimal integer""" if not isinstance(roman_numeral, str): raise TypeError("decimal_integer must be of type int") if roman_numeral == '': raise ValueError("roman_numeral cannot be an empty string") # ensure all characters are in the standard/uppercase set trans_to_uppercase = str.maketrans(LOWERCASE_TRANS, STANDARD_TRANS) # named partial_numeral because it will be shortened in loop below partial_numeral = roman_numeral.translate(trans_to_uppercase) # remove Unicode shortenings in favor of chars in conversion table for full_string, shortening in SHORTENINGS: partial_numeral = substitute( r'%s$' % shortening, full_string, partial_numeral, ) if not fullmatch(NUMERAL_PATTERN, partial_numeral): raise ValueError( "the string %s is not a valid numeral" % roman_numeral ) # convert uppercase roman numerals to integer return_value = 0 for integer, numeral in ROMAN_NUMERAL_TABLE: pattern_match = match(r'^(%s)+' % numeral, partial_numeral) if pattern_match: chars_matched = len(pattern_match.group()) numerals_matched = chars_matched // len(numeral) return_value += numerals_matched * integer partial_numeral = partial_numeral[chars_matched:] return return_value
def convert_to_numeral(decimal_integer: int, mode: int = STANDARD) -> str: """Convert a decimal integer to a Roman numeral""" if (not isinstance(decimal_integer, int) or isinstance(decimal_integer, bool)): raise TypeError("decimal_integer must be of type int") if (not isinstance(mode, int) or isinstance(mode, bool) or mode not in [LOWERCASE, STANDARD]): raise ValueError( "mode must be " "roman_numerals.STANDARD " "or roman_numerals.LOWERCASE " ) return_list = [] remainder = decimal_integer for integer, numeral in ROMAN_NUMERAL_TABLE: repetitions, remainder = divmod(remainder, integer) return_list.append(numeral * repetitions) numeral_string = ''.join(return_list) for full_string, shortening in SHORTENINGS: numeral_string = substitute( r'%s$' % full_string, shortening, numeral_string, ) if mode == LOWERCASE: trans_to_lowercase = str.maketrans(STANDARD_TRANS, LOWERCASE_TRANS) numeral_string = numeral_string.translate(trans_to_lowercase) return numeral_string
def substitute_all(text): # chatacters that need to be replaced adding an extra space: # those are che unicodes which are followed by an character # which does not belong to EXIT_CODES. # i.e. "a_αb_β" cannot be transalted to "a_\alphab_beta"; # the correct form is "a_\alpha b_\beta" pattern_space = '|'.join(escape(k) for k in SUBSTITUTIONS) replace_space = lambda m: SUBSTITUTIONS[m.group(0)] + ' ' # chatacters that can be replaced as they stand. # i.e. "α_aβ_b" con be transalted to "\alpha_a\beta_b" exit_pattern = '|'.join(escape(e) for e in EXIT_CODES) pattern_no_space = '(' + pattern_space + ')(?=(' + pattern_space + '|' + exit_pattern + '))' replace_no_space = lambda m: SUBSTITUTIONS[m.group(0)] return substitute(pattern_space, replace_space, substitute(pattern_no_space, replace_no_space, text))
def get_thousand_list_rows(): fake = Faker() append_list = list() st = time.process_time() for counter in range(10000): data = list() data.append(fake.name()) data.append(substitute('[^0-9\-\(\)]', '', fake.phone_number())) data.append(fake.email()) data.append(fake.sentence()) data.append(fake.date()) data.append('M' if counter % 3 == 0 else 'F' if counter % 2 == 0 else 'O') data.append(substitute('\\n', ' ', fake.address())) data.append(float(fake.latitude())) data.append(float(fake.longitude())) data.append(fake.image_url()) data.append(fake.uri()) append_list.append(data) ed = time.process_time() print('\nGenerated 10,000 Fake Data in ', ed - st, ' sec.\n') return append_list
def format_sms_number(number: str, carrier) -> str: """ Remove non-numerical characters (parens, hyphens) from the sms number """ return '@'.join([substitute('[()-]', '', number), carrier])
def kodi_auth(): aspect_ratio = control.infoLabel('Skin.AspectRatio') def obtain_authorization(_cookie, _uh): data = { 'authorize': 'Allow', 'state': state, 'redirect_uri': redirect_uri, 'response_type': 'code', 'client_id': client_id, 'duration': 'permanent', 'scope': ' '.join(scope), 'uh': _uh } headers = client.request(api_link('authorize'), cookie=_cookie, post=data, redirect=False, output='headers') geturl = dict([ line.partition(': ')[::2] for line in str(headers).splitlines() ]).get('location') token = dict(parse_qsl(urlparse(geturl).query)).get('code') if not token: return get_tokens(code=token) class Prompt(pyxbmct.AddonDialogWindow): pyxbmct.skin.estuary = control.setting('pyxbmct.estuary') == 'true' if aspect_ratio == '4:3': geometry = (506, 380, 5, 5) else: geometry = (676, 380, 5, 5) def __init__(self, title, description, _cookie, _uh): super(Prompt, self).__init__(title) self.allow_button = None self.deny_button = None self.text_box = None self.text = description self.cookie = _cookie self.uh = _uh self.setGeometry(*self.geometry) self.set_controls() self.set_navigation() self.connect(pyxbmct.ACTION_NAV_BACK, self.close) def set_controls(self): # Text box self.text_box = pyxbmct.TextBox() self.placeControl(self.text_box, 0, 0, 4, 5) self.text_box.setText(self.text) self.text_box.autoScroll(1000, 1000, 1000) # Allow self.allow_button = pyxbmct.Button(control.lang(30150)) self.placeControl(self.allow_button, 4, 1) self.connect(self.allow_button, lambda: self.authorize()) # Deny self.deny_button = pyxbmct.Button(control.lang(30151)) self.placeControl(self.deny_button, 4, 3) self.connect(self.deny_button, self.close) def set_navigation(self): self.allow_button.controlRight(self.deny_button) self.deny_button.controlLeft(self.allow_button) self.setFocus(self.allow_button) def authorize(self): obtain_authorization(self.cookie, self.uh) self.close() class UserPass(pyxbmct.AddonDialogWindow): pyxbmct.skin.estuary = control.setting('pyxbmct.estuary') == 'true' if aspect_ratio == '4:3': geometry = (341, 296, 6, 1) else: geometry = (455, 296, 6, 1) def __init__(self, title): super(UserPass, self).__init__(title) self.username_label = None self.user_input = None self.password_label = None self.pass_input = None self.submit_button = None self.cancel_button = None self.setGeometry(*self.geometry) self.set_controls() self.set_navigation() self.connect(pyxbmct.ACTION_NAV_BACK, self.close) def set_controls(self): # Username label self.username_label = pyxbmct.Label(control.lang(30152)) self.placeControl(self.username_label, 0, 0) # Username input self.user_input = pyxbmct.Edit(control.lang(30152)) self.placeControl(self.user_input, 1, 0) # Password label self.password_label = pyxbmct.Label(control.lang(30153)) self.placeControl(self.password_label, 2, 0) # Password input self.pass_input = pyxbmct.Edit(control.lang(30153), isPassword=True) self.placeControl(self.pass_input, 3, 0) # Submit button self.submit_button = pyxbmct.Button(control.lang(30154)) self.placeControl(self.submit_button, 4, 0) self.connect(self.submit_button, lambda: self.submit(True)) # Cancel button self.cancel_button = pyxbmct.Button(control.lang(30064)) self.placeControl(self.cancel_button, 5, 0) self.connect(self.cancel_button, self.close) def set_navigation(self): self.user_input.controlDown(self.pass_input) self.pass_input.controlUp(self.user_input) self.pass_input.controlDown(self.submit_button) self.submit_button.controlUp(self.pass_input) self.submit_button.controlDown(self.cancel_button) self.cancel_button.controlUp(self.submit_button) self.setFocus(self.user_input) def credentials(self): return self.user_input.getText(), self.pass_input.getText() def submit(self, _submitted=False): if _submitted: self.close() return True userpass_window = UserPass(control.name()) userpass_window.doModal() username, password = userpass_window.credentials() if not username or not password: return login_url = base_link(True) + '/api/login/' + username data = { 'form_is_compact': 'true', 'dest': authorization_link(True), 'passwd': password, 'user': username, 'rem': 'on', 'api_type': 'json', 'op': 'login' } del userpass_window cookie = client.request(login_url, close=False, post=data, output='cookie') html = client.request(authorization_link(True), cookie=cookie) try: uh = client.parseDOM(html, 'input', attrs={'name': 'uh'}, ret='value')[0] permissions = client.parseDOM(html, 'div', attrs={'class': 'access-permissions'})[0] notice = client.parseDOM(html, 'p', attrs={'class': 'notice'})[0] text = client.replaceHTMLCodes( client.stripTags(permissions + '[CR]' + notice)) text = substitute(r'([.:]) ?', r'\1[CR]', text).partition('[CR]') prompt_window = Prompt(title=text[0], description=text[2], _cookie=cookie, _uh=uh) prompt_window.doModal() del prompt_window except IndexError: control.okDialog(control.name(), control.lang(30114))
def remove_years_from_name(name): return substitute(r'\s\d*\-\d*$', '', name)
def remove_special(word): return substitute(r'\W+', '', word)
def get_description_from_argparser(self, argparser): command_description = substitute(r'^usage.*-h', r'[-h', argparser.format_usage()) return command_description