code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
try: # FIXME: Use `github3.Repository.contributors` to get this information contrib_url = gh.repository_with_id(repo_id).contributors_url r = requests.get(contrib_url) if r.status_code == 200: contributors = r.json() def get_author(contributor): ...
def get_contributors(gh, repo_id)
Get list of contributors to a repository.
2.939245
2.967424
0.990504
gh = GitHubAPI(user_id=token.remote_account.user_id) with db.session.begin_nested(): gh.init_account() # Create user <-> external id link. oauth_link_external_id( token.remote_account.user, dict(id=str(gh.account.extra_data['id']), method="github") )
def account_setup(remote, token=None, response=None, account_setup=None)
Setup user account.
9.653158
9.465898
1.019783
gh = GitHubAPI(user_id=token.remote_account.user_id) repos = [r.id for r in gh.api.repositories() if r.permissions['admin']] sync_hooks.delay(token.remote_account.user_id, repos)
def account_post_init(remote, token=None)
Perform post initialization.
7.169497
7.452936
0.96197
# User must be authenticated if not current_user.is_authenticated: return current_app.login_manager.unauthorized() external_method = 'github' external_ids = [i.id for i in current_user.external_identifiers if i.method == external_method] if external_ids: oau...
def disconnect(remote)
Disconnect callback handler for GitHub.
4.423737
4.36184
1.01419
attrs = { 'auto_close_field': publication_date_field, 'auto_moderate_field': publication_date_field, 'enable_field': enable_comments_field, } ModerationClass = type(ParentModel.__name__ + 'Moderator', (FluentCommentsModerator,), attrs) moderator.register(ParentModel, Moderat...
def moderate_model(ParentModel, publication_date_field=None, enable_comments_field=None)
Register a parent model (e.g. ``Blog`` or ``Article``) that should receive comment moderation. :param ParentModel: The parent model, e.g. a ``Blog`` or ``Article`` model. :param publication_date_field: The field name of a :class:`~django.db.models.DateTimeField` in the parent model which stores the publication...
4.151262
4.548418
0.912683
moderator = get_model_moderator(content_object.__class__) if moderator is None: return True # Check the 'enable_field', 'auto_close_field' and 'close_after', # by reusing the basic Django policies. return CommentModerator.allow(moderator, None, content_object, None)
def comments_are_open(content_object)
Return whether comments are still open for a given target object.
9.394444
8.953374
1.049263
moderator = get_model_moderator(content_object.__class__) if moderator is None: return False # Check the 'auto_moderate_field', 'moderate_after', # by reusing the basic Django policies. return CommentModerator.moderate(moderator, None, content_object, None)
def comments_are_moderated(content_object)
Return whether comments are moderated for a given target object.
8.434027
8.009002
1.053068
# Parent class check if not super(FluentCommentsModerator, self).allow(comment, content_object, request): return False # Akismet check if self.akismet_check: akismet_result = akismet_check(comment, content_object, request) if self.akismet_che...
def allow(self, comment, content_object, request)
Determine whether a given comment is allowed to be posted on a given object. Returns ``True`` if the comment should be allowed, ``False`` otherwise.
3.545572
3.586064
0.988708
# Soft delete checks are done first, so these comments are not mistakenly "just moderated" # for expiring the `close_after` date, but correctly get marked as spam instead. # This helps staff to quickly see which comments need real moderation. if self.akismet_check: ...
def moderate(self, comment, content_object, request)
Determine whether a given comment on a given object should be allowed to show up immediately, or should be marked non-public and await approval. Returns ``True`` if the comment should be moderated (marked non-public), ``False`` otherwise.
6.415975
6.277433
1.02207
if not self.email_notification: return send_comment_posted(comment, request)
def email(self, comment, content_object, request)
Overwritten for a better email notification.
10.979377
8.303303
1.32229
recipient_list = [manager_tuple[1] for manager_tuple in settings.MANAGERS] site = get_current_site(request) content_object = comment.content_object content_title = force_text(content_object) if comment.is_removed: subject = u'[{0}] Spam comment on "{1}"'.format(site.name, content_title...
def send_comment_posted(comment, request)
Send the email to staff that an comment was posted. While the django_comments module has email support, it doesn't pass the 'request' to the context. This also changes the subject to show the page title.
2.230723
2.231821
0.999508
# Process the template line. tag_name, args, kwargs = parse_token_kwargs( parser, token, allowed_kwargs=cls.allowed_kwargs, compile_args=False, # Only overrule here, keep at render() phase. compile_kwargs=cls.compile_kwargs ) # r...
def parse(cls, parser, token)
Custom parsing for the ``{% ajax_comment_tags for ... %}`` tag.
6.097346
5.907145
1.032198
target_object = tag_args[0] # moved one spot due to .pop(0) new_context = { 'STATIC_URL': parent_context.get('STATIC_URL', None), 'USE_THREADEDCOMMENTS': appsettings.USE_THREADEDCOMMENTS, 'target_object': target_object, } # Be configuration ...
def get_context_data(self, parent_context, *tag_args, **tag_kwargs)
The main logic for the inclusion node, analogous to ``@register.inclusion_node``.
4.184677
4.190144
0.998695
ctype = ContentType.objects.get_for_id(comment.content_type_id) return [ "comments/%s/%s/comment.html" % (ctype.app_label, ctype.model), "comments/%s/comment.html" % ctype.app_label, "comments/comment.html" ]
def get_comment_template_name(comment)
Internal function for the rendering of comments.
1.88657
1.862339
1.013011
# Writing the label values into the field placeholders. # This is done at rendering time, so the Form.__init__() could update any labels before. # Django 1.11 no longer lets EmailInput or URLInput inherit from TextInput, # so checking for `Input` instead while excluding `HiddenI...
def render_layout(self, form, context, template_pack=TEMPLATE_PACK)
Copy any field label to the ``placeholder`` attribute. Note, this method is called when :attr:`layout` is defined.
7.456183
7.163785
1.040816
qs = get_comments_model().objects.for_model(content_object) if not include_moderated: qs = qs.filter(is_public=True, is_removed=False) return qs
def get_comments_for_model(content_object, include_moderated=False)
Return the QuerySet with all comments for a given model.
2.538637
2.319546
1.094454
if 'captcha' not in ordering: raise ImproperlyConfigured( "When using 'FLUENT_COMMENTS_FIELD_ORDER', " "make sure the 'captcha' field included too to use '{}' form. ".format( self.__class__.__name__ ) ) ...
def _reorder_fields(self, ordering)
Test that the 'captcha' field is really present. This could be broken by a bad FLUENT_COMMENTS_FIELD_ORDER configuration.
8.07149
5.05553
1.596567
if not request.is_ajax(): return HttpResponseBadRequest("Expecting Ajax call") # This is copied from django_comments. # Basically that view does too much, and doesn't offer a hook to change the rendering. # The request object is not passed to next_redirect for example. # # This is ...
def post_comment_ajax(request, using=None)
Post a comment, via an Ajax call.
2.879929
2.863876
1.005605
template = '{0}/layout/field_errors.html'.format(appsettings.CRISPY_TEMPLATE_PACK) return render_to_string(template, { 'field': field, 'form_show_errors': True, })
def _render_errors(field)
Render form errors in crispy-forms style.
4.180565
3.337553
1.252584
global form_class from fluent_comments import appsettings if form_class is None: if appsettings.FLUENT_COMMENTS_FORM_CLASS: from django.utils.module_loading import import_string form_class = import_string(appsettings.FLUENT_COMMENTS_FORM_CLASS) else: ...
def get_form()
Return the form to use for commenting.
2.212231
2.041393
1.083687
if appsettings.FLUENT_COMMENTS_DEFAULT_MODERATOR == 'default': # Perform spam checks return moderation.FluentCommentsModerator(None) elif appsettings.FLUENT_COMMENTS_DEFAULT_MODERATOR == 'deny': # Deny all comments not from known registered models. return moderation.AlwaysDe...
def load_default_moderator()
Find a moderator object
3.818441
3.788697
1.007851
content_object = comment.content_object moderator = moderation.get_model_moderator(content_object.__class__) if moderator and comment.__class__ is not CommentModel: # Help with some hard to diagnose problems. The default Django moderator connects # to the configured comment model. When ...
def on_comment_will_be_posted(sender, comment, request, **kwargs)
Make sure both the Ajax and regular comments are checked for moderation. This signal is also used to link moderators to the comment posting.
5.752176
5.691848
1.010599
# The default moderator will likely not check things like "auto close". # It can still provide akismet and bad word checking. if not default_moderator.allow(comment, content_object, request): # Comment will be disallowed outright (HTTP 403 response) return False if default_moderato...
def _run_default_moderator(comment, content_object, request)
Run the default moderator
8.571913
8.790621
0.97512
content_object = comment.content_object moderator = moderation.get_model_moderator(content_object.__class__) if moderator is None or comment.__class__ is not CommentModel: # No custom moderator means no email would be sent. # This still pass the comment to the default moderator. ...
def on_comment_posted(sender, comment, request, **kwargs)
Send email notification of a new comment to site staff when email notifications have been requested.
6.528943
6.329392
1.031528
# Return previously cached response akismet_result = getattr(comment, '_akismet_result_', None) if akismet_result is not None: return akismet_result # Get Akismet data AKISMET_API_KEY = appsettings.AKISMET_API_KEY if not AKISMET_API_KEY: raise ImproperlyConfigured('You must...
def akismet_check(comment, content_object, request)
Connects to Akismet and evaluates to True if Akismet marks this comment as spam. :rtype: akismet.SpamStatus
2.5646
2.602924
0.985277
msg = msg.strip() if msg.startswith("runtime error:"): raise exception.OverpassRuntimeError(msg=msg) elif msg.startswith("runtime remark:"): raise exception.OverpassRuntimeRemark(msg=msg) raise exception.OverpassUnknownError(msg=msg)
def _handle_remark_msg(self, msg)
Try to parse the message provided with the remark tag or element. :param str msg: The message :raises overpy.exception.OverpassRuntimeError: If message starts with 'runtime error:' :raises overpy.exception.OverpassRuntimeRemark: If message starts with 'runtime remark:' :raises overpy.ex...
4.491766
2.071954
2.167889
if not isinstance(query, bytes): query = query.encode("utf-8") retry_num = 0 retry_exceptions = [] do_retry = True if self.max_retry_count > 0 else False while retry_num <= self.max_retry_count: if retry_num > 0: time.sleep(self.r...
def query(self, query)
Query the Overpass API :param String|Bytes query: The query string in Overpass QL :return: The parsed result :rtype: overpy.Result
2.175782
2.139175
1.017113
if isinstance(data, bytes): data = data.decode(encoding) data = json.loads(data, parse_float=Decimal) if "remark" in data: self._handle_remark_msg(msg=data.get("remark")) return Result.from_json(data, api=self)
def parse_json(self, data, encoding="utf-8")
Parse raw response from Overpass service. :param data: Raw JSON Data :type data: String or Bytes :param encoding: Encoding to decode byte string :type encoding: String :return: Result object :rtype: overpy.Result
4.667569
3.878443
1.203465
if not isinstance(other, Result): raise ValueError("Provided argument has to be instance of overpy:Result()") other_collection_map = {Node: other.nodes, Way: other.ways, Relation: other.relations, Area: other.areas} for element_type, own_collection in self._class_collection...
def expand(self, other)
Add all elements from an other result to the list of elements of this result object. It is used by the auto resolve feature. :param other: Expand the result with the elements from this result. :type other: overpy.Result :raises ValueError: If provided parameter is not instance of :clas...
4.616379
3.803428
1.213741
if is_valid_type(element, Element): self._class_collection_map[element.__class__].setdefault(element.id, element)
def append(self, element)
Append a new element to the result. :param element: The element to append :type element: overpy.Element
10.068097
11.245807
0.895276
result = [] if elem_id is not None: try: result = [self._class_collection_map[filter_cls][elem_id]] except KeyError: result = [] else: for e in self._class_collection_map[filter_cls].values(): result.app...
def get_elements(self, filter_cls, elem_id=None)
Get a list of elements from the result and filter the element type by a class. :param filter_cls: :param elem_id: ID of the object :type elem_id: Integer :return: List of available elements :rtype: List
2.424708
2.738659
0.885363
result = cls(api=api) for elem_cls in [Node, Way, Relation, Area]: for element in data.get("elements", []): e_type = element.get("type") if hasattr(e_type, "lower") and e_type.lower() == elem_cls._type_value: result.append(elem_cls...
def from_json(cls, data, api=None)
Create a new instance and load data from json object. :param data: JSON data returned by the Overpass API :type data: Dict :param api: :type api: overpy.Overpass :return: New instance of Result object :rtype: overpy.Result
4.129535
3.574597
1.155245
if parser is None: if isinstance(data, str): parser = XML_PARSER_SAX else: parser = XML_PARSER_DOM result = cls(api=api) if parser == XML_PARSER_DOM: import xml.etree.ElementTree as ET if isinstance(data, s...
def from_xml(cls, data, api=None, parser=None)
Create a new instance and load data from xml data or object. .. note:: If parser is set to None, the functions tries to find the best parse. By default the SAX parser is chosen if a string is provided as data. The parser is set to DOM if an xml.etree.ElementTree.Elem...
2.966142
2.58076
1.149329
areas = self.get_areas(area_id=area_id) if len(areas) == 0: if resolve_missing is False: raise exception.DataIncomplete("Resolve missing area is disabled") query = ("\n" "[out:json];\n" "area({area_id});\n" ...
def get_area(self, area_id, resolve_missing=False)
Get an area by its ID. :param area_id: The area ID :type area_id: Integer :param resolve_missing: Query the Overpass API if the area is missing in the result set. :return: The area :rtype: overpy.Area :raises overpy.exception.DataIncomplete: The requested way is not avai...
3.192134
2.721116
1.173097
return self.get_elements(Area, elem_id=area_id, **kwargs)
def get_areas(self, area_id=None, **kwargs)
Alias for get_elements() but filter the result by Area :param area_id: The Id of the area :type area_id: Integer :return: List of elements
7.119244
8.122379
0.876497
nodes = self.get_nodes(node_id=node_id) if len(nodes) == 0: if not resolve_missing: raise exception.DataIncomplete("Resolve missing nodes is disabled") query = ("\n" "[out:json];\n" "node({node_id});\n" ...
def get_node(self, node_id, resolve_missing=False)
Get a node by its ID. :param node_id: The node ID :type node_id: Integer :param resolve_missing: Query the Overpass API if the node is missing in the result set. :return: The node :rtype: overpy.Node :raises overpy.exception.DataIncomplete: At least one referenced node i...
3.006658
2.577747
1.16639
return self.get_elements(Node, elem_id=node_id, **kwargs)
def get_nodes(self, node_id=None, **kwargs)
Alias for get_elements() but filter the result by Node() :param node_id: The Id of the node :type node_id: Integer :return: List of elements
7.616557
8.679691
0.877515
relations = self.get_relations(rel_id=rel_id) if len(relations) == 0: if resolve_missing is False: raise exception.DataIncomplete("Resolve missing relations is disabled") query = ("\n" "[out:json];\n" "relation({...
def get_relation(self, rel_id, resolve_missing=False)
Get a relation by its ID. :param rel_id: The relation ID :type rel_id: Integer :param resolve_missing: Query the Overpass API if the relation is missing in the result set. :return: The relation :rtype: overpy.Relation :raises overpy.exception.DataIncomplete: The requeste...
3.25958
2.815489
1.157731
return self.get_elements(Relation, elem_id=rel_id, **kwargs)
def get_relations(self, rel_id=None, **kwargs)
Alias for get_elements() but filter the result by Relation :param rel_id: Id of the relation :type rel_id: Integer :return: List of elements
7.357014
7.455112
0.986841
ways = self.get_ways(way_id=way_id) if len(ways) == 0: if resolve_missing is False: raise exception.DataIncomplete("Resolve missing way is disabled") query = ("\n" "[out:json];\n" "way({way_id});\n" ...
def get_way(self, way_id, resolve_missing=False)
Get a way by its ID. :param way_id: The way ID :type way_id: Integer :param resolve_missing: Query the Overpass API if the way is missing in the result set. :return: The way :rtype: overpy.Way :raises overpy.exception.DataIncomplete: The requested way is not available in...
2.833235
2.641169
1.07272
return self.get_elements(Way, elem_id=way_id, **kwargs)
def get_ways(self, way_id=None, **kwargs)
Alias for get_elements() but filter the result by Way :param way_id: The Id of the way :type way_id: Integer :return: List of elements
6.076969
7.268125
0.836112
center_lat = None center_lon = None center = data.get("center") if isinstance(center, dict): center_lat = center.get("lat") center_lon = center.get("lon") if center_lat is None or center_lon is None: raise ValueError("Unable to...
def get_center_from_json(cls, data)
Get center information from json data :param data: json data :return: tuple with two elements: lat and lon :rtype: tuple
2.226508
2.362587
0.942403
if child.tag.lower() != cls._type_value: raise exception.ElementDataWrongType( type_expected=cls._type_value, type_provided=child.tag.lower() ) tags = {} for sub_child in child: if sub_child.tag.lower() == "tag": ...
def from_xml(cls, child, result=None)
Create new way element from XML data :param child: XML node to be parsed :type child: xml.etree.ElementTree.Element :param result: The result this node belongs to :type result: overpy.Result :return: New Way oject :rtype: overpy.Way :raises overpy.exception.Eleme...
2.617192
2.338133
1.119351
if data.get("type") != cls._type_value: raise exception.ElementDataWrongType( type_expected=cls._type_value, type_provided=data.get("type") ) tags = data.get("tags", {}) node_id = data.get("id") lat = data.get("lat") ...
def from_json(cls, data, result=None)
Create new Node element from JSON data :param data: Element data from JSON :type data: Dict :param result: The result this element belongs to :type result: overpy.Result :return: New instance of Node :rtype: overpy.Node :raises overpy.exception.ElementDataWrongTy...
2.590113
2.165703
1.195969
if child.tag.lower() != cls._type_value: raise exception.ElementDataWrongType( type_expected=cls._type_value, type_provided=child.tag.lower() ) tags = {} for sub_child in child: if sub_child.tag.lower() == "tag": ...
def from_xml(cls, child, result=None)
Create new way element from XML data :param child: XML node to be parsed :type child: xml.etree.ElementTree.Element :param result: The result this node belongs to :type result: overpy.Result :return: New Way oject :rtype: overpy.Node :raises overpy.exception.Elem...
2.176021
1.96866
1.105331
result = [] resolved = False for node_id in self._node_ids: try: node = self._result.get_node(node_id) except exception.DataIncomplete: node = None if node is not None: result.append(node) ...
def get_nodes(self, resolve_missing=False)
Get the nodes defining the geometry of the way :param resolve_missing: Try to resolve missing nodes. :type resolve_missing: Boolean :return: List of nodes :rtype: List of overpy.Node :raises overpy.exception.DataIncomplete: At least one referenced node is not available in the re...
3.010983
2.581548
1.166348
if data.get("type") != cls._type_value: raise exception.ElementDataWrongType( type_expected=cls._type_value, type_provided=data.get("type") ) tags = data.get("tags", {}) way_id = data.get("id") node_ids = data.get("nodes"...
def from_json(cls, data, result=None)
Create new Way element from JSON data :param data: Element data from JSON :type data: Dict :param result: The result this element belongs to :type result: overpy.Result :return: New instance of Way :rtype: overpy.Way :raises overpy.exception.ElementDataWrongType:...
2.816895
2.352754
1.197276
if child.tag.lower() != cls._type_value: raise exception.ElementDataWrongType( type_expected=cls._type_value, type_provided=child.tag.lower() ) tags = {} node_ids = [] center_lat = None center_lon = None f...
def from_xml(cls, child, result=None)
Create new way element from XML data :param child: XML node to be parsed :type child: xml.etree.ElementTree.Element :param result: The result this node belongs to :type result: overpy.Result :return: New Way oject :rtype: overpy.Way :raises overpy.exception.Eleme...
2.376032
2.116454
1.122647
if data.get("type") != cls._type_value: raise exception.ElementDataWrongType( type_expected=cls._type_value, type_provided=data.get("type") ) tags = data.get("tags", {}) rel_id = data.get("id") (center_lat, center_lon) = ...
def from_json(cls, data, result=None)
Create new Relation element from JSON data :param data: Element data from JSON :type data: Dict :param result: The result this element belongs to :type result: overpy.Result :return: New instance of Relation :rtype: overpy.Relation :raises overpy.exception.Elemen...
2.651139
2.298977
1.153182
if child.tag.lower() != cls._type_value: raise exception.ElementDataWrongType( type_expected=cls._type_value, type_provided=child.tag.lower() ) tags = {} members = [] center_lat = None center_lon = None su...
def from_xml(cls, child, result=None)
Create new way element from XML data :param child: XML node to be parsed :type child: xml.etree.ElementTree.Element :param result: The result this node belongs to :type result: overpy.Result :return: New Way oject :rtype: overpy.Relation :raises overpy.exception....
2.41029
2.220741
1.085354
if data.get("type") != cls._type_value: raise exception.ElementDataWrongType( type_expected=cls._type_value, type_provided=data.get("type") ) ref = data.get("ref") role = data.get("role") attributes = {} ignore = ...
def from_json(cls, data, result=None)
Create new RelationMember element from JSON data :param child: Element data from JSON :type child: Dict :param result: The result this element belongs to :type result: overpy.Result :return: New instance of RelationMember :rtype: overpy.RelationMember :raises ove...
2.967635
2.518195
1.178477
if child.attrib.get("type") != cls._type_value: raise exception.ElementDataWrongType( type_expected=cls._type_value, type_provided=child.tag.lower() ) ref = child.attrib.get("ref") if ref is not None: ref = int(ref) ...
def from_xml(cls, child, result=None)
Create new RelationMember from XML data :param child: XML node to be parsed :type child: xml.etree.ElementTree.Element :param result: The result this element belongs to :type result: overpy.Result :return: New relation member oject :rtype: overpy.RelationMember :...
2.883575
2.434872
1.184282
if name in self.ignore_start: return try: handler = getattr(self, '_handle_start_%s' % name) except AttributeError: raise KeyError("Unknown element start '%s'" % name) handler(attrs)
def startElement(self, name, attrs)
Handle opening elements. :param name: Name of the element :type name: String :param attrs: Attributes of the element :type attrs: Dict
3.766956
4.249985
0.886346
if name in self.ignore_end: return try: handler = getattr(self, '_handle_end_%s' % name) except AttributeError: raise KeyError("Unknown element end '%s'" % name) handler()
def endElement(self, name)
Handle closing elements :param name: Name of the element :type name: String
3.962454
4.430992
0.894259
center_lat = attrs.get("lat") center_lon = attrs.get("lon") if center_lat is None or center_lon is None: raise ValueError("Unable to get lat or lon of way center.") self._curr["center_lat"] = Decimal(center_lat) self._curr["center_lon"] = Decimal(center_lon)
def _handle_start_center(self, attrs)
Handle opening center element :param attrs: Attributes of the element :type attrs: Dict
3.050517
3.700111
0.824439
try: tag_key = attrs['k'] except KeyError: raise ValueError("Tag without name/key.") self._curr['tags'][tag_key] = attrs.get('v')
def _handle_start_tag(self, attrs)
Handle opening tag element :param attrs: Attributes of the element :type attrs: Dict
7.335098
8.951973
0.819383
self._curr = { 'attributes': dict(attrs), 'lat': None, 'lon': None, 'node_id': None, 'tags': {} } if attrs.get('id', None) is not None: self._curr['node_id'] = int(attrs['id']) del self._curr['attributes...
def _handle_start_node(self, attrs)
Handle opening node element :param attrs: Attributes of the element :type attrs: Dict
1.852912
1.908716
0.970764
self._result.append(Node(result=self._result, **self._curr)) self._curr = {}
def _handle_end_node(self)
Handle closing node element
9.579788
8.916809
1.074352
self._curr = { 'center_lat': None, 'center_lon': None, 'attributes': dict(attrs), 'node_ids': [], 'tags': {}, 'way_id': None } if attrs.get('id', None) is not None: self._curr['way_id'] = int(attrs['id']...
def _handle_start_way(self, attrs)
Handle opening way element :param attrs: Attributes of the element :type attrs: Dict
3.321794
3.267685
1.016559
self._result.append(Way(result=self._result, **self._curr)) self._curr = {}
def _handle_end_way(self)
Handle closing way element
9.976416
7.39932
1.348288
self._curr = { 'attributes': dict(attrs), 'tags': {}, 'area_id': None } if attrs.get('id', None) is not None: self._curr['area_id'] = int(attrs['id']) del self._curr['attributes']['id']
def _handle_start_area(self, attrs)
Handle opening area element :param attrs: Attributes of the element :type attrs: Dict
3.395813
3.668847
0.92558
self._result.append(Area(result=self._result, **self._curr)) self._curr = {}
def _handle_end_area(self)
Handle closing area element
9.437071
8.757668
1.077578
if isinstance(self.cur_relation_member, RelationWay): if self.cur_relation_member.geometry is None: self.cur_relation_member.geometry = [] self.cur_relation_member.geometry.append( RelationWayGeometryValue( lat=Decimal(attrs["l...
def _handle_start_nd(self, attrs)
Handle opening nd element :param attrs: Attributes of the element :type attrs: Dict
4.140232
4.372373
0.946907
self._curr = { 'attributes': dict(attrs), 'members': [], 'rel_id': None, 'tags': {} } if attrs.get('id', None) is not None: self._curr['rel_id'] = int(attrs['id']) del self._curr['attributes']['id']
def _handle_start_relation(self, attrs)
Handle opening relation element :param attrs: Attributes of the element :type attrs: Dict
3.52659
3.644725
0.967587
self._result.append(Relation(result=self._result, **self._curr)) self._curr = {}
def _handle_end_relation(self)
Handle closing relation element
8.991593
7.457947
1.205639
params = { # ToDo: Parse attributes 'attributes': {}, 'ref': None, 'result': self._result, 'role': None } if attrs.get('ref', None): params['ref'] = int(attrs['ref']) if attrs.get('role', None): ...
def _handle_start_member(self, attrs)
Handle opening member element :param attrs: Attributes of the element :type attrs: Dict
3.876762
3.864934
1.00306
if api is None: api = overpy.Overpass() query = data = api.query(query % (areacode, street)) return data
def get_street(street, areacode, api=None)
Retrieve streets in a given bounding area :param overpy.Overpass api: First street of intersection :param String street: Name of street :param String areacode: The OSM id of the bounding area :return: Parsed result :raises overpy.exception.OverPyException: If something bad happens.
5.379318
6.491738
0.828641
if api is None: api = overpy.Overpass() query = data = api.query(query % (areacode, street1, street2)) return data.get_nodes()
def get_intersection(street1, street2, areacode, api=None)
Retrieve intersection of two streets in a given bounding area :param overpy.Overpass api: First street of intersection :param String street1: Name of first street of intersection :param String street2: Name of second street of intersection :param String areacode: The OSM id of the bounding area :re...
4.500415
5.324904
0.845163
def print_tree(current_node, childattr='children', nameattr='name', indent='', last='updown'): if hasattr(current_node, nameattr): name = lambda node: getattr(node, nameattr) else: name = lambda node: str(node) children = lambda node: getattr(node, childattr) nb_children = lamb...
Creation of balanced lists for "up" branch and "down" branch.
null
null
null
if len(platforms) > 0: return all(platform in PLATFORM_IDS for platform in platforms) return True
def check_platforms(platforms)
Checks if the platforms have a valid platform code
5.22761
4.683544
1.116165
if not check_platforms(platforms): raise IncorrectParametersException('Invlaid code for platform. Please check the platform ids') try: if active: active_challenges = active_contests(platforms) if goto: webbrowser.open(active_challenges[goto - 1]["contest_url"], new=2) else: ...
def main(active, upcoming, hiring, short, goto, platforms, time)
A CLI for active and upcoming programming challenges from various platforms
1.933648
1.912681
1.010962
enums = dict( TIME_LEFT="red", CONTEST_NAME="yellow", HOST="green", MISC="blue", TIME_TO_START="green", ) return type('Enum', (), enums)
def colors()
Creates an enum for colors
12.87646
11.531578
1.116626
enums = dict( ACTIVE="active", UPCOMING="upcoming", HIRING="hiring", ALL="all", SHORT="short", ) return type('Enum', (), enums)
def challenge()
Creates an enum for contest type
9.533315
6.899948
1.38165
if contest_type == challenge().ACTIVE: time_diff = time_difference(contest["end"]) elif contest_type == challenge().UPCOMING: time_diff = time_difference(contest["start"]) elif contest_type in [challenge().HIRING, challenge().SHORT, challenge().ALL]: try: time_diff = time_difference(contest[...
def get_time_string(contest, contest_type)
Return a string with time for the contest to begin/end
2.194325
2.207815
0.99389
TimeDiff = namedtuple("TimeDiff", ["days", "hours", "minutes", "seconds"]) time_diff = format_date(target_time) - datetime.utcnow() hours, remainder = divmod(time_diff.seconds, 3600) minutes, seconds = divmod(remainder, 60) return TimeDiff(days=time_diff.days, hours=hours, minutes=minutes, seconds=seconds)
def time_difference(target_time)
Calculate the difference between the current time and the given time
2.162027
2.105503
1.026846
''' Checks whether a value is: - int, or - long, or - float without a fractional part, or - str or unicode composed only of digits ''' def fn(value): if not any([ isinstance(value, numbers.Integral), (isinstance(value, float) and value.is_i...
def IntegerLike(msg=None)
Checks whether a value is: - int, or - long, or - float without a fractional part, or - str or unicode composed only of digits
4.566205
2.727872
1.673907
''' Checks whether a value is: - int, or - long, or - float without a fractional part, or - str or unicode composed only of alphanumeric characters ''' def fn(value): if not any([ isinstance(value, numbers.Integral), (isinstance(value, floa...
def Alphanumeric(msg=None)
Checks whether a value is: - int, or - long, or - float without a fractional part, or - str or unicode composed only of alphanumeric characters
4.695483
2.787464
1.6845
''' Checks whether a value is: - str or unicode, and - composed of both alphabets and digits ''' def fn(value): if not ( isinstance(value, basestring) and value.isalnum() and not value.isdigit() and not value.isalpha() ): ...
def StrictlyAlphanumeric(msg=None)
Checks whether a value is: - str or unicode, and - composed of both alphabets and digits
5.234499
3.149012
1.662267
''' Checks whether a value is : - a valid castable datetime object with timezone. ''' def fn(value): try: date = parse_datetime(value) or parse_date(value) if date is not None: return date else: raise ValueError ...
def DatetimeWithTZ(msg=None)
Checks whether a value is : - a valid castable datetime object with timezone.
6.056317
3.337971
1.814371
''' Checks whether a value is list of integers. Returns list of integers or just one integer in list if there is only one element in given CSV string. ''' def fn(value): try: if isinstance(value, basestring): if ',' in value: value = list(m...
def CSVofIntegers(msg=None)
Checks whether a value is list of integers. Returns list of integers or just one integer in list if there is only one element in given CSV string.
4.216976
2.564914
1.6441
query_params = self.request.query_params url_params = self.kwargs # get queryset_filters from FilterMixin queryset_filters = self.get_db_filters(url_params, query_params) # This dict will hold filter kwargs to pass in to Django ORM calls. db_filters = queryset...
def get_queryset(self)
Optionally restricts the queryset by filtering against query parameters in the URL.
4.029297
3.707735
1.086727
parent_name = "CMSPLUGIN_NEWS_{0}".format(name) return getattr(django_settings, parent_name, default)
def get_setting(name, default)
A little helper for fetching global settings with a common prefix.
8.092972
7.248284
1.116536
rows_updated = queryset.update(is_published=True) self.message_user(request, ungettext('%(count)d newsitem was published', '%(count)d newsitems were published', rows_updated) % {'count': rows_updat...
def make_published(self, request, queryset)
Marks selected news items as published
2.486456
2.497666
0.995512
rows_updated = queryset.update(is_published=False) self.message_user(request, ungettext('%(count)d newsitem was unpublished', '%(count)d newsitems were unpublished', rows_updated) % {'count': rows_...
def make_unpublished(self, request, queryset)
Marks selected news items as unpublished
2.447137
2.422255
1.010272
if value is None: value = '' value = smart_unicode(value) final_attrs = self.build_attrs(attrs) final_attrs['name'] = name assert 'id' in final_attrs, \ "TinyMCE widget attributes must contain 'id'" mce_config = cms.plugins.text.settings.TINYMCE_CO...
def render(self, name, value, attrs=None)
plugins = mce_config.get("plugins", "") if len(plugins): plugins += "," plugins += "-cmsplugins" mce_config['plugins'] = plugins adv2 = mce_config.get('theme_advanced_buttons1', "") if len(adv2): adv2 = "," + adv2 adv2 = "cmsplugins,cmspluginsedit"...
3.212549
3.282926
0.978563
wk_args = (WK_PATH,) + args return subprocess.run(wk_args, input=input, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def _execute_wk(*args, input=None)
Generate path for the wkhtmltopdf binary and execute command. :param args: args to pass straight to subprocess.Popen :return: stdout, stderr
3.360648
4.649816
0.722749
if not cache_dir.exists(): Path.mkdir(cache_dir) py_args = dict( cache_dir=cache_dir, grayscale=grayscale, lowquality=lowquality, margin_bottom=margin_bottom, margin_left=margin_left, margin_right=margin_right, margin_top=margin_top, ...
def generate_pdf(html, *, cache_dir: Path=DFT_CACHE_DIR, grayscale: bool=False, lowquality: bool=False, margin_bottom: str=None, margin_left: str=None, margin_right: str=None, margin_top: str=None, ...
Generate a pdf from either a url or a html string. After the html and url arguments all other arguments are passed straight to wkhtmltopdf For details on extra arguments see the output of get_help() and get_extended_help() All arguments whether specified or caught with extra_kwargs are converted ...
2.835771
2.837434
0.999414
try: wk_version = _string_execute('-V') except Exception as e: # we catch all errors here to make sure we get a version no matter what wk_version = '%s: %s' % (e.__class__.__name__, e) return 'pydf version: %s\nwkhtmltopdf version: %s' % (VERSION, wk_version)
def get_version()
Get version of pydf and wkhtmltopdf binary :return: version string
5.915164
4.718647
1.253572
'''Perform sctring escape - for regexp literals''' self.index = 0 self.length = len(string) self.source = string self.lineNumber = 0 self.lineStart = 0 octal = False st = '' inside_square = 0 while (self.index < self.length): te...
def _interpret_regexp(self, string, flags)
Perform sctring escape - for regexp literals
2.110542
2.022409
1.043578
''' Search Crossref licenses :param query: [String] A query string :param offset: [Fixnum] Number of record to start at, from 1 to 10000 :param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000 :param sort...
def licenses(self, query = None, offset = None, limit = None, sample = None, sort = None, order = None, facet = None, **kwargs)
Search Crossref licenses :param query: [String] A query string :param offset: [Fixnum] Number of record to start at, from 1 to 10000 :param limit: [Fixnum] Number of results to return. Not relevant when searching with specific dois. Default: 20. Max: 1000 :param sort: [String] Field to ...
6.364017
1.551612
4.101551
''' Determine registration agency for DOIs :param ids: [Array] DOIs (digital object identifier) or other identifiers :param kwargs: additional named arguments passed on to `requests.get`, e.g., field queries (see examples) :return: list of DOI minting agencies ...
def registration_agency(self, ids, **kwargs)
Determine registration agency for DOIs :param ids: [Array] DOIs (digital object identifier) or other identifiers :param kwargs: additional named arguments passed on to `requests.get`, e.g., field queries (see examples) :return: list of DOI minting agencies Usage:: ...
6.548873
2.238151
2.926019
''' Get a random set of DOIs :param sample: [Fixnum] Number of random DOIs to return. Default: 10. Max: 100 :param kwargs: additional named arguments passed on to `requests.get`, e.g., field queries (see examples) :return: [Array] of DOIs Usage:: ...
def random_dois(self, sample = 10, **kwargs)
Get a random set of DOIs :param sample: [Fixnum] Number of random DOIs to return. Default: 10. Max: 100 :param kwargs: additional named arguments passed on to `requests.get`, e.g., field queries (see examples) :return: [Array] of DOIs Usage:: from habanero imp...
4.3941
1.915763
2.293655
''' Get list of styles from https://github.com/citation-style-language/styles :param kwargs: any additional arguments will be passed on to `requests.get` :return: list, of CSL styles Usage:: from habanero import cn cn.csl_styles() ''' base = "https://api.github.com/repos/citation-style-lan...
def csl_styles(**kwargs)
Get list of styles from https://github.com/citation-style-language/styles :param kwargs: any additional arguments will be passed on to `requests.get` :return: list, of CSL styles Usage:: from habanero import cn cn.csl_styles()
3.455679
2.370501
1.457784
''' Get a citation count with a DOI :param doi: [String] DOI, digital object identifier :param url: [String] the API url for the function (should be left to default) :param keyc: [String] your API key See http://labs.crossref.org/openurl/ for more info on this Crossref API service. Usage:...
def citation_count(doi, url = "http://www.crossref.org/openurl/", key = "cboettig@ropensci.org", **kwargs)
Get a citation count with a DOI :param doi: [String] DOI, digital object identifier :param url: [String] the API url for the function (should be left to default) :param keyc: [String] your API key See http://labs.crossref.org/openurl/ for more info on this Crossref API service. Usage:: f...
4.348143
1.797403
2.419125
hierarchy = [] defaults = TOC.default_hierarchy + tuple( '%ssection' % ('sub'*i) for i in range(2, max_subs)) for level in defaults: if getattr(self.source, level, False): hierarchy.append(level) return tuple(hierarchy)
def findHierarchy(self, max_subs=10)
Find hierarchy for the LaTeX source. >>> TOC.fromLatex(r'\subsection{yo}\section{hello}').findHierarchy() ('section', 'subsection') >>> TOC.fromLatex( ... r'\subsubsubsection{huh}\subsubsection{hah}').findHierarchy() ('subsubsection', 'subsubsubsection') >>> TOC.fromLate...
7.704581
6.508502
1.183772
try: return hierarchy.index(ts.name)+1 except ValueError: if ts.name.endswith('section'): i, name = 0, ts.name while name.startswith('sub'): name, i = name[3:], i+1 if name == 'section': ...
def getHeadingLevel(ts, hierarchy=default_hierarchy)
Extract heading level for a particular Tex element, given a specified hierarchy. >>> ts = TexSoup(r'\section{Hello}').section >>> TOC.getHeadingLevel(ts) 2 >>> ts2 = TexSoup(r'\chapter{hello again}').chapter >>> TOC.getHeadingLevel(ts2) 1 >>> ts3 = TexSou...
3.743455
4.007822
0.934037
descendants = list(descendants) or \ list(getattr(self.source, 'descendants', descendants)) if not descendants: return -1 return min(TOC.getHeadingLevel(e, self.hierarchy) for e in descendants)
def parseTopDepth(self, descendants=())
Parse tex for highest tag in hierarchy >>> TOC.fromLatex('\\section{Hah}\\subsection{No}').parseTopDepth() 1 >>> s = '\\subsubsubsection{Yo}\\subsubsection{Hah}' >>> TOC.fromLatex(s).parseTopDepth() 1 >>> h = ('section', 'subsubsection', 'subsubsubsection') >>> T...
8.159696
7.652165
1.066325
i, branches = self.parseTopDepth(descendants), [] for descendant in descendants: if self.getHeadingLevel(descendant, self.hierarchy) == i: branches.append({'source': descendant}) if self.getHeadingLevel(descendant, self.hierarchy) > i \ an...
def parseBranches(self, descendants)
Parse top level of latex :param list elements: list of source objects :return: list of filtered TreeOfContents objects >>> toc = TOC.fromLatex(r'\section{h1}\subsection{subh1}\section{h2}\ ... \subsection{subh2}') >>> toc.parseTopDepth(toc.descendants) 1 >>> toc....
5.443511
4.694856
1.159463
return TOC.fromLatex(open(path_or_buffer).read() if isinstance(path_or_buffer, str) else path_or_buffer)
def fromFile(path_or_buffer)
Creates abstraction using path to file :param str path_or_buffer: path to tex file or buffer :return: TreeOfContents object
4.879929
5.765104
0.84646
source = TexSoup(tex) return TOC('[document]', source=source, descendants=list(source.descendants), *args, **kwargs)
def fromLatex(tex, *args, **kwargs)
Creates abstraction using Latex :param str tex: Latex :return: TreeOfContents object
15.433957
15.249139
1.01212