code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
for (name, order) in iteritems(appsettings.FLUENT_DASHBOARD_CMS_MODEL_ORDER):
if name in model_name:
return order
return 999 | def get_cms_model_order(model_name) | Return a numeric ordering for a model name. | 5.57496 | 5.004251 | 1.114045 |
site_name = get_admin_site_name(context)
self.children += [
items.MenuItem(_('Dashboard'), reverse('{0}:index'.format(site_name))),
items.Bookmarks(),
]
for title, kwargs in get_application_groups():
if kwargs.get('enabled', True):
... | def init_with_context(self, context) | Initialize the menu items. | 6.95943 | 6.383672 | 1.090192 |
super(PersonalModule, self).init_with_context(context)
current_user = context['request'].user
if django.VERSION < (1, 5):
current_username = current_user.first_name or current_user.username
else:
current_username = current_user.get_short_name() or current... | def init_with_context(self, context) | Initializes the link list. | 3.172046 | 3.177809 | 0.998186 |
super(AppIconList, self).init_with_context(context)
apps = self.children
# Standard model only has a title, change_url and add_url.
# Restore the app_name and name, so icons can be matched.
for app in apps:
app_name = self._get_app_name(app)
app[... | def init_with_context(self, context) | Initializes the icon list. | 4.464128 | 4.321305 | 1.033051 |
if 'change_url' in modeldata:
return modeldata['change_url'].strip('/').split('/')[-1] # /foo/admin/appname/modelname
elif 'add_url' in modeldata:
return modeldata['add_url'].strip('/').split('/')[-2] # /foo/admin/appname/modelname/add
else:
ra... | def _get_model_name(self, modeldata) | Extract the model name from the ``modeldata`` that *django-admin-tools* provides. | 3.964528 | 3.285852 | 1.206545 |
key = "{0}/{1}".format(app_name, model_name)
return appsettings.FLUENT_DASHBOARD_APP_ICONS.get(key, default) | def get_icon_for_model(self, app_name, model_name, default=None) | Return the icon for the given model.
It reads the :ref:`FLUENT_DASHBOARD_APP_ICONS` setting. | 4.496424 | 2.793141 | 1.609809 |
if not icon.startswith('/') \
and not icon.startswith('http://') \
and not icon.startswith('https://'):
if '/' in icon:
return self.icon_static_root + icon
else:
return self.icon_theme_root + icon
else:
... | def get_icon_url(self, icon) | Replaces the "icon name" with a full usable URL.
* When the icon is an absolute URL, it is used as-is.
* When the icon contains a slash, it is relative from the ``STATIC_URL``.
* Otherwise, it's relative to the theme url folder. | 2.963868 | 2.871329 | 1.032229 |
super(CmsAppIconList, self).init_with_context(context)
apps = self.children
cms_apps = [a for a in apps if is_cms_app(a['name'])]
non_cms_apps = [a for a in apps if a not in cms_apps]
if cms_apps:
# Group the models of all CMS apps in one group.
... | def init_with_context(self, context) | Initializes the icon list. | 3.992007 | 3.812755 | 1.047014 |
super(CacheStatusGroup, self).init_with_context(context)
if 'dashboardmods' in settings.INSTALLED_APPS:
import dashboardmods
memcache_mods = dashboardmods.get_memcache_dash_modules()
try:
varnish_mods = dashboardmods.get_varnish_dash_modules... | def init_with_context(self, context) | Initializes the status list. | 5.832057 | 5.694176 | 1.024214 |
path = os.path.join(os.path.dirname(__file__), 'soupsieve')
fp, pathname, desc = imp.find_module('__meta__', [path])
try:
meta = imp.load_module('__meta__', fp, pathname, desc)
return meta.__version__, meta.__version_info__._get_dev_status()
finally:
fp.close() | def get_version() | Get version and version_info without importing the entire module. | 3.249981 | 2.856403 | 1.137788 |
with open("requirements/project.txt") as f:
requirements = []
for line in f.readlines():
line = line.strip()
if line and not line.startswith('#'):
requirements.append(line)
return requirements | def get_requirements() | Get the dependencies. | 2.782873 | 2.654299 | 1.04844 |
custom_selectors = process_custom(custom)
return cm.SoupSieve(
pattern,
CSSParser(pattern, custom=custom_selectors, flags=flags).process_selectors(),
namespaces,
custom,
flags
) | def _cached_css_compile(pattern, namespaces, custom, flags) | Cached CSS compile. | 12.141662 | 12.375255 | 0.981124 |
custom_selectors = {}
if custom is not None:
for key, value in custom.items():
name = util.lower(key)
if RE_CUSTOM.match(name) is None:
raise SelectorSyntaxError("The name '{}' is not a valid custom pseudo-class name".format(name))
if name in cus... | def process_custom(custom) | Process custom. | 4.098372 | 3.97375 | 1.031361 |
def replace(m):
if m.group(1):
codepoint = int(m.group(1)[1:], 16)
if codepoint == 0:
codepoint = UNICODE_REPLACEMENT_CHAR
value = util.uchr(codepoint)
elif m.group(2):
value = m.group(2)[1:]
elif m.group(3):
... | def css_unescape(content, string=False) | Unescape CSS value.
Strings allow for spanning the value on multiple strings by escaping a new line. | 3.410717 | 3.460138 | 0.985717 |
string = []
length = len(ident)
start_dash = length > 0 and ident[0] == '-'
if length == 1 and start_dash:
# Need to escape identifier that is a single `-` with no other characters
string.append('\\{}'.format(ident))
else:
for index, c in enumerate(ident):
c... | def escape(ident) | Escape identifier. | 2.486201 | 2.442711 | 1.017804 |
pseudo = None
m = self.re_pseudo_name.match(selector, index)
if m:
name = util.lower(css_unescape(m.group('name')))
pattern = self.patterns.get(name)
if pattern:
pseudo = pattern.match(selector, index)
if pseudo:
... | def match(self, selector, index) | Match the selector. | 4.821815 | 4.732815 | 1.018805 |
if relations:
sel = relations[0]
sel.relations.extend(relations[1:])
return ct.SelectorList([sel.freeze()])
else:
return ct.SelectorList() | def _freeze_relations(self, relations) | Freeze relation. | 7.33579 | 6.581553 | 1.114599 |
if self.no_match:
return ct.SelectorNull()
else:
return ct.Selector(
self.tag,
tuple(self.ids),
tuple(self.classes),
tuple(self.attributes),
tuple(self.nth),
tuple(self.selec... | def freeze(self) | Freeze self. | 6.130332 | 5.686028 | 1.07814 |
inverse = False
op = m.group('cmp')
case = util.lower(m.group('case')) if m.group('case') else None
parts = [css_unescape(a) for a in m.group('ns_attr').split('|')]
ns = ''
is_type = False
pattern2 = None
if len(parts) > 1:
ns = parts... | def parse_attribute_selector(self, sel, m, has_selector, quirks) | Create attribute selector from the returned regex match. | 3.077309 | 3.056513 | 1.006804 |
parts = [css_unescape(x) for x in m.group(0).split('|')]
if len(parts) > 1:
prefix = parts[0]
tag = parts[1]
else:
tag = parts[0]
prefix = None
sel.tag = ct.SelectorTag(tag, prefix)
has_selector = True
return has_s... | def parse_tag_pattern(self, sel, m, has_selector) | Parse tag pattern from regex match. | 3.315692 | 3.175302 | 1.044213 |
pseudo = util.lower(css_unescape(m.group('name')))
selector = self.custom.get(pseudo)
if selector is None:
raise SelectorSyntaxError(
"Undefined custom selector '{}' found at postion {}".format(pseudo, m.end(0)),
self.pattern,
... | def parse_pseudo_class_custom(self, sel, m, has_selector) | Parse custom pseudo class alias.
Compile custom selectors as we need them. When compiling a custom selector,
set it to `None` in the dictionary so we can avoid an infinite loop. | 5.184515 | 4.865182 | 1.065636 |
complex_pseudo = False
pseudo = util.lower(css_unescape(m.group('name')))
if m.group('open'):
complex_pseudo = True
if complex_pseudo and pseudo in PSEUDO_COMPLEX:
has_selector = self.parse_pseudo_open(sel, pseudo, has_selector, iselector, m.end(0))
... | def parse_pseudo_class(self, sel, m, has_selector, iselector, is_html) | Parse pseudo class. | 1.892315 | 1.890534 | 1.000942 |
mdict = m.groupdict()
if mdict.get('pseudo_nth_child'):
postfix = '_child'
else:
postfix = '_type'
mdict['name'] = util.lower(css_unescape(mdict['name']))
content = util.lower(mdict.get('nth' + postfix))
if content == 'even':
... | def parse_pseudo_nth(self, sel, m, has_selector, iselector) | Parse `nth` pseudo. | 2.875005 | 2.853676 | 1.007474 |
flags = FLG_PSEUDO | FLG_OPEN
if name == ':not':
flags |= FLG_NOT
if name == ':has':
flags |= FLG_RELATIVE
sel.selectors.append(self.parse_selectors(iselector, index, flags))
has_selector = True
return has_selector | def parse_pseudo_open(self, sel, name, has_selector, iselector, index) | Parse pseudo with opening bracket. | 5.094254 | 5.033452 | 1.01208 |
combinator = m.group('relation').strip()
if not combinator:
combinator = WS_COMBINATOR
if combinator == COMMA_COMBINATOR:
if not has_selector:
# If we've not captured any selector parts, the comma is either at the beginning of the pattern
... | def parse_has_combinator(self, sel, m, has_selector, selectors, rel_type, index) | Parse combinator tokens. | 5.385429 | 5.290143 | 1.018012 |
combinator = m.group('relation').strip()
if not combinator:
combinator = WS_COMBINATOR
if not has_selector:
# The only way we don't fail is if we are at the root level and quirks mode is enabled,
# and we've found no other selectors yet in this compo... | def parse_combinator(self, sel, m, has_selector, selectors, relations, is_pseudo, index) | Parse combinator tokens. | 6.027544 | 5.884726 | 1.024269 |
selector = m.group(0)
if selector.startswith('.'):
sel.classes.append(css_unescape(selector[1:]))
else:
sel.ids.append(css_unescape(selector[1:]))
has_selector = True
return has_selector | def parse_class_id(self, sel, m, has_selector) | Parse HTML classes and ids. | 2.960413 | 2.486229 | 1.190724 |
values = m.group('values')
patterns = []
for token in RE_VALUES.finditer(values):
if token.group('split'):
continue
value = token.group('value')
if value.startswith(("'", '"')):
value = css_unescape(value[1:-1], True)
... | def parse_pseudo_contains(self, sel, m, has_selector) | Parse contains. | 4.069114 | 3.815512 | 1.066466 |
values = m.group('values')
patterns = []
for token in RE_VALUES.finditer(values):
if token.group('split'):
continue
value = token.group('value')
if value.startswith(('"', "'")):
parts = css_unescape(value[1:-1], True).... | def parse_pseudo_lang(self, sel, m, has_selector) | Parse pseudo language. | 4.068581 | 3.953016 | 1.029235 |
value = ct.SEL_DIR_LTR if util.lower(m.group('dir')) == 'ltr' else ct.SEL_DIR_RTL
sel.flags |= value
has_selector = True
return has_selector | def parse_pseudo_dir(self, sel, m, has_selector) | Parse pseudo direction. | 7.11588 | 5.730907 | 1.241667 |
# Ignore whitespace and comments at start and end of pattern
m = RE_WS_BEGIN.search(pattern)
index = m.end(0) if m else 0
m = RE_WS_END.search(pattern)
end = (m.start(0) - 1) if m else (len(pattern) - 1)
if self.debug: # pragma: no cover
if self.qu... | def selector_iter(self, pattern) | Iterate selector tokens. | 3.374916 | 3.304499 | 1.021309 |
return self.parse_selectors(self.selector_iter(self.pattern), index, flags) | def process_selectors(self, index=0, flags=0) | Process selectors.
We do our own selectors as BeautifulSoup4 has some annoying quirks,
and we don't really need to do nth selectors or siblings or
descendants etc. | 11.810998 | 9.798994 | 1.205328 |
edit = None
for name, values in label_list.items():
color, description = values
if isinstance(name, tuple):
old_name = name[0]
new_name = name[1]
else:
old_name = name
new_name = name
if label.lower() == old_name.lower():
... | def find_label(label, label_color, label_description) | Find label. | 2.680322 | 2.653534 | 1.010095 |
updated = set()
for label in repo.get_labels():
edit = find_label(label.name, label.color, label.description)
if edit is not None:
print(' Updating {}: #{} "{}"'.format(edit.new, edit.color, edit.description))
label.edit(edit.new, edit.color, edit.description)
... | def update_labels(repo) | Update labels. | 2.193489 | 2.163813 | 1.013714 |
import getpass
user = input("User Name: ") # noqa
pswd = getpass.getpass('Password: ')
return Github(user, pswd) | def get_auth() | Get authentication. | 5.045118 | 4.873763 | 1.035159 |
if len(sys.argv) > 1 and os.path.exists(sys.argv[1]):
try:
with open(sys.argv[1], 'r') as f:
user_name, password = f.read().strip().split(':')
git = Github(user_name, password)
password = None
except Exception:
git = get_auth()
... | def main() | Main. | 2.889318 | 2.955536 | 0.977595 |
m = RE_VER.match(ver)
# Handle major, minor, micro
major = int(m.group('major'))
minor = int(m.group('minor')) if m.group('minor') else 0
micro = int(m.group('micro')) if m.group('micro') else 0
# Handle pre releases
if m.group('type'):
release = PRE_REL_MAP[m.group('type')]
... | def parse_version(ver, pre=False) | Parse version into a comparable Version tuple. | 2.24915 | 2.166104 | 1.038339 |
# Assemble major, minor, micro version and append `pre`, `post`, or `dev` if needed..
if self.micro == 0:
ver = "{}.{}".format(self.major, self.minor)
else:
ver = "{}.{}.{}".format(self.major, self.minor, self.micro)
if self._is_pre():
ver +=... | def _get_canonical(self) | Get the canonical output string. | 3.333762 | 3.244327 | 1.027567 |
# Fail on unexpected types.
if not cls.is_tag(tag):
raise TypeError("Expected a BeautifulSoup 'Tag', but instead recieved type {}".format(type(tag))) | def assert_valid_input(cls, tag) | Check if valid input tag or document. | 10.128628 | 8.929666 | 1.134267 |
import bs4
return isinstance(obj, (bs4.Comment, bs4.Declaration, bs4.CData, bs4.ProcessingInstruction)) | def is_special_string(obj) | Is special string. | 5.646356 | 4.947763 | 1.141194 |
return ((el.name if self.is_xml_tree(el) else util.lower(el.name)) == 'iframe') and self.is_html_tag(el) | def is_iframe(self, el) | Check if element is an `iframe`. | 7.655076 | 7.327609 | 1.044689 |
root = self.root and self.root is el
if not root:
parent = self.get_parent(el)
root = parent is not None and self.is_html and self.is_iframe(parent)
return root | def is_root(self, el) | Return whether element is a root element.
We check that the element is the root of the tree (which we have already pre-calculated),
and we check if it is the root element under an `iframe`. | 5.749985 | 3.979209 | 1.445007 |
if not no_iframe or not self.is_iframe(el):
for content in el.contents:
yield content | def get_contents(self, el, no_iframe=False) | Get contents or contents in reverse. | 4.37772 | 3.826323 | 1.144106 |
if not no_iframe or not self.is_iframe(el):
last = len(el.contents) - 1
if start is None:
index = last if reverse else 0
else:
index = start
end = -1 if reverse else last + 1
incr = -1 if reverse else 1
... | def get_children(self, el, start=None, reverse=False, tags=True, no_iframe=False) | Get children. | 3.000698 | 2.991842 | 1.00296 |
if not no_iframe or not self.is_iframe(el):
next_good = None
for child in el.descendants:
if next_good is not None:
if child is not next_good:
continue
next_good = None
is_tag = se... | def get_descendants(self, el, tags=True, no_iframe=False) | Get descendants. | 3.19757 | 3.181231 | 1.005136 |
parent = el.parent
if no_iframe and parent is not None and self.is_iframe(parent):
parent = None
return parent | def get_parent(self, el, no_iframe=False) | Get parent. | 3.336184 | 3.121232 | 1.068867 |
sibling = el.next_sibling
while not cls.is_tag(sibling) and sibling is not None:
sibling = sibling.next_sibling
return sibling | def get_next_tag(cls, el) | Get next sibling tag. | 3.661618 | 2.966142 | 1.234472 |
sibling = el.previous_sibling
while not cls.is_tag(sibling) and sibling is not None:
sibling = sibling.previous_sibling
return sibling | def get_previous_tag(cls, el) | Get previous sibling tag. | 3.589844 | 3.064833 | 1.171302 |
value = default
if el._is_xml:
try:
value = el.attrs[name]
except KeyError:
pass
else:
for k, v in el.attrs.items():
if util.lower(k) == name:
value = v
break
... | def get_attribute_by_name(el, name, default=None) | Get attribute by name. | 3.555025 | 3.347672 | 1.06194 |
classes = cls.get_attribute_by_name(el, 'class', [])
if isinstance(classes, util.ustr):
classes = RE_NOT_WS.findall(classes)
return classes | def get_classes(cls, el) | Get classes. | 8.735995 | 7.893437 | 1.106742 |
return ''.join(
[node for node in self.get_descendants(el, tags=False, no_iframe=no_iframe) if self.is_content_string(node)]
) | def get_text(self, el, no_iframe=False) | Get text. | 5.612234 | 5.659024 | 0.991732 |
max_days = LONG_MONTH
if month == FEB:
max_days = FEB_LEAP_MONTH if ((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0) else FEB_MONTH
elif month in MONTHS_30:
max_days = SHORT_MONTH
return 1 <= day <= max_days | def validate_day(year, month, day) | Validate day. | 3.153016 | 2.93545 | 1.074117 |
max_week = datetime.strptime("{}-{}-{}".format(12, 31, year), "%m-%d-%Y").isocalendar()[1]
if max_week == 1:
max_week = 53
return 1 <= week <= max_week | def validate_week(year, week) | Validate week. | 3.891196 | 3.4765 | 1.119285 |
parsed = None
if itype == "date":
m = RE_DATE.match(value)
if m:
year = int(m.group('year'), 10)
month = int(m.group('month'), 10)
day = int(m.group('day'), 10)
if cls.validate_year(year) and cls.validate_m... | def parse_value(cls, itype, value) | Parse the input value. | 1.317309 | 1.298387 | 1.014573 |
if self.supports_namespaces():
namespace = ''
ns = el.namespace
if ns:
namespace = ns
else:
namespace = NS_XHTML
return namespace | def get_tag_ns(self, el) | Get tag namespace. | 6.853922 | 5.572846 | 1.229878 |
name = self.get_tag_name(el)
return util.lower(name) if name is not None and not self.is_xml else name | def get_tag(self, el) | Get tag. | 8.263759 | 7.393437 | 1.117715 |
prefix = self.get_prefix_name(el)
return util.lower(prefix) if prefix is not None and not self.is_xml else prefix | def get_prefix(self, el) | Get prefix. | 9.405027 | 8.161655 | 1.152343 |
for node in self.get_children(el, tags=False):
# Analyze child text nodes
if self.is_tag(node):
# Avoid analyzing certain elements specified in the specification.
direction = DIR_MAP.get(util.lower(self.get_attribute_by_name(node, 'dir', '')), ... | def find_bidi(self, el) | Get directionality from element text. | 5.396224 | 5.162448 | 1.045284 |
value = None
if self.supports_namespaces():
value = None
# If we have not defined namespaces, we can't very well find them, so don't bother trying.
if prefix:
ns = self.namespaces.get(prefix)
if ns is None and prefix != '*':
... | def match_attribute_name(self, el, attr, prefix) | Match attribute name and return value if it exists. | 6.117806 | 5.911597 | 1.034882 |
match = True
namespace = self.get_tag_ns(el)
default_namespace = self.namespaces.get('')
tag_ns = '' if tag.prefix is None else self.namespaces.get(tag.prefix, None)
# We must match the default namespace if one is not provided
if tag.prefix is None and (default_... | def match_namespace(self, el, tag) | Match the namespace of the element. | 4.508564 | 4.384207 | 1.028365 |
match = True
if attributes:
for a in attributes:
value = self.match_attribute_name(el, a.attribute, a.prefix)
pattern = a.xml_type_pattern if self.is_xml and a.xml_type_pattern else a.pattern
if isinstance(value, list):
... | def match_attributes(self, el, attributes) | Match attributes. | 3.309111 | 3.114988 | 1.062319 |
name = (util.lower(tag.name) if not self.is_xml and tag.name is not None else tag.name)
return not (
name is not None and
name not in (self.get_tag(el), '*')
) | def match_tagname(self, el, tag) | Match tag name. | 7.785077 | 6.481961 | 1.201037 |
match = True
if tag is not None:
# Verify namespace
if not self.match_namespace(el, tag):
match = False
if not self.match_tagname(el, tag):
match = False
return match | def match_tag(self, el, tag) | Match the tag. | 3.812284 | 3.356091 | 1.13593 |
found = False
if relation[0].rel_type == REL_PARENT:
parent = self.get_parent(el, no_iframe=self.iframe_restrict)
while not found and parent:
found = self.match_selectors(parent, relation)
parent = self.get_parent(parent, no_iframe=self.i... | def match_past_relations(self, el, relation) | Match past relationship. | 2.121911 | 2.098878 | 1.010974 |
match = False
children = self.get_descendants if recursive else self.get_children
for child in children(parent, no_iframe=self.iframe_restrict):
match = self.match_selectors(child, relation)
if match:
break
return match | def match_future_child(self, parent, relation, recursive=False) | Match future child. | 5.689409 | 5.575224 | 1.020481 |
found = False
if relation[0].rel_type == REL_HAS_PARENT:
found = self.match_future_child(el, relation, True)
elif relation[0].rel_type == REL_HAS_CLOSE_PARENT:
found = self.match_future_child(el, relation)
elif relation[0].rel_type == REL_HAS_SIBLING:
... | def match_future_relations(self, el, relation) | Match future relationship. | 2.389908 | 2.338819 | 1.021844 |
found = False
if relation[0].rel_type.startswith(':'):
found = self.match_future_relations(el, relation)
else:
found = self.match_past_relations(el, relation)
return found | def match_relations(self, el, relation) | Match relationship to other elements. | 4.452347 | 4.316449 | 1.031484 |
found = True
for i in ids:
if i != self.get_attribute_by_name(el, 'id', ''):
found = False
break
return found | def match_id(self, el, ids) | Match element's ID. | 5.006849 | 4.250157 | 1.178038 |
current_classes = self.get_classes(el)
found = True
for c in classes:
if c not in current_classes:
found = False
break
return found | def match_classes(self, el, classes) | Match element's classes. | 3.118884 | 2.610764 | 1.194625 |
return(
(self.get_tag(child) == self.get_tag(el)) and
(self.get_tag_ns(child) == self.get_tag_ns(el))
) | def match_nth_tag_type(self, el, child) | Match tag type for `nth` matches. | 3.262023 | 3.181597 | 1.025279 |
matched = True
for n in nth:
matched = False
if n.selectors and not self.match_selectors(el, n.selectors):
break
parent = self.get_parent(el)
if parent is None:
parent = self.create_fake_parent(el)
las... | def match_nth(self, el, nth) | Match `nth` elements. | 4.537304 | 4.507852 | 1.006533 |
is_empty = True
for child in self.get_children(el, tags=False):
if self.is_tag(child):
is_empty = False
break
elif self.is_content_string(child) and RE_NOT_EMPTY.search(child):
is_empty = False
break
... | def match_empty(self, el) | Check if element is empty (if requested). | 3.933377 | 3.449668 | 1.140219 |
match = True
for sel in selectors:
if not self.match_selectors(el, sel):
match = False
return match | def match_subselectors(self, el, selectors) | Match selectors. | 3.694434 | 3.051526 | 1.210684 |
match = True
content = None
for contain_list in contains:
if content is None:
content = self.get_text(el, no_iframe=self.is_html)
found = False
for text in contain_list.text:
if text in content:
fou... | def match_contains(self, el, contains) | Match element if it contains text. | 4.529285 | 4.104909 | 1.103383 |
match = False
# Find this input's form
form = None
parent = self.get_parent(el, no_iframe=True)
while parent and form is None:
if self.get_tag(parent) == 'form' and self.is_html_tag(parent):
form = parent
else:
pa... | def match_default(self, el) | Match default. | 3.74838 | 3.691196 | 1.015492 |
match = False
name = self.get_attribute_by_name(el, 'name')
def get_parent_form(el):
form = None
parent = self.get_parent(el, no_iframe=True)
while form is None:
if self.get_tag(parent) == 'form' and self.is_html_tag(par... | def match_indeterminate(self, el) | Match default. | 2.757062 | 2.734687 | 1.008182 |
match = False
has_ns = self.supports_namespaces()
root = self.root
has_html_namespace = self.has_html_namespace
# Walk parents looking for `lang` (HTML) or `xml:lang` XML property.
parent = el
found_lang = None
last = None
while not foun... | def match_lang(self, el, langs) | Match languages. | 3.018803 | 2.987338 | 1.010533 |
# If we have to match both left and right, we can't match either.
if directionality & ct.SEL_DIR_LTR and directionality & ct.SEL_DIR_RTL:
return False
if el is None or not self.is_html_tag(el):
return False
# Element has defined direction of left to ri... | def match_dir(self, el, directionality) | Check directionality. | 2.88703 | 2.863652 | 1.008164 |
out_of_range = False
itype = self.get_attribute_by_name(el, 'type').lower()
mn = self.get_attribute_by_name(el, 'min', None)
if mn is not None:
mn = Inputs.parse_value(itype, mn)
mx = self.get_attribute_by_name(el, 'max', None)
if mx is not None:
... | def match_range(self, el, condition) | Match range.
Behavior is modeled after what we see in browsers. Browsers seem to evaluate
if the value is out of range, and if not, it is in range. So a missing value
will not evaluate out of range; therefore, value is in range. Personally, I
feel like this should evaluate as neither in... | 2.505399 | 2.447089 | 1.023828 |
name = self.get_tag(el)
return (
name.find('-') == -1 or
name.find(':') != -1 or
self.get_prefix(el) is not None
) | def match_defined(self, el) | Match defined.
`:defined` is related to custom elements in a browser.
- If the document is XML (not XHTML), all tags will match.
- Tags that are not custom (don't have a hyphen) are marked defined.
- If the tag has a prefix (without or without a namespace), it will not match.
... | 5.786547 | 4.045404 | 1.4304 |
match = False
is_not = selectors.is_not
is_html = selectors.is_html
# Internal selector lists that use the HTML flag, will automatically get the `html` namespace.
if is_html:
namespaces = self.namespaces
iframe_restrict = self.iframe_restrict
... | def match_selectors(self, el, selectors) | Check if element matches one of the selectors. | 3.548921 | 3.54455 | 1.001233 |
if limit < 1:
limit = None
for child in self.get_descendants(self.tag):
if self.match(child):
yield child
if limit is not None:
limit -= 1
if limit < 1:
break | def select(self, limit=0) | Match all tags under the targeted tag. | 4.118438 | 3.277686 | 1.256508 |
current = self.tag
closest = None
while closest is None and current is not None:
if self.match(current):
closest = current
else:
current = self.get_parent(current)
return closest | def closest(self) | Match closest ancestor. | 4.356379 | 3.618756 | 1.203833 |
def filter(self): # noqa A001
return [tag for tag in self.get_contents(self.tag) if not self.is_navigable_string(tag) and self.match(tag)] | Filter tag's children. | null | null | null | |
return not self.is_doc(el) and self.is_tag(el) and self.match_selectors(el, self.selectors) | def match(self, el) | Match. | 6.369496 | 6.154245 | 1.034976 |
if limit < 1:
limit = None
for child in self.get_descendants(self.tag, tags=False):
if self.is_comment(child):
yield child
if limit is not None:
limit -= 1
if limit < 1:
bre... | def get_comments(self, limit=0) | Get comments. | 4.114154 | 3.908249 | 1.052685 |
return CSSMatch(self.selectors, tag, self.namespaces, self.flags).match(tag) | def match(self, tag) | Match. | 18.249794 | 14.185442 | 1.286516 |
return CSSMatch(self.selectors, tag, self.namespaces, self.flags).closest() | def closest(self, tag) | Match closest ancestor. | 28.698742 | 19.111601 | 1.50164 |
return CSSMatch(self.selectors, iterable, self.namespaces, self.flags).filter()
else:
return [node for node in iterable if not CSSMatch.is_navigable_string(node) and self.match(node)] | def filter(self, iterable): # noqa A001
if CSSMatch.is_tag(iterable) | Filter.
`CSSMatch` can cache certain searches for tags of the same document,
so if we are given a tag, all tags are from the same document,
and we can take advantage of the optimization.
Any other kind of iterable could have tags from different documents or detached tags,
so fo... | 6.024602 | 6.85924 | 0.878319 |
return [comment for comment in CommentsMatch(tag).get_comments(limit)] | def comments(self, tag, limit=0) | Get comments only. | 19.325962 | 17.212065 | 1.122815 |
for comment in CommentsMatch(tag).get_comments(limit):
yield comment | def icomments(self, tag, limit=0) | Iterate comments only. | 19.198608 | 15.066796 | 1.274233 |
tags = self.select(tag, limit=1)
return tags[0] if tags else None | def select_one(self, tag) | Select a single tag. | 5.64672 | 4.356817 | 1.296065 |
for el in CSSMatch(self.selectors, tag, self.namespaces, self.flags).select(limit):
yield el | def iselect(self, tag, limit=0) | Iterate the specified tags. | 17.47974 | 14.84416 | 1.17755 |
new_string = []
for c in string:
o = ord(c)
new_string.append(chr(o + 32) if UC_A <= o <= UC_Z else c)
return ''.join(new_string) | def lower(string) | Lower. | 3.526256 | 3.110875 | 1.133525 |
o = ord(c)
new_string.append(chr(o - 32) if LC_A <= o <= LC_Z else c)
return ''.join(new_string) | def upper(string): # pragma: no cover
new_string = []
for c in string | Lower. | 5.689211 | 5.748389 | 0.989705 |
if len(c) == 2: # pragma: no cover
high, low = [ord(p) for p in c]
ordinal = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000
else:
ordinal = ord(c)
return ordinal | def uord(c) | Get Unicode ordinal. | 2.719096 | 2.323659 | 1.170178 |
@wraps(func)
def _func(*args, **kwargs):
warnings.warn(
"'{}' is deprecated. {}".format(func.__name__, message),
category=DeprecationWarning,
stacklevel=stacklevel
)
return func(*args, **kwargs)
return _func
... | def deprecated(message, stacklevel=2): # pragma: no cover
def _decorator(func) | Raise a `DeprecationWarning` when wrapped function/method is called.
Borrowed from https://stackoverflow.com/a/48632082/866026 | 1.972821 | 2.037551 | 0.968231 |
def warn_deprecated(message, stacklevel=2): # pragma: no cover
warnings.warn(
message,
category=DeprecationWarning,
stacklevel=stacklevel
) | Warn deprecated. | null | null | null | |
last = 0
current_line = 1
col = 1
text = []
line = 1
# Split pattern by newline and handle the text before the newline
for m in RE_PATTERN_LINE_SPLIT.finditer(pattern):
linetext = pattern[last:m.start(0)]
if not len(m.group(0)) and not len(text):
indent = '... | def get_pattern_context(pattern, index) | Get the pattern context. | 4.329061 | 4.313479 | 1.003612 |
import traceback
import bs4 # noqa: F401
# Acquire source code line context
paths = (MODULE, sys.modules['bs4'].__path__[0])
tb = traceback.extract_stack()
previous = None
filename = None
lineno = None
for entry in tb:
if (PY35 and entry.filename.startswith(paths)) or... | def warn_quirks(message, recommend, pattern, index) | Warn quirks. | 6.167274 | 6.184664 | 0.997188 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.