code stringlengths 52 7.75k | docs stringlengths 1 5.85k |
|---|---|
def is_playing_shared_game(self, steamID, appid_playing, format=None):
parameters = {'steamid' : steamID, 'appid_playing' : appid_playing}
if format is not None:
parameters['format'] = format
url = self.create_request_url(self.interface, 'IsPlayingSharedGame', 1,
... | Returns valid lender SteamID if game currently played is borrowed.
steamID: The users ID
appid_playing: The game player is currently playing
format: Return format. None defaults to json. (json, xml, vdf) |
def get_server_info(self, format=None):
parameters = {}
if format is not None:
parameters['format'] = format
url = self.create_request_url(self.interface, 'GetServerInfo', 1,
parameters)
data = self.retrieve_request(url)
return self.return_data(da... | Request the Steam Web API status and time.
format: Return format. None defaults to json. (json, xml, vdf) |
def create_request_url(self, profile_type, steamID):
regex = re.compile('^\d{17,}$')
if regex.match(steamID):
if profile_type == self.USER:
url = "http://steamcommunity.com/profiles/%s/?xml=1" % (steamID)
if profile_type == self.GROUP:
url... | Create the url to submit to the Steam Community XML feed. |
def get_user_info(self, steamID):
url = self.create_request_url(self.USER, steamID)
data = self.retrieve_request(url)
return self.return_data(data, format='xml') | Request the Steam Community XML feed for a specific user. |
def get_group_info(self, steamID):
url = self.create_request_url(self.GROUP, steamID)
data = self.retrieve_request(url)
return self.return_data(data, format='xml') | Request the Steam Community XML feed for a specific group. |
def Deserializer(stream_or_string, **options):
if isinstance(stream_or_string, (bytes, six.string_types)):
stream_or_string = BytesIO(stream_or_string)
try:
def line_generator():
for line in stream_or_string:
yield json.loads(line.strip())
for obj in Pyth... | Deserialize a stream or string of JSON data. |
def request(self, method, url, data=None, files=None, query=None, headers=None, timeout=60):
headers = headers or {}
if self.token:
my_token = self.token
else:
from figure import token
my_token = token
if my_token:
self.__set_aut... | Mechanism for issuing an API call |
def export(cls, folder, particles, datetimes):
normalized_locations = [particle.normalized_locations(datetimes) for particle in particles]
track_coords = []
for x in xrange(0, len(datetimes)):
points = MultiPoint([loc[x].point.coords[0] for loc in normalized_locations])
... | Export trackline data to GeoJSON file |
def export(cls, folder, particles, datetimes):
if not os.path.exists(folder):
os.makedirs(folder)
particle_path = os.path.join(folder, 'particles.pickle')
f = open(particle_path, "wb")
pickle.dump(particles, f)
f.close()
datetimes_path = os.path.joi... | Export particle and datetime data to Pickled objects.
This can be used to debug or to generate different output
in the future. |
def import_settings_class(setting_name):
config_value = getattr(settings, setting_name)
if config_value is None:
raise ImproperlyConfigured("Required setting not found: {0}".format(setting_name))
return import_class(config_value, setting_name) | Return the class pointed to be an app setting variable. |
def import_class(import_path, setting_name=None):
mod_name, class_name = import_path.rsplit('.', 1)
# import module
mod = import_module_or_none(mod_name)
if mod is not None:
# Loaded module, get attribute
try:
return getattr(mod, class_name)
except AttributeErro... | Import a class by name. |
def import_apps_submodule(submodule):
found_apps = []
for appconfig in apps.get_app_configs():
app = appconfig.name
if import_module_or_none('{0}.{1}'.format(app, submodule)) is not None:
found_apps.append(app)
return found_apps | Look for a submodule is a series of packages, e.g. ".pagetype_plugins" in all INSTALLED_APPS. |
def import_module_or_none(module_label):
try:
# On Python 3, importlib has much more functionality compared to Python 2.
return importlib.import_module(module_label)
except ImportError:
# Based on code from django-oscar:
# There are 2 reasons why there could be an ImportErro... | Imports the module with the given name.
Returns None if the module doesn't exist,
but it does propagates import errors in deeper modules. |
def get_logger(name):
logger = logging.getLogger(name)
logger.addHandler(logging.NullHandler())
return logger | Gets a logger
Arguments:
name - the name you wish to log as
Returns:
A logger! |
def get_best_single_experiments(nets,expvars):
'''
returns the experiments as a``TermSet`` object [instance].
'''
netsf = nets.to_file()
expvarsf = expvars.to_file()
i = 1 #single experiment
num_exp = String2TermSet('pexperiment('+str(i)+')')
num_expf = num_exp.to_file()
prg = [ netsf, e... | returns the experiments as a``TermSet`` object [instance]. |
async def handler(self):
'''Handle loop, get and process messages'''
self.ws = await websockets.connect(self.url, ssl=self.ssl)
while self.ws:
message = await self.ws.recv()
for handle in self.on_message:
if asyncio.iscoroutinefunction(handle):
await handle(self, message)
... | Handle loop, get and process messages |
async def get(self, path, **query):
'''return a get request
Parameters
----------
path : str
same as get_url
query : kargs dict
additional info to pass to get_url
See Also
--------
get_url :
getJson :
Returns
-------
requests.models.Response
the r... | return a get request
Parameters
----------
path : str
same as get_url
query : kargs dict
additional info to pass to get_url
See Also
--------
get_url :
getJson :
Returns
-------
requests.models.Response
the response that was given |
async def getJson(self, path, **query):
'''wrapper for get, parses response as json
Parameters
----------
path : str
same as get_url
query : kargs dict
additional info to pass to get_url
See Also
--------
get_url :
get :
Returns
-------
dict
the r... | wrapper for get, parses response as json
Parameters
----------
path : str
same as get_url
query : kargs dict
additional info to pass to get_url
See Also
--------
get_url :
get :
Returns
-------
dict
the response content as a dict |
def filter_by_missing(max_miss=0.01):
def f(G, bim):
Isnp = sp.isnan(G).mean(0) < max_miss
G_out = G[:, Isnp]
bim_out = bim[Isnp]
return G_out, bim_out
return f | return function that filters by missing values
(takes maximum fraction of missing values, default is 0.01) |
def filter_by_maf(min_maf=0.01):
def f(G, bim):
maf = 0.5 * G.mean(0)
maf[maf > 0.5] = 1.0 - maf[maf > 0.5]
Isnp = maf > min_maf
G_out = G[:, Isnp]
bim_out = bim[Isnp]
return G_out, bim_out
return f | return function that filters by maf
(takes minimum maf, default is 0.01) |
def standardize():
def f(G, bim):
G_out = standardize_snps(G)
return G_out, bim
return f | return variant standarize function |
def impute(imputer):
def f(G, bim):
return imputer.fit_transform(G), bim
return f | return impute function |
def compose(func_list):
def f(G, bim):
for func in func_list:
G, bim = func(G, bim)
return G, bim
return f | composion of preprocessing functions |
def asdict(self):
items = {}
for name in self._items:
value = self._items[name]
if isinstance(value, DictionaryObject):
items[name] = value.asdict()
else:
items[name] = value
return items | Copy the data back out of here and into a dict. Then return it.
Some libraries may check specifically for dict objects, such
as the json library; so, this makes it convenient to get the data
back out.
>>> import dictobj
>>> d = {'a':1, 'b':2}
>>> dictobj.DictionaryObject(d).asdict() == d
T... |
def get_joke():
joke = None
while joke is None:
service_num = randint(1, NUM_SERVICES)
joke = load_joke(service_num)
return joke | Return a jokes from one of the random services. |
def load_joke(service_num=1):
result = {
1 : ronswanson.get_joke(),
2 : chucknorris.get_joke(),
3 : catfacts.get_joke(),
4 : dadjokes.get_joke(),
}.get(service_num)
return result | Pulls the joke from the service based on the argument.
It is expected that all services used will return a string
when successful or None otherwise. |
def read_14c(fl):
indata = pd.read_csv(fl, index_col=None, skiprows=11, header=None,
names=['calbp', 'c14age', 'error', 'delta14c', 'sigma'])
outcurve = CalibCurve(calbp=indata['calbp'],
c14age=indata['c14age'],
error=indata['erro... | Create CalibCurve instance from Bacon curve file |
def read_chron(fl):
indata = pd.read_csv(fl, sep=r'\s*\,\s*', index_col=None, engine='python')
outcore = ChronRecord(age=indata['age'],
error=indata['error'],
depth=indata['depth'],
labid=indata['labID'])
return outcore | Create ChronRecord instance from Bacon file |
def read_proxy(fl):
outcore = ProxyRecord(data=pd.read_csv(fl, sep=r'\s*\,\s*', index_col=None, engine='python'))
return outcore | Read a file to create a proxy record instance |
def to_pandas(self):
agedepthdf = pd.DataFrame(self.age, index=self.data.depth)
agedepthdf.columns = list(range(self.n_members()))
out = (agedepthdf.join(self.data.set_index('depth'))
.reset_index()
.melt(id_vars=self.data.columns.values, var_name='mciter',... | Convert record to pandas.DataFrame |
def _get_token_type(self, char):
if char in '()':
return self.SPLIT, 0
elif char == ',':
return self.SPLIT, 1
elif char in '<>':
return self.IGNORE, 2
elif char == '.':
return self.JOIN, 3
elif char.isdigit():
r... | Returns a 2-tuple (behaviour, type).
behaviours:
0 - join
1 - split
2 - ignore |
def request(method, url, **kwargs):
auth = kwargs.get('auth')
headers = kwargs.get('headers', {})
# headers = headers.copy() # ? We do modify the dict in place here...
if isinstance(auth, TreqKerberosAuth):
del kwargs['auth']
if auth.force_preemptive:
# Save a round-trip... | Pass auth=HTTPKerberosAuth() kwarg |
def negotiate_header(url):
hostname = urlparse(url).hostname
_, krb_context = kerberos.authGSSClientInit('HTTP@%s' % hostname)
# authGSSClientStep goes over the network to the KDC (ie blocking).
yield threads.deferToThread(kerberos.authGSSClientStep,
krb_context, '')... | Return the "Authorization" HTTP header value to use for this URL. |
def _get_specification(self, specification):
result = six.moves.urllib.parse.urlparse(specification)
# If the specification has an http or an https scheme we can
# retrieve it via an HTTP get request, else we try to open it
# as a file.
if result.scheme in ['http', 'htt... | Read the specification provided. It can either be a url or a file
location. |
def _get_headers(self, resource):
# If the resource is a file we just open it up with the csv
# reader (after being sure we're reading from the beginning
# of the file
if type(resource) == file:
resource.seek(0)
reader = csv.reader(resource)
# If... | Get CSV file headers from the provided resource. |
def schema(self):
if self.headers is None:
raise exceptions.NoResourceLoadedException(
'Resource must be loaded to find schema')
try:
fields = self.specification.get('fields', {})
parsed = {
'primaryKey': 'id',
... | The generated budget data package schema for this resource.
If the resource has any fields that do not conform to the
provided specification this will raise a
NotABudgetDataPackageException. |
def get_time(self, idx=0):
timestr = SingleTifPhasics._get_meta_data(path=self.path,
section="acquisition info",
name="date & heure")
if timestr is not None:
timestr = timestr.split("... | Return the time of the tif data since the epoch
The time is stored in the "61238" tag. |
def verify(path):
valid = False
try:
tf = SingleTifPhasics._get_tif(path)
except (ValueError, IsADirectoryError):
pass
else:
if (len(tf) == 3 and
"61243" in tf.pages[0].tags and
"61242" in tf.pages[0].tags and
... | Verify that `path` is a phasics phase/intensity TIFF file |
def _init(
self, default_prefix='_',
fext=TMPL_FN_EXT, req_tmpl_name=REQ_TMPL_NAME,
text_prefix=REQUIREJS_TEXT_PREFIX,
auto_reload=False,
*a, **kw):
self.default_prefix = default_prefix
self.molds = {}
self.tracked_entry_point... | Arguments:
registry_name
The name of this registry. |
def _generate_and_store_mold_id_map(self, template_map, molds):
name = self.req_tmpl_name
for key in sorted(template_map.keys(), reverse=True):
if len(key.split('/')) == 3 and key.endswith(name):
mold_id = key[len(self.text_prefix):-len(name) - 1]
mo... | Not a pure generator expression as this has the side effect of
storing the resulting id and map it into a local dict. Produces
a list of all valid mold_ids from the input template_keys.
Internal function; NOT meant to be used outside of this class. |
def mold_id_to_path(self, mold_id, default=_marker):
def handle_default(debug_msg=None):
if debug_msg:
logger.debug('mold_id_to_path:' + debug_msg, mold_id)
if default is _marker:
raise KeyError(
'Failed to lookup mold_id %s t... | Lookup the filesystem path of a mold identifier. |
def lookup_path(self, mold_id_path, default=_marker):
fragments = mold_id_path.split('/')
mold_id = '/'.join(fragments[:2])
try:
subpath = []
for piece in fragments[2:]:
if (sep in piece or (altsep and altsep in piece) or
... | For the given mold_id_path, look up the mold_id and translate
that path to its filesystem equivalent. |
def verify_path(self, mold_id_path):
try:
path = self.lookup_path(mold_id_path)
if not exists(path):
raise KeyError
except KeyError:
raise_os_error(ENOENT)
return path | Lookup and verify path. |
def _get_skippers(configure, file_name=None):
skippers = []
if file_name is None:
file_name = os.path.join(os.path.dirname(os.path.dirname(
os.path.dirname(os.path.realpath(__file__))
)), 'skippers.xml')
xmldoc = minidom.parse(file_name)
... | Returns the skippers of configuration.
:param configure: The configuration of HaTeMiLe.
:type configure: hatemile.util.configure.Configure
:param file_name: The file path of skippers configuration.
:type file_name: str
:return: The skippers of configuration.
:rtype: list... |
def _generate_list_skippers(self):
container = self.parser.find(
'#'
+ AccessibleNavigationImplementation.ID_CONTAINER_SKIPPERS
).first_result()
html_list = None
if container is None:
local = self.parser.find('body').first_result()
... | Generate the list of skippers of page.
:return: The list of skippers of page.
:rtype: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _get_heading_level(self, element):
# pylint: disable=no-self-use
tag = element.get_tag_name()
if tag == 'H1':
return 1
elif tag == 'H2':
return 2
elif tag == 'H3':
return 3
elif tag == 'H4':
return 4
el... | Returns the level of heading.
:param element: The heading.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:return: The level of heading.
:rtype: int |
def _is_valid_heading(self):
elements = self.parser.find('h1,h2,h3,h4,h5,h6').list_results()
last_level = 0
count_main_heading = 0
self.validate_heading = True
for element in elements:
level = self._get_heading_level(element)
if level == 1:
... | Check that the headings of page are sintatic correct.
:return: True if the headings of page are sintatic correct or False if
not.
:rtype: bool |
def _generate_anchor_for(self, element, data_attribute, anchor_class):
self.id_generator.generate_id(element)
if self.parser.find(
'[' + data_attribute + '="' + element.get_attribute('id') + '"]'
).first_result() is None:
if element.get_tag_name() == 'A':
... | Generate an anchor for the element.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param data_attribute: The name of attribute that links the element
with the anchor.
:type data_attribute: str
:param a... |
def _free_shortcut(self, shortcut):
alpha_numbers = '1234567890abcdefghijklmnopqrstuvwxyz'
elements = self.parser.find('[accesskey]').list_results()
found = False
for element in elements:
shortcuts = element.get_attribute('accesskey').lower()
if CommonFu... | Replace the shortcut of elements, that has the shortcut passed.
:param shortcut: The shortcut.
:type shortcut: str |
def get_scrim(path=None, auto_write=None, shell=None, script=None, cache={}):
'''Get a :class:`Scrim` instance. Each instance is cached so if you call
get_scrim again with the same arguments you get the same instance.
See also:
:class:`Scrim`
'''
args = (path, auto_write, shell, script)
... | Get a :class:`Scrim` instance. Each instance is cached so if you call
get_scrim again with the same arguments you get the same instance.
See also:
:class:`Scrim` |
def _add(self, name, *args, **kwargs):
'''Appends a command to the scrims list of commands. You should not
need to use this.'''
self.commands.append(Command(name, args, kwargs)f _add(self, name, *args, **kwargs):
'''Appends a command to the scrims list of commands. You should not
... | Appends a command to the scrims list of commands. You should not
need to use this. |
def to_string(self, shell=None):
'''Use the command executor to retrieve the text of the scrim script
compatible with the provided shell. If no shell is provided, use
:attr:`scrim.shell`.
Attributes:
shell (str): Which shell should we return a script for
cmd.... | Use the command executor to retrieve the text of the scrim script
compatible with the provided shell. If no shell is provided, use
:attr:`scrim.shell`.
Attributes:
shell (str): Which shell should we return a script for
cmd.exe, powershell.exe, bash...
Return... |
def write(self):
'''Write this Scrims commands to its path'''
if self.path is None:
raise Exception('Scrim.path is None')
dirname = os.path.dirname(os.path.abspath(self.path))
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
... | Write this Scrims commands to its path |
def on_exit(self):
'''atexit callback. If :attr:`Scrim.auto_write` is True write the
scrim to :attr:`Scrim.path` as :attr:`Scrim.shell`'''
if not all([self.auto_write, self.commands, self.script, self.path]):
return
self.write(f on_exit(self):
'''atexit callback. If... | atexit callback. If :attr:`Scrim.auto_write` is True write the
scrim to :attr:`Scrim.path` as :attr:`Scrim.shell` |
def remove_orphans(self, instance, **kwargs):
from activity_monitor.models import Activity
try:
instance_content_type = ContentType.objects.get_for_model(instance)
timeline_item = Activity.objects.get(content_type=instance_content_type, object_id=instance.pk)
timeline_item.del... | When an item is deleted, first delete any Activity object that has been created
on its behalf. |
def follow_model(self, model):
if model:
self.models_by_name[model.__name__.lower()] = model
signals.post_save.connect(create_or_update, sender=model)
signals.post_delete.connect(self.remove_orphans, sender=model) | Follow a particular model class, updating associated Activity objects automatically. |
def get_for_model(self, model):
return self.filter(content_type=ContentType.objects.get_for_model(model)) | Return a QuerySet of only items of a certain type. |
def get_last_update_of_model(self, model, **kwargs):
qs = self.get_for_model(model)
if kwargs:
qs = qs.filter(**kwargs)
try:
return qs.order_by('-timestamp')[0].timestamp
except IndexError:
return datetime.datetime.fromtimestamp(0) | Return the last time a given model's items were updated. Returns the
epoch if the items were never updated. |
def for_each(self, operation, limit=0, verbose=False):
if limit != 0:
count = 0
while self.has_next():
operation.perform(self.next())
count += 1
if verbose:
print count
if count >= limit:
... | Applies the given Operation to each item in the stream. The Operation executes on the
items in the stream in the order that they appear in the stream.
If the limit is supplied, then processing of the stream will stop after that many items
have been processed. |
def _parse_lookup_string(self, lookup_chain):
lookup_chain = lookup_chain.split('__')
comparator = self.default_comparator
# Only look for a lookup method if the lookup chain is larger than 1
if len(lookup_chain) <= 1:
return lookup_chain, comparator
# Get ... | Convert a lookup string to a (lookup_chain, comparator) tuple. |
def _resolve_lookup_chain(self, chain, instance):
value = instance
for link in chain:
value = getattr(value, link)
return value | Return the value of inst.chain[0].chain[1].chain[...].chain[n]. |
def iregex(value, iregex):
return re.match(iregex, value, flags=re.I) | Returns true if the value case insentively matches agains the
regex. |
def get_subdirectories(directory):
return [name for name in os.listdir(directory)
if name != '__pycache__'
if os.path.isdir(os.path.join(directory, name))] | Get subdirectories without pycache |
def get_python_path() -> str:
python_bin = None
if os.name == 'nt':
python_root = os.path.abspath(
os.path.join(os.__file__, os.pardir, os.pardir))
python_bin = os.path.join(python_root, 'python.exe')
else:
python_root = os.path.abspath(
os.path.... | Accurately get python executable |
def __collect_fields(self):
form = FormData()
form.add_field(self.__username_field, required=True,
error=self.__username_error)
form.add_field(self.__password_field, required=True,
error=self.__password_error)
form.parse()
... | Use field values from config.json and collect from request |
def session(self) -> str:
session_jwt = None
self.user = self.user_model.where_username(self.username)
if self.user is None:
return None
self.user.updated() # update timestamp on user access
if self.verify_password(self.user.password):
se... | Generate a session(authorization Bearer) JWT token |
def install_board(board_id, board_options, hwpack='arduino', replace_existing=False):
doaction = 0
if board_id in boards(hwpack).keys():
log.debug('board already exists: %s', board_id)
if replace_existing:
log.debug('remove board: %s' , board_id)
remove_board(board_i... | install board in boards.txt.
:param board_id: string identifier
:param board_options: dict like
:param replace_existing: bool
:rtype: None |
def _parse_nested_interval(self, tokens):
if tokens[0].isdigit():
return self._parse_interval(tokens)
elif tokens[0] in ['join', 'order']:
return self._parse_join(tokens)
elif tokens[0] == 'complement':
return self._parse_complement(tokens)
ra... | Parses a super range.
SuperRange ::= Range | Join | Complement |
def _parse_interval(self, tokens):
fr = int(tokens.pop(0)) - 1
if len(tokens) > 1 and tokens[0] in ['..', '^']:
tokens.pop(0) # Pop '..' | '^'
to = int(tokens.pop(0))
return GenomicInterval(fr, to, chromosome=self.hdr['ACCESSION']['value'])
return Ge... | Parses a range
Range ::= <num> | <num> ('..' | '^') <num> |
def _parse_join(self, tokens):
children = []
tokens.pop(0) # Pop 'join'
tokens.pop(0) # Pop '('
children.append(self._parse_nested_interval(tokens))
while tokens[0] == ',':
tokens.pop(0)
children.append(self._parse_nested_interval(tokens))
... | Parses a join.
Join ::= 'join' '(' SuperRange [',' SuperRange] ')' |
def _parse_complement(self, tokens):
tokens.pop(0) # Pop 'complement'
tokens.pop(0) # Pop '('
res = self._parse_nested_interval(tokens)
tokens.pop(0) # Pop ')'
res.switch_strand()
return res | Parses a complement
Complement ::= 'complement' '(' SuperRange ')' |
def indel_at( self, position, check_insertions=True, check_deletions=True, one_based=True ):
(insertions, deletions) = self.get_indels( one_based=one_based )
if check_insertions:
for insertion in insertions:
if insertion[0] == position:
return Tru... | Does the read contain an indel at the given position?
Return True if the read contains an insertion at the given position
(position must be the base before the insertion event) or if the read
contains a deletion where the base at position is deleted. Return False
otherwise. |
def get_indels( self, one_based=True ):
cigar = self.get_cigar() #CIGAR_OP = list( 'MIDNSHP=X' )
insertions = []
deletions = []
position_offset = 0
position_start = self.get_position( one_based=one_based )
while cigar:
cigar_size, cigar_op = cigar.pop... | Return a data structure containing all indels in the read.
Returns the tuple (insertions, deletions)
insertions = [(pos1,ins1), (pos2,ins2)]
posN = start position (preceding base, VCF-style)
insN = length of inserted sequence (not including preceding base)
deletions = [(pos1,del1... |
def _operation_speak_as_spell_out(self, content, index, children):
children.append(self._create_content_element(
content[0:(index + 1)],
'spell-out'
))
children.append(self._create_aural_content_element(' ', 'spell-out'))
return children | The operation method of _speak_as method for spell-out.
:param content: The text content of element.
:type content: str
:param index: The index of pattern in text content of element.
:type index: int
:param children: The children of element.
:type children: list(hatemile... |
def _operation_speak_as_literal_punctuation(
self,
content,
index,
children
):
data_property_value = 'literal-punctuation'
if index != 0:
children.append(self._create_content_element(
content[0:index],
data_propert... | The operation method of _speak_as method for literal-punctuation.
:param content: The text content of element.
:type content: str
:param index: The index of pattern in text content of element.
:type index: int
:param children: The children of element.
:type children: lis... |
def _operation_speak_as_no_punctuation(self, content, index, children):
if index != 0:
children.append(self._create_content_element(
content[0:index],
'no-punctuation'
))
children.append(self._create_visual_content_element(
co... | The operation method of _speak_as method for no-punctuation.
:param content: The text content of element.
:type content: str
:param index: The index of pattern in text content of element.
:type index: int
:param children: The children of element.
:type children: list(hat... |
def _operation_speak_as_digits(self, content, index, children):
data_property_value = 'digits'
if index != 0:
children.append(self._create_content_element(
content[0:index],
data_property_value
))
children.append(self._create_aura... | The operation method of _speak_as method for digits.
:param content: The text content of element.
:type content: str
:param index: The index of pattern in text content of element.
:type index: int
:param children: The children of element.
:type children: list(hatemile.ut... |
def _set_symbols(self, file_name, configure):
self.symbols = []
if file_name is None:
file_name = os.path.join(os.path.dirname(os.path.dirname(
os.path.dirname(os.path.realpath(__file__))
)), 'symbols.xml')
xmldoc = minidom.parse(file_name)
... | Load the symbols with configuration.
:param file_name: The file path of symbol configuration.
:type file_name: str
:param configure: The configuration of HaTeMiLe.
:type configure: hatemile.util.configure.Configure |
def _get_formated_symbol(self, symbol):
# pylint: disable=no-self-use
old_symbols = [
'\\',
'.',
'+',
'*',
'?',
'^',
'$',
'[',
']',
'{',
'}',
'(',
... | Returns the symbol formated to be searched by regular expression.
:param symbol: The symbol.
:type symbol: str
:return: The symbol formated.
:rtype: str |
def _get_regular_expression_of_symbols(self):
regular_expression = None
for symbol in self.symbols:
formated_symbol = self._get_formated_symbol(symbol['symbol'])
if regular_expression is None:
regular_expression = '(' + formated_symbol + ')'
... | Returns the regular expression to search all symbols.
:return: The regular expression to search all symbols.
:rtype: str |
def _is_valid_inherit_element(self, element):
# pylint: disable=no-self-use
tag_name = element.get_tag_name()
return (
(tag_name in AccessibleCSSImplementation.VALID_INHERIT_TAGS)
and (not element.has_attribute(CommonFunctions.DATA_IGNORE))
) | Check that the children of element can be manipulated to apply the CSS
properties.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:return: True if the children of element can be manipulated to apply
the CSS properties or Fal... |
def _isolate_text_node(self, element):
if (
(element.has_children_elements())
and (self._is_valid_element(element))
):
if self._is_valid_element(element):
child_nodes = element.get_children()
for child_node in child_nodes:
... | Isolate text nodes of element nodes.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _replace_element_by_own_content(self, element):
# pylint: disable=no-self-use
if element.has_children_elements():
children = element.get_children_elements()
for child in children:
element.insert_before(child)
element.remove_node()
... | Replace the element by own text content.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _visit(self, element, operation):
if self._is_valid_inherit_element(element):
if element.has_children_elements():
children = element.get_children_elements()
for child in children:
self._visit(child, operation)
elif self._i... | Visit and execute a operation in element and descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param operation: The operation to be executed.
:type operation: function |
def _create_content_element(self, content, data_property_value):
content_element = self.html_parser.create_element('span')
content_element.set_attribute(
AccessibleCSSImplementation.DATA_ISOLATOR_ELEMENT,
'true'
)
content_element.set_attribute(
... | Create a element to show the content.
:param content: The text content of element.
:type content: str
:param data_property_value: The value of custom attribute used to
identify the fix.
:type data_property_value: str
:return: The element to sh... |
def _create_aural_content_element(self, content, data_property_value):
content_element = self._create_content_element(
content,
data_property_value
)
content_element.set_attribute('unselectable', 'on')
content_element.set_attribute('class', 'screen-reade... | Create a element to show the content, only to aural displays.
:param content: The text content of element.
:type content: str
:param data_property_value: The value of custom attribute used to
identify the fix.
:type data_property_value: str
:r... |
def _create_visual_content_element(self, content, data_property_value):
content_element = self._create_content_element(
content,
data_property_value
)
content_element.set_attribute('aria-hidden', 'true')
content_element.set_attribute('role', 'presentatio... | Create a element to show the content, only to visual displays.
:param content: The text content of element.
:type content: str
:param data_property_value: The value of custom attribute used to
identify the fix.
:type data_property_value: str
:... |
def _speak_normal(self, element):
if element.has_attribute(AccessibleCSSImplementation.DATA_SPEAK):
if (
(element.get_attribute(
AccessibleCSSImplementation.DATA_SPEAK
) == 'none')
and (not element.has_attribute(
... | Speak the content of element only.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _speak_normal_inherit(self, element):
self._visit(element, self._speak_normal)
element.normalize() | Speak the content of element and descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _speak_none(self, element):
# pylint: disable=no-self-use
element.set_attribute('role', 'presentation')
element.set_attribute('aria-hidden', 'true')
element.set_attribute(AccessibleCSSImplementation.DATA_SPEAK, 'none') | No speak any content of element only.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _speak_none_inherit(self, element):
self._isolate_text_node(element)
self._visit(element, self._speak_none) | No speak any content of element and descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _speak_as(
self,
element,
regular_expression,
data_property_value,
operation
):
children = []
pattern = re.compile(regular_expression)
content = element.get_text_content()
while content:
matches = pattern.search(conten... | Execute a operation by regular expression for element only.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param regular_expression: The regular expression.
:type regular_expression: str
:param data_property_value: The value of cust... |
def _reverse_speak_as(self, element, data_property_value):
data_property = (
'['
+ AccessibleCSSImplementation.DATA_SPEAK_AS
+ '="'
+ data_property_value
+ '"]'
)
auxiliar_elements = self.html_parser.find(element).find_descen... | Revert changes of a speak_as method for element and descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param data_property_value: The value of custom attribute used to
identify the fix.
:type dat... |
def _speak_as_normal(self, element):
self._reverse_speak_as(element, 'spell-out')
self._reverse_speak_as(element, 'literal-punctuation')
self._reverse_speak_as(element, 'no-punctuation')
self._reverse_speak_as(element, 'digits') | Use the default speak configuration of user agent for element and
descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _speak_as_spell_out_inherit(self, element):
self._reverse_speak_as(element, 'spell-out')
self._isolate_text_node(element)
self._visit(element, self._speak_as_spell_out) | Speak one letter at a time for each word for elements and descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _speak_as_literal_punctuation(self, element):
self._speak_as(
element,
self._get_regular_expression_of_symbols(),
'literal-punctuation',
self._operation_speak_as_literal_punctuation
) | Speak the punctuation for elements only.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _speak_as_literal_punctuation_inherit(self, element):
self._reverse_speak_as(element, 'literal-punctuation')
self._reverse_speak_as(element, 'no-punctuation')
self._isolate_text_node(element)
self._visit(element, self._speak_as_literal_punctuation) | Speak the punctuation for elements and descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _speak_as_no_punctuation_inherit(self, element):
self._reverse_speak_as(element, 'literal-punctuation')
self._reverse_speak_as(element, 'no-punctuation')
self._isolate_text_node(element)
self._visit(element, self._speak_as_no_punctuation) | No speak the punctuation for element and descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _speak_as_digits_inherit(self, element):
self._reverse_speak_as(element, 'digits')
self._isolate_text_node(element)
self._visit(element, self._speak_as_digits) | Speak the digit at a time for each number for element and descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
def _speak_header_always_inherit(self, element):
self._speak_header_once_inherit(element)
cell_elements = self.html_parser.find(element).find_descendants(
'td[headers],th[headers]'
).list_results()
accessible_display = AccessibleDisplayImplementation(
s... | The cells headers will be spoken for every data cell for element and
descendants.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.