message_user(user, message, constants.DEBUG)<EOL>

Adds a message with the ``DEBUG`` level.

:param user: User instance
:param message: Message to show


message_user(user, message, constants.INFO)<EOL>

Adds a message with the ``INFO`` level.

:param user: User instance
:param message: Message to show


message_user(user, message, constants.SUCCESS)<EOL>

Adds a message with the ``SUCCESS`` level.

:param user: User instance
:param message: Message to show


message_user(user, message, constants.WARNING)<EOL>

Adds a message with the ``WARNING`` level.

:param user: User instance
:param message: Message to show


message_user(user, message, constants.ERROR)<EOL>

Adds a message with the ``ERROR`` level.

:param user: User instance
:param message: Message to show


def process_response(self, request, response):

if hasattr(request, "<STR_LIT>") and hasattr(request, "<STR_LIT:user>") and request.user.is_authenticated():<EOL><INDENT>msgs = get_messages(request.user)<EOL>if msgs:<EOL><INDENT>for msg, level in msgs:<EOL><INDENT>messages.add_message(request, level, msg)<EOL><DEDENT><DEDENT><DEDENT>return response<EOL>

Check for messages for this user and, if it exists,
call the messages API with it


def message_user(user, message, level=constants.INFO):

<EOL>user_key = _user_key(user)<EOL>messages = cache.get(user_key) or []<EOL>messages.append((message, level))<EOL>cache.set(user_key, messages)<EOL>

Send a message to a particular user.

:param user: User instance
:param message: Message to show
:param level: Message level


def message_users(users, message, level=constants.INFO):

for user in users:<EOL><INDENT>message_user(user, message, level)<EOL><DEDENT>

Send a message to a group of users.

:param users: Users queryset
:param message: Message to show
:param level: Message level


key = _user_key(user)<EOL>result = cache.get(key)<EOL>if result:<EOL><INDENT>cache.delete(key)<EOL>return result<EOL><DEDENT>return None<EOL>

Fetch messages for given user.  Returns None if no such message exists.

:param user: User instance


auth = auth or []<EOL>dynamodb = boto.connect_dynamodb(*auth)<EOL>table = dynamodb.get_table(name)<EOL>return Table(table=table, eager=eager)<EOL>

Returns a given table for the given user.


auth = auth or []<EOL>dynamodb = boto.connect_dynamodb(*auth)<EOL>return [table(t, auth, eager=eager) for t in dynamodb.list_tables()]<EOL>

Returns a list of tables for the given user.


@api_request(methods=['<STR_LIT:GET>', '<STR_LIT:POST>'])<EOL>def status(request, data):

return dict()<EOL>

A status view for querying the API availability with given token.
Can be used e.g. by monitoring systems to poll the service. Note
that the @api_request has hit the database to look up the token,
so this view will monitor database availability as well.


def decorator(view_func):<EOL><INDENT>@wraps(view_func, assigned=available_attrs(view_func))<EOL>def _wrapped_view(request, *args, **kwargs):<EOL><INDENT>ApiToken = apps.get_model('<STR_LIT>', '<STR_LIT>')<EOL>m = methods if methods is not None else DEFAULT_API_METHODS<EOL>if request.method not in m:<EOL><INDENT>response = ApiResponse(False, '<STR_LIT>', status=<NUM_LIT>)<EOL>response['<STR_LIT>'] = '<STR_LIT:U+002CU+0020>'.join(methods)<EOL>return response<EOL><DEDENT>try:<EOL><INDENT>data = json.loads(request.body.decode('<STR_LIT:utf-8>')) if request.body else {}<EOL>if require_token:<EOL><INDENT>token_string = request.GET['<STR_LIT>'] if request.method == '<STR_LIT:GET>' else data['<STR_LIT>']<EOL>try:<EOL><INDENT>token = ApiToken.objects.get(token=token_string)<EOL>token.save()  <EOL>data['<STR_LIT>'] = token<EOL><DEDENT>except ApiToken.DoesNotExist:<EOL><INDENT>logger.exception('<STR_LIT>'.format(token_string))<EOL>return ApiResponse(False, '<STR_LIT>', status=<NUM_LIT>)<EOL><DEDENT><DEDENT>return ApiResponse(data=view_func(request, data=data, *args, **kwargs))<EOL><DEDENT>except Exception as e:<EOL><INDENT>if e.__class__.__name__ == '<STR_LIT>':<EOL><INDENT>logger.exception('<STR_LIT>')<EOL>return ApiResponse(False, '<STR_LIT>'.format(e), status=<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>logger.exception('<STR_LIT>')<EOL>return ApiResponse(False, '<STR_LIT>'.format(e), status=<NUM_LIT>)<EOL><DEDENT><DEDENT><DEDENT>return _wrapped_view<EOL><DEDENT>return decorator<EOL>

View decorator that handles JSON based API requests and responses consistently.
:param methods: A list of allowed methods
:param require_token: Whether API token is checked automatically or not


list_display = []<EOL>for field_name in self.list_display:<EOL><INDENT>try:<EOL><INDENT>db_field = self.model._meta.get_field(field_name)<EOL>if isinstance(db_field, BooleanField):<EOL><INDENT>field_name = boolean_switch_field(db_field)<EOL><DEDENT><DEDENT>except FieldDoesNotExist:<EOL><INDENT>pass<EOL><DEDENT>list_display.append(field_name)<EOL><DEDENT>return list_display<EOL>

Return a sequence containing the fields to be displayed on the
changelist.


app_label, model_name, object_id, field = url.split('<STR_LIT:/>')<EOL>try:<EOL><INDENT>from django.apps import apps<EOL>model = apps.get_model(app_label, model_name)<EOL><DEDENT>except ImportError:<EOL><INDENT>from django.db.models import get_model<EOL>model = get_model(app_label, model_name)<EOL><DEDENT>object = get_object_or_404(model, pk=object_id)<EOL>perm_str = '<STR_LIT>' % (app_label, model.__name__)<EOL>if not request.user.has_perm(perm_str.lower()):<EOL><INDENT>raise PermissionDenied<EOL><DEDENT>setattr(object, field, getattr(object, field) == <NUM_LIT:0>)<EOL>object.save()<EOL>if request.is_ajax():<EOL><INDENT>return JsonResponse({'<STR_LIT>': object.pk, '<STR_LIT>': field, '<STR_LIT:value>': getattr(object, field)})<EOL><DEDENT>else:<EOL><INDENT>msg = _(u'<STR_LIT>') % {'<STR_LIT>': field, '<STR_LIT:object>': object}<EOL>messages.success(request, msg)<EOL>return HttpResponseRedirect(request.META.get('<STR_LIT>', '<STR_LIT:/>'))<EOL><DEDENT>

Set/clear boolean field value for model object


url = f'<STR_LIT>'<EOL>headers = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': f'<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT:yes>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}<EOL>def gen_tweets(pages):<EOL><INDENT>r = session.get(url, headers=headers)<EOL>while pages > <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>html = HTML(html=r.json()['<STR_LIT>'],<EOL>url='<STR_LIT>', default_encoding='<STR_LIT:utf-8>')<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError(<EOL>f'<STR_LIT>')<EOL><DEDENT>comma = "<STR_LIT:U+002C>"<EOL>dot = "<STR_LIT:.>"<EOL>tweets = []<EOL>for tweet in html.find('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>text = tweet.find('<STR_LIT>')[<NUM_LIT:0>].full_text<EOL><DEDENT>except IndexError:  <EOL><INDENT>continue<EOL><DEDENT>tweet_id = tweet.find('<STR_LIT>')[<NUM_LIT:0>].attrs['<STR_LIT>']<EOL>time = datetime.fromtimestamp(int(tweet.find('<STR_LIT>')[<NUM_LIT:0>].attrs['<STR_LIT>']) / <NUM_LIT>)<EOL>interactions = [<EOL>x.text<EOL>for x in tweet.find('<STR_LIT>')<EOL>]<EOL>replies = int(<EOL>interactions[<NUM_LIT:0>].split('<STR_LIT:U+0020>')[<NUM_LIT:0>].replace(comma, '<STR_LIT>').replace(dot, '<STR_LIT>')<EOL>or interactions[<NUM_LIT:3>]<EOL>)<EOL>retweets = int(<EOL>interactions[<NUM_LIT:1>].split('<STR_LIT:U+0020>')[<NUM_LIT:0>].replace(comma, '<STR_LIT>').replace(dot, '<STR_LIT>')<EOL>or interactions[<NUM_LIT:4>]<EOL>or interactions[<NUM_LIT:5>]<EOL>)<EOL>likes = int(<EOL>interactions[<NUM_LIT:2>].split('<STR_LIT:U+0020>')[<NUM_LIT:0>].replace(comma, '<STR_LIT>').replace(dot, '<STR_LIT>')<EOL>or interactions[<NUM_LIT:6>]<EOL>or interactions[<NUM_LIT:7>]<EOL>)<EOL>hashtags = [<EOL>hashtag_node.full_text<EOL>for hashtag_node in tweet.find('<STR_LIT>')<EOL>]<EOL>urls = [<EOL>url_node.attrs['<STR_LIT>']<EOL>for url_node in tweet.find('<STR_LIT>')<EOL>]<EOL>photos = [<EOL>photo_node.attrs['<STR_LIT>']<EOL>for photo_node in tweet.find('<STR_LIT>')<EOL>]<EOL>videos = []<EOL>video_nodes = tweet.find("<STR_LIT>")<EOL>for node in video_nodes:<EOL><INDENT>styles = node.attrs['<STR_LIT>'].split()<EOL>for style in styles:<EOL><INDENT>if style.startswith('<STR_LIT>'):<EOL><INDENT>tmp = style.split('<STR_LIT:/>')[-<NUM_LIT:1>]<EOL>video_id = tmp[:tmp.index('<STR_LIT>')]<EOL>videos.append({'<STR_LIT:id>': video_id})<EOL><DEDENT><DEDENT><DEDENT>tweets.append({<EOL>'<STR_LIT>': tweet_id,<EOL>'<STR_LIT:time>': time,<EOL>'<STR_LIT:text>': text,<EOL>'<STR_LIT>': replies,<EOL>'<STR_LIT>': retweets,<EOL>'<STR_LIT>': likes,<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': hashtags, '<STR_LIT>': urls,<EOL>'<STR_LIT>': photos, '<STR_LIT>': videos<EOL>}<EOL>})<EOL><DEDENT>last_tweet = html.find('<STR_LIT>')[-<NUM_LIT:1>].attrs['<STR_LIT>']<EOL>for tweet in tweets:<EOL><INDENT>if tweet:<EOL><INDENT>tweet['<STR_LIT:text>'] = re.sub('<STR_LIT:http>', '<STR_LIT>', tweet['<STR_LIT:text>'], <NUM_LIT:1>)<EOL>yield tweet<EOL><DEDENT><DEDENT>r = session.get(url, params={'<STR_LIT>': last_tweet}, headers=headers)<EOL>pages += -<NUM_LIT:1><EOL><DEDENT><DEDENT>yield from gen_tweets(pages)<EOL>

Gets tweets for a given user, via the Twitter frontend API.


for config, distro in iter_files_distros(path=path):<EOL><INDENT>if (group in config) and (name in config[group]):<EOL><INDENT>epstr = config[group][name]<EOL>with BadEntryPoint.err_to_warnings():<EOL><INDENT>return EntryPoint.from_string(epstr, name, distro)<EOL><DEDENT><DEDENT><DEDENT>raise NoSuchEntryPoint(group, name)<EOL>

Find a single entry point.

    Returns an :class:`EntryPoint` object, or raises :exc:`NoSuchEntryPoint`
    if no match is found.


result = {}<EOL>for ep in get_group_all(group, path=path):<EOL><INDENT>if ep.name not in result:<EOL><INDENT>result[ep.name] = ep<EOL><DEDENT><DEDENT>return result<EOL>

Find a group of entry points with unique names.

    Returns a dictionary of names to :class:`EntryPoint` objects.


result = []<EOL>for config, distro in iter_files_distros(path=path):<EOL><INDENT>if group in config:<EOL><INDENT>for name, epstr in config[group].items():<EOL><INDENT>with BadEntryPoint.err_to_warnings():<EOL><INDENT>result.append(EntryPoint.from_string(epstr, name, distro))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return result<EOL>

Find all entry points in a group.

    Returns a list of :class:`EntryPoint` objects.


mod = import_module(self.module_name)<EOL>obj = mod<EOL>if self.object_name:<EOL><INDENT>for attr in self.object_name.split('<STR_LIT:.>'):<EOL><INDENT>obj = getattr(obj, attr)<EOL><DEDENT><DEDENT>return obj<EOL>

Load the object to which this entry point refers.


@classmethod<EOL><INDENT>def from_string(cls, epstr, name, distro=None):<DEDENT>

m = entry_point_pattern.match(epstr)<EOL>if m:<EOL><INDENT>mod, obj, extras = m.group('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>if extras is not None:<EOL><INDENT>extras = re.split(r'<STR_LIT>', extras)<EOL><DEDENT>return cls(name, mod, obj, extras, distro)<EOL><DEDENT>else:<EOL><INDENT>raise BadEntryPoint(epstr)<EOL><DEDENT>

Parse an entry point from the syntax in entry_points.txt

        :param str epstr: The entry point string (not including 'name =')
        :param str name: The name of this entry point
        :param Distribution distro: The distribution in which the entry point was found
        :rtype: EntryPoint
        :raises BadEntryPoint: if *epstr* can't be parsed as an entry point.


filename = pathlib.Path(filename)<EOL>if not isinstance(data, np.ndarray):<EOL><INDENT>data = np.array(data, dtype=float)<EOL><DEDENT>nanrows = np.isnan(data).any(axis=<NUM_LIT:1>)<EOL>if np.sum(nanrows):<EOL><INDENT>msg = "<STR_LIT>".format(filename)<EOL>warnings.warn(msg)<EOL>data = data[~nanrows]<EOL><DEDENT>if endianness not in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>msg = "<STR_LIT>"<EOL>assert len(chn_names) == data.shape[<NUM_LIT:1>], msg<EOL>rpl = [["<STR_LIT>", "<STR_LIT:u>"],<EOL>["<STR_LIT>", "<STR_LIT:2>"],<EOL>]<EOL>if compat_chn_names:<EOL><INDENT>rpl += [["<STR_LIT:U+0020>", "<STR_LIT>"],<EOL>["<STR_LIT:?>", "<STR_LIT>"],<EOL>["<STR_LIT:_>", "<STR_LIT>"],<EOL>]<EOL><DEDENT>for ii in range(len(chn_names)):<EOL><INDENT>for (a, b) in rpl:<EOL><INDENT>chn_names[ii] = chn_names[ii].replace(a, b)<EOL><DEDENT><DEDENT>pcnt_cands = []<EOL>for ch in range(data.shape[<NUM_LIT:1>]):<EOL><INDENT>if data[:, ch].min() >= <NUM_LIT:0> and data[:, ch].max() <= <NUM_LIT:1>:<EOL><INDENT>pcnt_cands.append(ch)<EOL><DEDENT><DEDENT>if compat_percent and pcnt_cands:<EOL><INDENT>if compat_copy:<EOL><INDENT>data = data.copy()<EOL><DEDENT>for ch in pcnt_cands:<EOL><INDENT>data[:, ch] *= <NUM_LIT:100><EOL><DEDENT><DEDENT>if compat_negative:<EOL><INDENT>toflip = []<EOL>for ch in range(data.shape[<NUM_LIT:1>]):<EOL><INDENT>if np.mean(data[:, ch]) < <NUM_LIT:0>:<EOL><INDENT>toflip.append(ch)<EOL><DEDENT><DEDENT>if len(toflip):<EOL><INDENT>if compat_copy:<EOL><INDENT>data = data.copy()<EOL><DEDENT>for ch in toflip:<EOL><INDENT>data[:, ch] *= -<NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>data1 = data.flatten().tolist()<EOL>DATA = struct.pack('<STR_LIT>' % len(data1), *data1)<EOL>header_size = <NUM_LIT><EOL>if endianness == "<STR_LIT>":<EOL><INDENT>byteord = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>byteord = '<STR_LIT>'<EOL><DEDENT>TEXT = '<STR_LIT>'<EOL>TEXT += '<STR_LIT>'<EOL>TEXT += '<STR_LIT>'<EOL>TEXT += '<STR_LIT>'.format(byteord)<EOL>TEXT += '<STR_LIT>'.format(data.shape[<NUM_LIT:0>])<EOL>TEXT += '<STR_LIT>'.format(data.shape[<NUM_LIT:1>])<EOL>for jj in range(data.shape[<NUM_LIT:1>]):<EOL><INDENT>if (compat_max_int16 and<EOL>np.max(data[:, jj]) > compat_max_int16 and<EOL>np.max(data[:, jj]) < <NUM_LIT:2>**<NUM_LIT:15>):<EOL><INDENT>pnrange = int(<NUM_LIT:2>**<NUM_LIT:15>)<EOL><DEDENT>elif jj in pcnt_cands:<EOL><INDENT>if compat_percent:  <EOL><INDENT>pnrange = <NUM_LIT:100><EOL><DEDENT>else:  <EOL><INDENT>pnrange = <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>pnrange = int(abs(np.max(data[:, jj])))<EOL><DEDENT>fmt_str = '<STR_LIT>'<EOL>TEXT += fmt_str.format(jj+<NUM_LIT:1>, chn_names[jj], pnrange)<EOL><DEDENT>TEXT += '<STR_LIT:/>'<EOL>text_padding = <NUM_LIT>  <EOL>data_start_byte = header_size + len(TEXT) + text_padding<EOL>data_end_byte = data_start_byte + len(DATA) - <NUM_LIT:1><EOL>TEXT = TEXT.format(data_start_byte=data_start_byte,<EOL>data_end_byte=data_end_byte)<EOL>lentxt = len(TEXT)<EOL>TEXT = TEXT.ljust(data_start_byte - header_size, "<STR_LIT:U+0020>")<EOL>ver = '<STR_LIT>'<EOL>textfirst = '<STR_LIT>'.format(header_size)<EOL>textlast = '<STR_LIT>'.format(lentxt + header_size - <NUM_LIT:1>)<EOL>if data_end_byte <= <NUM_LIT>:<EOL><INDENT>datafirst = '<STR_LIT>'.format(data_start_byte)<EOL>datalast = '<STR_LIT>'.format(data_end_byte)<EOL><DEDENT>else:<EOL><INDENT>datafirst = '<STR_LIT>'.format(<NUM_LIT:0>)<EOL>datalast = '<STR_LIT>'.format(<NUM_LIT:0>)<EOL><DEDENT>anafirst = '<STR_LIT>'.format(<NUM_LIT:0>)<EOL>analast = '<STR_LIT>'.format(<NUM_LIT:0>)<EOL>HEADER = '<STR_LIT>'.format(ver + '<STR_LIT:U+0020>'<EOL>+ textfirst<EOL>+ textlast<EOL>+ datafirst<EOL>+ datalast<EOL>+ anafirst<EOL>+ analast)<EOL>with filename.open("<STR_LIT:wb>") as fd:<EOL><INDENT>fd.write(HEADER.encode("<STR_LIT:ascii>", "<STR_LIT:replace>"))<EOL>fd.write(TEXT.encode("<STR_LIT:ascii>", "<STR_LIT:replace>"))<EOL>fd.write(DATA)<EOL>fd.write(b'<STR_LIT>')<EOL><DEDENT>

Write numpy data to an .fcs file (FCS3.0 file format)

    Parameters
    ----------
    filename: str or pathlib.Path
        Path to the output .fcs file
    ch_names: list of str, length C
        Names of the output channels
    data: 2d ndarray of shape (N,C)
        The numpy array data to store as .fcs file format.
    endianness: str
        Set to "little" or "big" to define the byte order used.
    compat_chn_names: bool
        Compatibility mode for 3rd party flow analysis software:
        The characters " ", "?", and "_" are removed in the output
        channel names.
    compat_copy: bool
        Do not override the input array `data` when modified in
        compatibility mode.
    compat_negative: bool
        Compatibliity mode for 3rd party flow analysis software:
        Flip the sign of `data` if its mean is smaller than zero.
    compat_percent: bool
        Compatibliity mode for 3rd party flow analysis software:
        If a column in `data` contains values only between 0 and 1,
        they are multiplied by 100.
    compat_max_int16: int
        Compatibliity mode for 3rd party flow analysis software:
        If a column in `data` has a maximum above this value,
        then the display-maximum is set to 2**15.

    Notes
    -----

    - These commonly used unicode characters are replaced: "µ", "²"
    - If the input data contain NaN values, the corresponding rows
      are excluded due to incompatibility with the FCS file format.


tdms_file = nptdms.TdmsFile(tdms_file)<EOL>ch_names = []<EOL>ch_data = []<EOL>for o in tdms_file.objects.values():<EOL><INDENT>if o.data is not None and len(o.data):<EOL><INDENT>chn = o.path.split('<STR_LIT:/>')[-<NUM_LIT:1>].strip("<STR_LIT:'>")<EOL>if "<STR_LIT>" in o.properties:<EOL><INDENT>unit = o.properties["<STR_LIT>"]<EOL>ch_names.append("<STR_LIT>".format(chn, unit))<EOL><DEDENT>else:<EOL><INDENT>ch_names.append(chn)<EOL><DEDENT>ch_data.append(o.data)<EOL><DEDENT><DEDENT>return ch_names, ch_data<EOL>

Read tdms file and return channel names and data


if "<STR_LIT>" not in chn_names:<EOL><INDENT>for ii, ch in enumerate(chn_names):<EOL><INDENT>if ch == "<STR_LIT>":<EOL><INDENT>chn_names.append("<STR_LIT>")<EOL>data.append(<NUM_LIT:1>-data[ii])<EOL><DEDENT><DEDENT><DEDENT>return chn_names, data<EOL>

From circularity, compute the deformation

    This method is useful for RT-DC data sets that contain
    the circularity but not the deformation.


fcs_file = tdms_file[:-<NUM_LIT:4>]+"<STR_LIT>"<EOL>chn_names, data = read_tdms(tdms_file)<EOL>chn_names, data = add_deformation(chn_names, data)<EOL>fcswrite.write_fcs(filename=fcs_file,<EOL>chn_names=chn_names,<EOL>data=np.array(data).transpose())<EOL>

Creates an fcs file for a given tdms file


<EOL>assert threshold > <NUM_LIT:0><EOL>df.createOrReplaceTempView("<STR_LIT>".format(**self.header))<EOL>if timedecay_formula:<EOL><INDENT>query = self.f(<EOL>"""<STR_LIT>""",<EOL>time_now=time_now,<EOL>time_decay_coefficient=time_decay_coefficient,<EOL>)<EOL>df = self.spark.sql(query)<EOL><DEDENT>else:<EOL><INDENT>if self.header['<STR_LIT>'].lower() in [s.name.lower() for s in df.schema]:<EOL><INDENT>query = self.f(<EOL>"""<STR_LIT>"""<EOL>)<EOL>df = self.spark.sql(query)<EOL><DEDENT><DEDENT>df.createOrReplaceTempView(self.f("<STR_LIT>"))<EOL>log.info("<STR_LIT>")<EOL>query = self.f(<EOL>"""<STR_LIT>""",<EOL>threshold=threshold,<EOL>)<EOL>item_cooccurrence = self.spark.sql(query)<EOL>item_cooccurrence.write.mode("<STR_LIT>").saveAsTable(<EOL>self.f("<STR_LIT>")<EOL>)<EOL>if similarity_type == SIM_LIFT or similarity_type == SIM_JACCARD:<EOL><INDENT>item_marginal = self.spark.sql(<EOL>self.f(<EOL>"<STR_LIT>"<EOL>)<EOL>)<EOL>item_marginal.createOrReplaceTempView(self.f("<STR_LIT>"))<EOL><DEDENT>if similarity_type == SIM_COOCCUR:<EOL><INDENT>self.item_similarity = item_cooccurrence<EOL><DEDENT>elif similarity_type == SIM_JACCARD:<EOL><INDENT>query = self.f(<EOL>"""<STR_LIT>"""<EOL>)<EOL>self.item_similarity = self.spark.sql(query)<EOL><DEDENT>elif similarity_type == SIM_LIFT:<EOL><INDENT>query = self.f(<EOL>"""<STR_LIT>"""<EOL>)<EOL>self.item_similarity = self.spark.sql(query)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>".format(similarity_type))<EOL><DEDENT>log.info("<STR_LIT>" % similarity_type)<EOL>self.item_similarity.write.mode("<STR_LIT>").saveAsTable(<EOL>self.f("<STR_LIT>")<EOL>)<EOL>query = self.f(<EOL>"""<STR_LIT>"""<EOL>)<EOL>self.item_similarity = self.spark.sql(query)<EOL>self.item_similarity.write.mode("<STR_LIT>").saveAsTable(<EOL>self.f("<STR_LIT>")<EOL>)<EOL>self.spark.sql(self.f("<STR_LIT>"))<EOL>self.spark.sql(self.f("<STR_LIT>"))<EOL>self.item_similarity = self.spark.table(self.f("<STR_LIT>"))<EOL>

Main fit method for SAR. Expects the dataframes to have row_id, col_id columns which are indexes,
        i.e. contain the sequential integer index of the original alphanumeric user and item IDs.
        Dataframe also contains rating and timestamp as floats; timestamp is in seconds since Epoch by default.

        Arguments:
            df (pySpark.DataFrame): input dataframe which contains the index of users and items.


def loads(s, strip_comments=False, **kw):

kw['<STR_LIT>'] = strip_comments<EOL>return [parse_node(ss.strip(), **kw) for ss in s.split('<STR_LIT:;>') if ss.strip()]<EOL>

Load a list of trees from a Newick formatted string.

:param s: Newick formatted string.
:param strip_comments: Flag signaling whether to strip comments enclosed in square \
brackets.
:param kw: Keyword arguments are passed through to `Node.create`.
:return: List of Node objects.


if isinstance(trees, Node):<EOL><INDENT>trees = [trees]<EOL><DEDENT>return '<STR_LIT>'.join([tree.newick for tree in trees]) + '<STR_LIT:;>'<EOL>

Serialize a list of trees in Newick format.

:param trees: List of Node objects or a single Node object.
:return: Newick formatted string.


def load(fp, strip_comments=False, **kw):

kw['<STR_LIT>'] = strip_comments<EOL>return loads(fp.read(), **kw)<EOL>

Load a list of trees from an open Newick formatted file.

:param fp: open file handle.
:param strip_comments: Flag signaling whether to strip comments enclosed in square \
brackets.
:param kw: Keyword arguments are passed through to `Node.create`.
:return: List of Node objects.


def read(fname, encoding='<STR_LIT:utf8>', strip_comments=False, **kw):

kw['<STR_LIT>'] = strip_comments<EOL>with io.open(fname, encoding=encoding) as fp:<EOL><INDENT>return load(fp, **kw)<EOL><DEDENT>

Load a list of trees from a Newick formatted file.

:param fname: file path.
:param strip_comments: Flag signaling whether to strip comments enclosed in square \
brackets.
:param kw: Keyword arguments are passed through to `Node.create`.
:return: List of Node objects.


bracket_level = <NUM_LIT:0><EOL>current = []<EOL>for c in (s + "<STR_LIT:U+002C>"):<EOL><INDENT>if c == "<STR_LIT:U+002C>" and bracket_level == <NUM_LIT:0>:<EOL><INDENT>yield parse_node("<STR_LIT>".join(current), **kw)<EOL>current = []<EOL><DEDENT>else:<EOL><INDENT>if c == "<STR_LIT:(>":<EOL><INDENT>bracket_level += <NUM_LIT:1><EOL><DEDENT>elif c == "<STR_LIT:)>":<EOL><INDENT>bracket_level -= <NUM_LIT:1><EOL><DEDENT>current.append(c)<EOL><DEDENT><DEDENT>


def parse_node(s, strip_comments=False, **kw):

if strip_comments:<EOL><INDENT>s = COMMENT.sub('<STR_LIT>', s)<EOL><DEDENT>s = s.strip()<EOL>parts = s.split('<STR_LIT:)>')<EOL>if len(parts) == <NUM_LIT:1>:<EOL><INDENT>descendants, label = [], s<EOL><DEDENT>else:<EOL><INDENT>if not parts[<NUM_LIT:0>].startswith('<STR_LIT:(>'):<EOL><INDENT>raise ValueError('<STR_LIT>' % parts[<NUM_LIT:0>][:<NUM_LIT:100>])<EOL><DEDENT>descendants = list(_parse_siblings('<STR_LIT:)>'.join(parts[:-<NUM_LIT:1>])[<NUM_LIT:1>:], **kw))<EOL>label = parts[-<NUM_LIT:1>]<EOL><DEDENT>name, length = _parse_name_and_length(label)<EOL>return Node.create(name=name, length=length, descendants=descendants, **kw)<EOL>

Parse a Newick formatted string into a `Node` object.

:param s: Newick formatted string to parse.
:param strip_comments: Flag signaling whether to strip comments enclosed in square \
brackets.
:param kw: Keyword arguments are passed through to `Node.create`.
:return: `Node` instance.


def __init__(self, name=None, length=None, **kw):

for char in RESERVED_PUNCTUATION:<EOL><INDENT>if (name and char in name) or (length and char in length):<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>' % char)<EOL><DEDENT><DEDENT>self.name = name<EOL>self._length = length<EOL>self.descendants = []<EOL>self.ancestor = None<EOL>self._length_parser = kw.pop('<STR_LIT>', length_parser)<EOL>self._length_formatter = kw.pop('<STR_LIT>', length_formatter)<EOL>

:param name: Node label.
:param length: Branch length from the new node to its parent.
:param kw: Recognized keyword arguments:\
    `length_parser`: Custom parser for the `length` attribute of a Node.\
    `length_formatter`: Custom formatter for the branch length when formatting a\
    Node as Newick string.


@classmethod<EOL><INDENT>def create(cls, name=None, length=None, descendants=None, **kw):<DEDENT>

node = cls(name=name, length=length, **kw)<EOL>for descendant in descendants or []:<EOL><INDENT>node.add_descendant(descendant)<EOL><DEDENT>return node<EOL>

Create a new `Node` object.

:param name: Node label.
:param length: Branch length from the new node to its parent.
:param descendants: list of descendants or `None`.
:param kw: Additonal keyword arguments are passed through to `Node.__init__`.
:return: `Node` instance.


label = self.name or '<STR_LIT>'<EOL>if self._length:<EOL><INDENT>label += '<STR_LIT::>' + self._length<EOL><DEDENT>descendants = '<STR_LIT:U+002C>'.join([n.newick for n in self.descendants])<EOL>if descendants:<EOL><INDENT>descendants = '<STR_LIT:(>' + descendants + '<STR_LIT:)>'<EOL><DEDENT>return descendants + label<EOL>

The representation of the Node in Newick format.


def ascii_art(self, strict=False, show_internal=True):

cmap = {<EOL>'<STR_LIT>': '<STR_LIT:->',<EOL>'<STR_LIT>': '<STR_LIT:|>',<EOL>'<STR_LIT>': '<STR_LIT:/>',<EOL>'<STR_LIT>': '<STR_LIT:\\>',<EOL>'<STR_LIT>': '<STR_LIT:|>',<EOL>'<STR_LIT>': '<STR_LIT:|>',<EOL>'<STR_LIT>': '<STR_LIT:+>',<EOL>}<EOL>def normalize(line):<EOL><INDENT>m = re.compile('<STR_LIT>')<EOL>line = m.sub(lambda m: m.group('<STR_LIT:s>')[<NUM_LIT:1>:], line)<EOL>line = re.sub('<STR_LIT>', '<STR_LIT>', line)  <EOL>line = re.sub('<STR_LIT>', '<STR_LIT>', line)  <EOL>line = re.sub('<STR_LIT>', '<STR_LIT>', line)  <EOL>if strict:<EOL><INDENT>for u, a in cmap.items():<EOL><INDENT>line = line.replace(u, a)<EOL><DEDENT><DEDENT>return line<EOL><DEDENT>return '<STR_LIT:\n>'.join(<EOL>normalize(l) for l in self._ascii_art(show_internal=show_internal)[<NUM_LIT:0>]<EOL>if set(l) != {'<STR_LIT:U+0020>', '<STR_LIT>'})<EOL>

Return a unicode string representing a tree in ASCII art fashion.

:param strict: Use ASCII characters strictly (for the tree symbols).
:param show_internal: Show labels of internal nodes.
:return: unicode string

>>> node = loads('((A,B)C,((D,E)F,G,H)I)J;')[0]
>>> print(node.ascii_art(show_internal=False, strict=True))
        /-A
    /---|
    |   \-B
----|       /-D
    |   /---|
    |   |   \-E
    \---|
        |-G
        \-H


if mode == '<STR_LIT>':<EOL><INDENT>for n in self._postorder():<EOL><INDENT>yield n<EOL><DEDENT><DEDENT>else:  <EOL><INDENT>yield self<EOL>for node in self.descendants:<EOL><INDENT>for n in node.walk():<EOL><INDENT>yield n<EOL><DEDENT><DEDENT><DEDENT>

Traverses the (sub)tree rooted at self, yielding each visited Node.

.. seealso:: https://en.wikipedia.org/wiki/Tree_traversal

:param mode: Specifies the algorithm to use when traversing the subtree rooted \
at self. `None` for breadth-first, `'postorder'` for post-order depth-first \
search.
:return: Generator of the visited Nodes.


def visit(self, visitor, predicate=None, **kw):

predicate = predicate or bool<EOL>for n in self.walk(**kw):<EOL><INDENT>if predicate(n):<EOL><INDENT>visitor(n)<EOL><DEDENT><DEDENT>

Apply a function to matching nodes in the (sub)tree rooted at self.

:param visitor: A callable accepting a Node object as single argument..
:param predicate: A callable accepting a Node object as single argument and \
returning a boolean signaling whether Node matches; if `None` all nodes match.
:param kw: Addtional keyword arguments are passed through to self.walk.


return [n for n in self.walk() if n.is_leaf]<EOL>

Get all the leaf nodes of the subtree descending from this node.

:return: List of Nodes with no descendants.


for n in self.walk():<EOL><INDENT>if n.name == label:<EOL><INDENT>return n<EOL><DEDENT><DEDENT>

Gets the specified node by name.

:return: Node or None if name does not exist in tree


return [n.name for n in self.get_leaves()]<EOL>

Get the names of all the leaf nodes of the subtree descending from
this node.

:return: List of names of Nodes with no descendants.


self.visit(<EOL>lambda n: n.ancestor.descendants.remove(n),<EOL>lambda n: ((not inverse and n in leaves) or<EOL>(inverse and n.is_leaf and n not in leaves)) and n.ancestor,<EOL>mode="<STR_LIT>")<EOL>

Remove all those nodes in the specified list, or if inverse=True,
remove all those nodes not in the specified list.  The specified nodes
must be leaves and distinct from the root node.

:param nodes: A list of Node objects
:param inverse: Specifies whether to remove nodes in the list or not\
        in the list.


def prune_by_names(self, leaf_names, inverse=False):

self.prune([l for l in self.walk() if l.name in leaf_names], inverse)<EOL>

Perform an (inverse) prune, with leaves specified by name.
:param node_names: A list of leaaf Node names (strings)
:param inverse: Specifies whether to remove nodes in the list or not\
        in the list.


for n in self.walk(mode='<STR_LIT>'):<EOL><INDENT>while n.ancestor and len(n.ancestor.descendants) == <NUM_LIT:1>:<EOL><INDENT>grandfather = n.ancestor.ancestor<EOL>father = n.ancestor<EOL>if preserve_lengths:<EOL><INDENT>n.length += father.length<EOL><DEDENT>if grandfather:<EOL><INDENT>for i, child in enumerate(grandfather.descendants):<EOL><INDENT>if child is father:<EOL><INDENT>del grandfather.descendants[i]<EOL><DEDENT><DEDENT>grandfather.add_descendant(n)<EOL>father.ancestor = None<EOL><DEDENT>else:<EOL><INDENT>self.descendants = n.descendants<EOL>if preserve_lengths:<EOL><INDENT>self.length = n.length<EOL><DEDENT><DEDENT><DEDENT><DEDENT>

Remove all nodes which have only a single child, and attach their
grandchildren to their parent.  The resulting tree has the minimum
number of internal nodes required for the number of leaves.
:param preserve_lengths: If true, branch lengths of removed nodes are \
added to those of their children.


def _resolve_polytomies(n):<EOL><INDENT>new = Node(length=self._length_formatter(self._length_parser('<STR_LIT:0>')))<EOL>while len(n.descendants) > <NUM_LIT:1>:<EOL><INDENT>new.add_descendant(n.descendants.pop())<EOL><DEDENT>n.descendants.append(new)<EOL><DEDENT>self.visit(_resolve_polytomies, lambda n: len(n.descendants) > <NUM_LIT:2>)<EOL>

Insert additional nodes with length=0 into the subtree in such a way
that all non-leaf nodes have only 2 descendants, i.e. the tree becomes
a fully resolved binary tree.


self.visit(lambda n: setattr(n, '<STR_LIT:name>', None))<EOL>

Set the name of all nodes in the subtree to None.


self.visit(lambda n: setattr(n, '<STR_LIT:name>', None), lambda n: not n.is_leaf)<EOL>

Set the name of all non-leaf nodes in the subtree to None.


self.visit(lambda n: setattr(n, '<STR_LIT:name>', None), lambda n: n.is_leaf)<EOL>

Set the name of all leaf nodes in the subtree to None.


self.visit(lambda n: setattr(n, '<STR_LIT>', None))<EOL>

Set the length of all nodes in the subtree to None.


pass<EOL>


self.msg = msg<EOL>return len(msg)<EOL>


return self.msg[<NUM_LIT:0>:buffer_size]<EOL>


self.msg = msg<EOL>


cam = AsyncCAM(loop=loop)<EOL>await cam.connect()<EOL>print(cam.welcome_msg)<EOL>await cam.send(b'<STR_LIT>')<EOL>print(await cam.receive())<EOL>await cam.send(b'<STR_LIT>')<EOL>print(await cam.wait_for(cmd='<STR_LIT>', timeout=<NUM_LIT:0.1>))<EOL>await cam.send(b'<STR_LIT>')<EOL>print(await cam.wait_for(cmd='<STR_LIT>', timeout=<NUM_LIT:0>))<EOL>print(await cam.wait_for(cmd='<STR_LIT>', timeout=<NUM_LIT:0.1>))<EOL>print(await cam.wait_for(cmd='<STR_LIT:test>', timeout=<NUM_LIT:0.1>))<EOL>cam.close()<EOL>


def __init__(self, *args, loop=None, **kwargs):

super().__init__(*args, **kwargs)<EOL>self.loop = loop or asyncio.get_event_loop()<EOL>self.reader = None<EOL>self.writer = None<EOL>self.welcome_msg = None<EOL>


self.reader, self.writer = await asyncio.open_connection(<EOL>self.host, self.port, loop=self.loop)<EOL>self.welcome_msg = await self.reader.read(self.buffer_size)<EOL>


msg = self._prepare_send(commands)<EOL>self.writer.write(msg)<EOL>await self.writer.drain()<EOL>

Send commands to LASAF through CAM-socket.

        Parameters
        ----------
        commands : list of tuples or bytes string
            Commands as a list of tuples or a bytes string. cam.prefix is
            allways prepended before sending.

        Returns
        -------
        int
            Bytes sent.

        Example
        -------
        ::

            >>> # send list of tuples
            >>> await cam.send([('cmd', 'enableall'), ('value', 'true')])

            >>> # send bytes string
            >>> await cam.send(b'/cmd:enableall /value:true')


try:<EOL><INDENT>incomming = await self.reader.read(self.buffer_size)<EOL><DEDENT>except OSError:<EOL><INDENT>return []<EOL><DEDENT>return _parse_receive(incomming)<EOL>

Receive message from socket interface as list of OrderedDict.


async def wait_for(self, cmd, value=None, timeout=<NUM_LIT>):

try:<EOL><INDENT>async with async_timeout(timeout * <NUM_LIT>):<EOL><INDENT>while True:<EOL><INDENT>msgs = await self.receive()<EOL>msg = check_messages(msgs, cmd, value=value)<EOL>if msg:<EOL><INDENT>return msg<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except asyncio.TimeoutError:<EOL><INDENT>return OrderedDict()<EOL><DEDENT>

Hang until command is received.

        If value is supplied, it will hang until ``cmd:value`` is received.

        Parameters
        ----------
        cmd : string
            Command to wait for in bytestring from microscope CAM interface. If
            ``value`` is falsey, value of received command does not matter.
        value : string
            Wait until ``cmd:value`` is received.
        timeout : int
            Minutes to wait for command. If timeout is reached, an empty
            OrderedDict will be returned.

        Returns
        -------
        collections.OrderedDict
            Last received messsage or empty message if timeout is reached.


if self.writer.can_write_eof():<EOL><INDENT>self.writer.write_eof()<EOL><DEDENT>self.writer.close()<EOL>


@functools.wraps(function)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>sep = kwargs.get('<STR_LIT>', '<STR_LIT:U+0020>')<EOL>end = kwargs.get('<STR_LIT:end>', '<STR_LIT>')  <EOL>out = sep.join([repr(x) for x in args])<EOL>out = out + end<EOL>_LOGGER.debug(out)<EOL>return function(*args, **kwargs)<EOL><DEDENT>return wrapper<EOL>

Decorate passed in function and log message to module logger.


debug(b'<STR_LIT>' + incomming)<EOL>incomming = incomming.rstrip(b'<STR_LIT:\x00>')<EOL>msgs = incomming.splitlines()<EOL>return [bytes_as_dict(msg) for msg in msgs]<EOL>

Parse received response.

    Parameters
    ----------
    incomming : bytes string
        Incomming bytes from socket server.

    Returns
    -------
    list of OrderedDict
        Received message as a list of OrderedDict.


cmds = OrderedDict(cmds)  <EOL>tmp = []<EOL>for key, val in cmds.items():<EOL><INDENT>key = str(key)<EOL>val = str(val)<EOL>tmp.append('<STR_LIT:/>' + key + '<STR_LIT::>' + val)<EOL><DEDENT>return '<STR_LIT:U+0020>'.join(tmp).encode()<EOL>

Format list of tuples to CAM message with format /key:val.

    Parameters
    ----------
    cmds : list of tuples
        List of commands as tuples.

    Returns
    -------
    bytes
        Sequence of /key:val.

    Example
    -------
    ::

        >>> tuples_as_bytes([('cmd', 'val'), ('cmd2', 'val2')])
        b'/cmd:val /cmd2:val2'


_dict = OrderedDict()<EOL>for key, val in _list:<EOL><INDENT>key = str(key)<EOL>val = str(val)<EOL>_dict[key] = val<EOL><DEDENT>return _dict<EOL>

Translate a list of tuples to OrderedDict with key and val as strings.

    Parameters
    ----------
    _list : list of tuples

    Returns
    -------
    collections.OrderedDict

    Example
    -------
    ::

        >>> tuples_as_dict([('cmd', 'val'), ('cmd2', 'val2')])
        OrderedDict([('cmd', 'val'), ('cmd2', 'val2')])


<EOL>cmd_strings = msg.decode()[<NUM_LIT:1>:].split(r'<STR_LIT>')<EOL>cmds = OrderedDict()<EOL>for cmd in cmd_strings:<EOL><INDENT>unpacked = cmd.split('<STR_LIT::>')<EOL>if len(unpacked) > <NUM_LIT:2>:<EOL><INDENT>key = unpacked[<NUM_LIT:0>]<EOL>val = '<STR_LIT::>'.join(unpacked[<NUM_LIT:1>:])<EOL><DEDENT>elif len(unpacked) < <NUM_LIT:2>:<EOL><INDENT>continue<EOL><DEDENT>else:<EOL><INDENT>key, val = unpacked<EOL><DEDENT>cmds[key] = val<EOL><DEDENT>return cmds<EOL>

Parse CAM message to OrderedDict based on format /key:val.

    Parameters
    ----------
    msg : bytes
        Sequence of /key:val.

    Returns
    -------
    collections.OrderedDict
        With /key:val => dict[key] = val.


def check_messages(msgs, cmd, value=None):

for msg in msgs:<EOL><INDENT>if value and msg.get(cmd) == value:<EOL><INDENT>return msg<EOL><DEDENT>if not value and msg.get(cmd):<EOL><INDENT>return msg<EOL><DEDENT><DEDENT>return None<EOL>

Check if specific message is present.

    Parameters
    ----------
    cmd : string
        Command to check for in bytestring from microscope CAM interface. If
        ``value`` is falsey, value of received command does not matter.
    value : string
        Check if ``cmd:value`` is received.

    Returns
    -------
    collections.OrderedDict
        Correct messsage or None if no correct message if found.


def __init__(self, host='<STR_LIT:127.0.0.1>', port=<NUM_LIT>):

self.host = host<EOL>self.port = port<EOL>self.prefix = [('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>')]<EOL>self.prefix_bytes = b'<STR_LIT>'<EOL>self.buffer_size = <NUM_LIT><EOL>self.delay = <NUM_LIT:0.1><EOL>


raise NotImplementedError<EOL>

Send commands to LASAF through CAM-socket.

        Parameters
        ----------
        commands : list of tuples or bytes string
            Commands as a list of tuples or a bytes string. cam.prefix is
            allways prepended before sending.

        Returns
        -------
        int
            Bytes sent.

        Example
        -------
        ::

            >>> # send list of tuples
            >>> cam.send([('cmd', 'enableall'), ('value', 'true')])

            >>> # send bytes string
            >>> cam.send(b'/cmd:enableall /value:true')


raise NotImplementedError<EOL>


def wait_for(self, cmd, value=None, timeout=<NUM_LIT>):

raise NotImplementedError<EOL>


if isinstance(commands, bytes):<EOL><INDENT>msg = self.prefix_bytes + commands<EOL><DEDENT>else:<EOL><INDENT>msg = tuples_as_bytes(self.prefix + commands)<EOL><DEDENT>debug(b'<STR_LIT>' + msg)<EOL>return msg<EOL>

Prepare message to be sent.

        Parameters
        ----------
        commands : list of tuples or bytes string
            Commands as a list of tuples or a bytes string. cam.prefix is
            allways prepended before sending.

        Returns
        -------
        string
            Message to be sent.


super(CAM, self).__init__(*args, **kwargs)<EOL>self.connect()<EOL>


self.socket = socket.socket()<EOL>self.socket.connect((self.host, self.port))<EOL>self.socket.settimeout(False)  <EOL>sleep(self.delay)  <EOL>self.welcome_msg = self.socket.recv(<EOL>self.buffer_size)<EOL>


debug('<STR_LIT>')<EOL>try:<EOL><INDENT>while True:<EOL><INDENT>msg = self.socket.recv(self.buffer_size)<EOL>debug(b'<STR_LIT>' + msg)<EOL><DEDENT><DEDENT>except socket.error:<EOL><INDENT>pass<EOL><DEDENT>


self.flush()  <EOL>msg = self._prepare_send(commands)<EOL>return self.socket.send(msg)<EOL>


try:<EOL><INDENT>incomming = self.socket.recv(self.buffer_size)<EOL><DEDENT>except socket.error:<EOL><INDENT>return []<EOL><DEDENT>return _parse_receive(incomming)<EOL>


wait = time() + timeout * <NUM_LIT><EOL>while True:<EOL><INDENT>if time() > wait:<EOL><INDENT>return OrderedDict()<EOL><DEDENT>msgs = self.receive()<EOL>msg = check_messages(msgs, cmd, value=value)<EOL>if msg:<EOL><INDENT>return msg<EOL><DEDENT>sleep(self.delay)<EOL><DEDENT>


self.socket.close()<EOL>


cmd = [('<STR_LIT>', '<STR_LIT>')]<EOL>self.send(cmd)<EOL>return self.wait_for(*cmd[<NUM_LIT:0>])<EOL>


def enable(self, slide=<NUM_LIT:0>, wellx=<NUM_LIT:1>, welly=<NUM_LIT:1>, fieldx=<NUM_LIT:1>, fieldy=<NUM_LIT:1>):

<EOL>cmd = [<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', str(slide)),<EOL>('<STR_LIT>', str(wellx)),<EOL>('<STR_LIT>', str(welly)),<EOL>('<STR_LIT>', str(fieldx)),<EOL>('<STR_LIT>', str(fieldy)),<EOL>('<STR_LIT:value>', '<STR_LIT:true>')<EOL>]<EOL>self.send(cmd)<EOL>return self.wait_for(*cmd[<NUM_LIT:0>])<EOL>


def disable(self, slide=<NUM_LIT:0>, wellx=<NUM_LIT:1>, welly=<NUM_LIT:1>, fieldx=<NUM_LIT:1>, fieldy=<NUM_LIT:1>):

<EOL>cmd = [<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', str(slide)),<EOL>('<STR_LIT>', str(wellx)),<EOL>('<STR_LIT>', str(welly)),<EOL>('<STR_LIT>', str(fieldx)),<EOL>('<STR_LIT>', str(fieldy)),<EOL>('<STR_LIT:value>', '<STR_LIT:false>')<EOL>]<EOL>self.send(cmd)<EOL>return self.wait_for(*cmd[<NUM_LIT:0>])<EOL>


cmd = [('<STR_LIT>', '<STR_LIT>'), ('<STR_LIT:value>', '<STR_LIT:true>')]<EOL>self.send(cmd)<EOL>return self.wait_for(*cmd[<NUM_LIT:0>])<EOL>


cmd = [('<STR_LIT>', '<STR_LIT>'), ('<STR_LIT:value>', '<STR_LIT:false>')]<EOL>self.send(cmd)<EOL>return self.wait_for(*cmd[<NUM_LIT:0>])<EOL>


cmd = [<EOL>('<STR_LIT>', '<STR_LIT:0>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', str(filename))<EOL>]<EOL>self.send(cmd)<EOL>return self.wait_for(*cmd[<NUM_LIT:0>])<EOL>


basename = os.path.basename(filename)<EOL>if basename[-<NUM_LIT:4>:] == '<STR_LIT>':<EOL><INDENT>basename = basename[:-<NUM_LIT:4>]<EOL><DEDENT>if basename[:<NUM_LIT>] != '<STR_LIT>':<EOL><INDENT>basename = '<STR_LIT>' + basename<EOL><DEDENT>cmd = [<EOL>('<STR_LIT>', '<STR_LIT:0>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', str(basename))<EOL>]<EOL>self.send(cmd)<EOL>return self.wait_for(*cmd[<NUM_LIT:1>])<EOL>

Load scanning template from filename.

        Template needs to exist in database, otherwise it will not load.

        Parameters
        ----------
        filename : str
            Filename to template to load. Filename may contain path also, in
            such case, the basename will be used. '.xml' will be stripped
            from the filename if it exists because of a bug; LASAF implicit
            add '.xml'. If '{ScanningTemplate}' is omitted, it will be added.

        Returns
        -------
        collections.OrderedDict
            Response from LASAF in an ordered dict.

        Example
        -------
        ::

            >>> # load {ScanningTemplate}leicacam.xml
            >>> cam.load_template('leicacam')

            >>> # load {ScanningTemplate}leicacam.xml
            >>> cam.load_template('{ScanningTemplate}leicacam')

            >>> # load {ScanningTemplate}leicacam.xml
            >>> cam.load_template('/path/to/{ScanningTemplate}leicacam.xml')


cmd = [<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', str(about))<EOL>]<EOL>self.send(cmd)<EOL>return self.wait_for(*cmd[<NUM_LIT:1>])<EOL>

Get information about given keyword. Defaults to stage.


import leicacam<EOL>version_string = leicacam.__version__<EOL>versions = version_string.split('<STR_LIT:.>', <NUM_LIT:3>)<EOL>try:<EOL><INDENT>for ver in versions:<EOL><INDENT>int(ver)<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>print(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format(version_string))<EOL>return None<EOL><DEDENT>return version_string<EOL>


old_dir = os.getcwd()<EOL>proj_dir = os.path.join(os.path.dirname(__file__), os.pardir)<EOL>os.chdir(proj_dir)<EOL>version = validate_version()<EOL>if not version:<EOL><INDENT>os.chdir(old_dir)<EOL>return<EOL><DEDENT>print('<STR_LIT>'.format(version))<EOL>options = [<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', version]<EOL>generator = ChangelogGenerator(options)<EOL>generator.run()<EOL>os.chdir(old_dir)<EOL>


def gen_filter(name, op, value, is_or=False):

if op not in OPERATORS:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(op))<EOL><DEDENT>result = u'<STR_LIT>'.format(name, op, escape_filter(value))<EOL>if is_or:<EOL><INDENT>result = u'<STR_LIT>' + result<EOL><DEDENT>return result<EOL>

Generates a single filter expression for ``filter[]``.


if not d:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>items = list(d.items())<EOL>key, value = items.pop(<NUM_LIT:0>)<EOL>q = cls(key, u'<STR_LIT:=>', value)<EOL>for key, value in items:<EOL><INDENT>q = q & cls(key, u'<STR_LIT:=>', value)<EOL><DEDENT>return q<EOL>

Creates a query (AND and =) from a dictionary.


for qc in QUOTES:<EOL><INDENT>if qc != q:<EOL><INDENT>return qc<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError(u'<STR_LIT>'.format(q))<EOL><DEDENT>

When you pass a quote character, returns you an another one if possible


if o is None:<EOL><INDENT>return u'<STR_LIT>'<EOL><DEDENT>if isinstance(o, int):<EOL><INDENT>return str(o)<EOL><DEDENT>if not isinstance(o, six.string_types):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if not o:<EOL><INDENT>return u"<STR_LIT>"<EOL><DEDENT>o = unicode_process(o)<EOL>if u'<STR_LIT:">' not in o:<EOL><INDENT>return u'<STR_LIT:">' + o + u'<STR_LIT:">'<EOL><DEDENT>elif u"<STR_LIT:'>" not in o:<EOL><INDENT>return u"<STR_LIT:'>" + o + u"<STR_LIT:'>"<EOL><DEDENT>else:<EOL><INDENT>first_char = o[<NUM_LIT:0>]<EOL>last_char = o[-<NUM_LIT:1>]<EOL>if first_char in QUOTES and last_char in QUOTES:<EOL><INDENT>if first_char == last_char:<EOL><INDENT>quote = give_another_quote(first_char)<EOL>return quote + o + quote<EOL><DEDENT>else:<EOL><INDENT>return u"<STR_LIT:'>" + o + u"<STR_LIT:'>"<EOL><DEDENT><DEDENT>elif first_char not in QUOTES and last_char not in QUOTES:<EOL><INDENT>return u"<STR_LIT:'>" + o + u"<STR_LIT:'>"<EOL><DEDENT>else:<EOL><INDENT>if first_char in QUOTES:<EOL><INDENT>quote = give_another_quote(first_char)<EOL><DEDENT>else:<EOL><INDENT>quote = give_another_quote(last_char)<EOL><DEDENT>return quote + o + quote<EOL><DEDENT><DEDENT>

Tries to escape the values that are passed to filter as correctly as possible.

    No standard way is followed, but at least it is simple.


def __init__(self, entry_point, auth, logger=None, verify_ssl=True, ca_bundle_path=None):

self._entry_point = entry_point<EOL>self._auth = auth<EOL>self._verify_ssl = verify_ssl<EOL>self._ca_bundle_path = ca_bundle_path<EOL>self._session = requests.Session()<EOL>self._session.headers.update({'<STR_LIT:Content-Type>': '<STR_LIT>'})<EOL>self._build_auth(auth)<EOL>if not verify_ssl:<EOL><INDENT>self._session.verify = False<EOL><DEDENT>elif ca_bundle_path:<EOL><INDENT>self._session.verify = ca_bundle_path<EOL><DEDENT>self.logger = logger or logging.getLogger(__name__)<EOL>self.response = None<EOL>self._load_data()<EOL>

If ca_bundle_path is specified it replaces the system's trusted root CAs


return SearchResult(self, self._api.get(self._href, **params))<EOL>

Specify query string to use with the collection.

        Returns: :py:class:`SearchResult`


return SearchResult(self, self._api.get(self._href, **{"<STR_LIT>": filters}))<EOL>

Sends all filters to the API.

        No fancy, just a wrapper. Any advanced functionality shall be implemented as another method.

        Args:
            filters: List of filters (strings)

        Returns: :py:class:`SearchResult`


return self.raw_filter(q.as_filters)<EOL>

Access the ``filter[]`` functionality of ManageIQ.

        Args:
            q: An instance of :py:class:`filters.Q`

        Returns: :py:class:`SearchResult`


return self.filter(Q.from_dict(params))<EOL>

Searches in ManageIQ using the ``filter[]`` get parameter.

        This method only supports logical AND so all key/value pairs are considered as equality
        comparision and all are logically anded.


self.reload(expand=True, attributes=attributes)<EOL>entities = [Entity(self, r, attributes=attributes) for r in self._resources]<EOL>self.reload()<EOL>return entities<EOL>

Returns all entities present in the collection with ``attributes`` included.


href_result = result['<STR_LIT>']<EOL>if self.collection._href.startswith(href_result):<EOL><INDENT>return Entity(self.collection, result, incomplete=True)<EOL><DEDENT>href_match = re.match(r"<STR_LIT>", href_result)<EOL>if not href_match:<EOL><INDENT>raise ValueError("<STR_LIT>".format(href_result))<EOL><DEDENT>collection_name = href_match.group(<NUM_LIT:2>)<EOL>entry_point = href_match.group(<NUM_LIT:1>)<EOL>new_collection = Collection(<EOL>self.collection.api,<EOL>"<STR_LIT>".format(entry_point, collection_name),<EOL>collection_name<EOL>)<EOL>return Entity(new_collection, result, incomplete=True)<EOL>

Returns entity in correct collection.

        If the "href" value in result doesn't match the current collection,
        try to find the collection that the "href" refers to.


k, _, v = value.partition('<STR_LIT:=>')<EOL>k, v = k.strip(), v.strip().encode('<STR_LIT>').decode('<STR_LIT:ascii>')<EOL>if v and v[<NUM_LIT:0>] == v[-<NUM_LIT:1>] in ['<STR_LIT:">', "<STR_LIT:'>"]:<EOL><INDENT>v = __escape_decoder(v[<NUM_LIT:1>:-<NUM_LIT:1>])[<NUM_LIT:0>]<EOL><DEDENT>return k, v<EOL>

Split a env var text like

ENV_VAR_NAME=env_var_value

into a tuple ('ENV_VAR_NAME', 'env_var_value')


<EOL>try:<EOL><INDENT>click_log.basic_config('<STR_LIT>')<EOL>logger.debug('<STR_LIT>')<EOL>if edit:<EOL><INDENT>if ctx.invoked_subcommand is None:<EOL><INDENT>logger.debug('<STR_LIT>', config.LOCAL_CONFIG_FILE)<EOL>config.ConfigFileResolver(config.LOCAL_CONFIG_FILE).edit(create=create)<EOL>return<EOL><DEDENT>else:<EOL><INDENT>raise UsageError('<STR_LIT>')<EOL><DEDENT><DEDENT>if ctx.invoked_subcommand is None:<EOL><INDENT>click.echo(main.get_help(ctx))<EOL><DEDENT><DEDENT>except exceptions.FileDoesNotExist as e:<EOL><INDENT>raise UsageError('<STR_LIT>'.format(str(e)))<EOL><DEDENT>

Simple command line tool to help manage environment variables stored in a S3-like system. Facilitates editing text
files remotely stored, as well as downloading and uploading files.


try:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>settings = config.Settings(section=section)<EOL>storage = STORAGES['<STR_LIT>'](settings=settings)<EOL>conf = s3conf.S3Conf(storage=storage, settings=settings)<EOL>if edit:<EOL><INDENT>conf.edit(create=create)<EOL><DEDENT>else:<EOL><INDENT>env_vars = conf.get_envfile().as_dict()<EOL>if env_vars.get('<STR_LIT>') and map_files:<EOL><INDENT>conf.download_mapping(env_vars.get('<STR_LIT>'))<EOL><DEDENT>if not quiet:<EOL><INDENT>for var_name, var_value in sorted(env_vars.items(), key=lambda x: x[<NUM_LIT:0>]):<EOL><INDENT>click.echo('<STR_LIT>'.format(var_name, var_value))<EOL><DEDENT><DEDENT>if phusion:<EOL><INDENT>s3conf.phusion_dump(env_vars, phusion_path)<EOL><DEDENT><DEDENT><DEDENT>except exceptions.EnvfilePathNotDefinedError:<EOL><INDENT>raise exceptions.EnvfilePathNotDefinedUsageError()<EOL><DEDENT>except exceptions.FileDoesNotExist as e:<EOL><INDENT>raise UsageError('<STR_LIT>'.format(str(e)))<EOL><DEDENT>

Reads the file defined by the S3CONF variable and output its contents to stdout. Logs are printed to stderr.
See options for added functionality: editing file, mapping files, dumping in the phusion-baseimage format, etc.


try:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>existing_sections = config.ConfigFileResolver(config.LOCAL_CONFIG_FILE).sections()<EOL>command = '<STR_LIT:U+0020>'.join(command)<EOL>if section not in existing_sections:<EOL><INDENT>command = '<STR_LIT>'.format(section, command) if command else section<EOL>section = None<EOL><DEDENT>if not command:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL>click.echo(exec_command.get_help(ctx))<EOL>return<EOL><DEDENT>settings = config.Settings(section=section)<EOL>storage = STORAGES['<STR_LIT>'](settings=settings)<EOL>conf = s3conf.S3Conf(storage=storage, settings=settings)<EOL>env_vars = conf.get_envfile().as_dict()<EOL>if env_vars.get('<STR_LIT>') and map_files:<EOL><INDENT>conf.download_mapping(env_vars.get('<STR_LIT>'))<EOL><DEDENT>current_env = os.environ.copy()<EOL>current_env.update(env_vars)<EOL>logger.debug('<STR_LIT>', command)<EOL>subprocess.run(shlex.split(command), env=current_env, check=True)<EOL><DEDENT>except exceptions.EnvfilePathNotDefinedError:<EOL><INDENT>raise exceptions.EnvfilePathNotDefinedUsageError()<EOL><DEDENT>

Sets the process environemnt and executes the [COMMAND] in the same context. Does not modify the current shell
environment.

If the [COMMAND] has option-like arguments, use the standard POSIX pattern "--" to separate options
from arguments. Considering our configuration in the "dev" section, we could write:

s3conf -v info exec dev -- ping -v google.com


storage = STORAGES['<STR_LIT>']()<EOL>conf = s3conf.S3Conf(storage=storage)<EOL>conf.download(remote_path, local_path)<EOL>

Download a file or folder from the S3-like service.

If REMOTE_PATH has a trailing slash it is considered to be a folder, e.g.: "s3://my-bucket/my-folder/". In this
case, LOCAL_PATH must be a folder as well. The files and subfolder structure in REMOTE_PATH are copied to
LOCAL_PATH.

If REMOTE_PATH does not have a trailing slash, it is considered to be a file, and LOCAL_PATH should be a file as
well.


storage = STORAGES['<STR_LIT>']()<EOL>conf = s3conf.S3Conf(storage=storage)<EOL>conf.upload(local_path, remote_path)<EOL>

Upload a file or folder to the S3-like service.

If LOCAL_PATH is a folder, the files and subfolder structure in LOCAL_PATH are copied to REMOTE_PATH.

If LOCAL_PATH is a file, the REMOTE_PATH file is created with the same contents.


try:<EOL><INDENT>settings = config.Settings(section=section)<EOL>storage = STORAGES['<STR_LIT>'](settings=settings)<EOL>conf = s3conf.S3Conf(storage=storage, settings=settings)<EOL>local_root = os.path.join(config.LOCAL_CONFIG_FOLDER, section)<EOL>conf.downsync(local_root, map_files=map_files)<EOL><DEDENT>except exceptions.EnvfilePathNotDefinedError:<EOL><INDENT>raise exceptions.EnvfilePathNotDefinedUsageError()<EOL><DEDENT>

For each section defined in the local config file, creates a folder inside the local config folder
named after the section. Downloads the environemnt file defined by the S3CONF variable for this section
to this folder.


try:<EOL><INDENT>settings = config.Settings(section=section)<EOL>storage = STORAGES['<STR_LIT>'](settings=settings)<EOL>conf = s3conf.S3Conf(storage=storage, settings=settings)<EOL>local_root = os.path.join(config.LOCAL_CONFIG_FOLDER, section)<EOL>conf.upsync(local_root, map_files=map_files)<EOL><DEDENT>except exceptions.EnvfilePathNotDefinedError:<EOL><INDENT>raise exceptions.EnvfilePathNotDefinedUsageError()<EOL><DEDENT>

For each section defined in the local config file, look up for a folder inside the local config folder
named after the section. Uploads the environemnt file named as in the S3CONF variable for this section
to the remote S3CONF path.


try:<EOL><INDENT>settings = config.Settings(section=section)<EOL>storage = STORAGES['<STR_LIT>'](settings=settings)<EOL>conf = s3conf.S3Conf(storage=storage, settings=settings)<EOL>local_root = os.path.join(config.LOCAL_CONFIG_FOLDER, section)<EOL>click.echo('<STR_LIT>'.join(conf.diff(local_root)))<EOL><DEDENT>except exceptions.EnvfilePathNotDefinedError:<EOL><INDENT>raise exceptions.EnvfilePathNotDefinedUsageError()<EOL><DEDENT>


if not value:<EOL><INDENT>value = section<EOL>section = None<EOL><DEDENT>try:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>settings = config.Settings(section=section)<EOL>conf = s3conf.S3Conf(settings=settings)<EOL>env_vars = conf.get_envfile()<EOL>env_vars.set(value, create=create)<EOL><DEDENT>except exceptions.EnvfilePathNotDefinedError:<EOL><INDENT>raise exceptions.EnvfilePathNotDefinedUsageError()<EOL><DEDENT>

Set value of a variable in an environment file for the given section.
If the variable is already defined, its value is replaced, otherwise, it is added to the end of the file.
The value is given as "ENV_VAR_NAME=env_var_value", e.g.:

s3conf set test ENV_VAR_NAME=env_var_value


if not value:<EOL><INDENT>value = section<EOL>section = None<EOL><DEDENT>try:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>settings = config.Settings(section=section)<EOL>conf = s3conf.S3Conf(settings=settings)<EOL>env_vars = conf.get_envfile()<EOL>env_vars.unset(value)<EOL><DEDENT>except exceptions.EnvfilePathNotDefinedError:<EOL><INDENT>raise exceptions.EnvfilePathNotDefinedUsageError()<EOL><DEDENT>

Unset a variable in an environment file for the given section.
The value is given is the variable name, e.g.:

s3conf unset test ENV_VAR_NAME


if not remote_file.startswith('<STR_LIT>'):<EOL><INDENT>raise UsageError('<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>logger.debug('<STR_LIT>')<EOL>config_file_path = os.path.join(os.getcwd(), '<STR_LIT>', '<STR_LIT>')<EOL>config_file = config.ConfigFileResolver(config_file_path, section=section)<EOL>config_file.set('<STR_LIT>', remote_file)<EOL>gitignore_file_path = os.path.join(os.getcwd(), '<STR_LIT>', '<STR_LIT>')<EOL>config_file.save()<EOL>open(gitignore_file_path, '<STR_LIT:w>').write('<STR_LIT>')<EOL>

Creates the .s3conf config folder and .s3conf/config config file
with the provided section name and configuration file. It is a very
basic config file. Manually edit it in order to add credentials. E.g.:

s3conf init development s3://my-project/development.env


return [dirpath<EOL>for dirpath, dirnames, filenames in os.walk(package)<EOL>if os.path.exists(os.path.join(dirpath, '<STR_LIT>'))]<EOL>

Return root package and all sub-packages.


walk = [(dirpath.replace(package + os.sep, '<STR_LIT>', <NUM_LIT:1>), filenames)<EOL>for dirpath, dirnames, filenames in os.walk(package)<EOL>if not os.path.exists(os.path.join(dirpath, '<STR_LIT>'))]<EOL>filepaths = []<EOL>for base, filenames in walk:<EOL><INDENT>filepaths.extend([os.path.join(base, filename)<EOL>for filename in filenames])<EOL><DEDENT>return {package: filepaths}<EOL>

Return all files under the root package, that are not in a
package themselves.


if language is None:<EOL><INDENT>language = getattr(settings, '<STR_LIT>', DJFRONTEND_H5BP_HTML_DEFAULT)<EOL><DEDENT>return format_html('<STR_LIT>', language)<EOL>

Returns HTML tag according to chosen language.
Included in HTML5 Boilerplate.


if version is None:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_H5BP_CSS_DEFAULT)<EOL><DEDENT>return format_html(<EOL>'<STR_LIT>',<EOL>_static_url, version)<EOL>

Returns HTML5 Boilerplate CSS file.
Included in HTML5 Boilerplate.


if version is None:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_NORMALIZE_DEFAULT)<EOL><DEDENT>return format_html(<EOL>'<STR_LIT>',<EOL>_static_url, version)<EOL>

Returns Normalize CSS file.
Included in HTML5 Boilerplate.


if version is None:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_FONTAWESOME_DEFAULT)<EOL><DEDENT>return format_html(<EOL>'<STR_LIT>',<EOL>_static_url, version, _min)<EOL>

Returns Font Awesome CSS file.
TEMPLATE_DEBUG returns full file, otherwise returns minified file.


if version is None:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_MODERNIZR_DEFAULT)<EOL><DEDENT>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>template = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>template = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>return format_html(template, static=_static_url, v=version)<EOL>

Returns Modernizr JavaScript file according to version number.
TEMPLATE_DEBUG returns full file, otherwise returns minified file.
Included in HTML5 Boilerplate.


if version is None:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERY_DEFAULT)<EOL><DEDENT>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>template = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>template = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>return format_html(template, static=_static_url, v=version)<EOL>

Returns jQuery JavaScript file according to version number.
TEMPLATE_DEBUG returns full file, otherwise returns minified file from Google CDN with local fallback.
Included in HTML5 Boilerplate.


if version is None:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERYUI_DEFAULT)<EOL><DEDENT>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>return format_html(<EOL>'<STR_LIT>',<EOL>settings.STATIC_URL, version)<EOL><DEDENT>else:<EOL><INDENT>return format_html(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>static=_static_url, v=version)<EOL><DEDENT>

Returns the jQuery UI plugin file according to version number.
TEMPLATE_DEBUG returns full file, otherwise returns minified file from Google CDN with local fallback.


if version is None:<EOL><INDENT>if not getattr(settings, '<STR_LIT>', False):<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERY_DATATABLES_VERSION_DEFAULT)<EOL><DEDENT>else:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERY_DATATABLES_VERSION_DEFAULT)<EOL><DEDENT><DEDENT>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>template = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>template = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>return format_html(template, static=_static_url, v=version)<EOL>

Returns the jQuery DataTables plugin file according to version number.
TEMPLATE_DEBUG returns full file, otherwise returns minified file.


if version is None:<EOL><INDENT>if not getattr(settings, '<STR_LIT>', False):<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERY_DATATABLES_VERSION_DEFAULT)<EOL><DEDENT>else:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERY_DATATABLES_VERSION_DEFAULT)<EOL><DEDENT><DEDENT>return format_html(<EOL>'<STR_LIT>',<EOL>static=_static_url, v=version, min=_min)<EOL>

Returns the jQuery DataTables CSS file according to version number.


if version is None:<EOL><INDENT>if not getattr(settings, '<STR_LIT>', False):<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERY_DATATABLES_VERSION_DEFAULT)<EOL><DEDENT>else:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERY_DATATABLES_VERSION_DEFAULT)<EOL><DEDENT><DEDENT>return format_html(<EOL>'<STR_LIT>',<EOL>static=_static_url, v=version)<EOL>

Returns the jQuery DataTables ThemeRoller CSS file according to version number.


if version is None:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERY_FORMSET_DEFAULT)<EOL><DEDENT>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>template = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>template = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>return format_html(template, static=_static_url, v=version)<EOL>

Returns the jQuery Dynamic Formset plugin file according to version number.
TEMPLATE_DEBUG returns full file, otherwise returns minified file.


if version is None:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERY_SCROLLTO_DEFAULT)<EOL><DEDENT>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>template = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>template = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>return format_html(template, static=_static_url, v=version)<EOL>

Returns the jQuery ScrollTo plugin file according to version number.
TEMPLATE_DEBUG returns full file, otherwise returns minified file.


if version is None:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_JQUERY_SMOOTHSCROLL_DEFAULT)<EOL><DEDENT>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>template = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>template = (<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>return format_html(template, static=_static_url, v=version)<EOL>

Returns the jQuery Smooth Scroll plugin file according to version number.
TEMPLATE_DEBUG returns full file, otherwise returns minified file.


if version is None:<EOL><INDENT>if not getattr(settings, '<STR_LIT>', False):<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_TWBS_VERSION_DEFAULT)<EOL><DEDENT>else:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_TWBS_VERSION_DEFAULT)<EOL><DEDENT><DEDENT>return format_html(<EOL>'<STR_LIT>',<EOL>static=_static_url, v=version, min=_min)<EOL>

Returns Twitter Bootstrap CSS file.
TEMPLATE_DEBUG returns full file, otherwise returns minified file.


Returns Twitter Bootstrap Theme CSS file.


if version is None:<EOL><INDENT>if not getattr(settings, '<STR_LIT>', False):<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_TWBS_VERSION_DEFAULT)<EOL><DEDENT>else:<EOL><INDENT>version = getattr(settings, '<STR_LIT>', DJFRONTEND_TWBS_VERSION_DEFAULT)<EOL><DEDENT><DEDENT>if files:<EOL><INDENT>if files != '<STR_LIT:all>':<EOL><INDENT>files = files.split('<STR_LIT:U+0020>')<EOL><DEDENT><DEDENT>elif getattr(settings, '<STR_LIT>', False) and settings.DJFRONTEND_TWBS_JS_FILES != '<STR_LIT:all>':<EOL><INDENT>files = settings.DJFRONTEND_TWBS_JS_FILES.split('<STR_LIT:U+0020>')<EOL><DEDENT>else:<EOL><INDENT>files = '<STR_LIT:all>'<EOL><DEDENT>if files == '<STR_LIT:all>':<EOL><INDENT>return format_html(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>',<EOL>v=version, static=_static_url)<EOL><DEDENT>else:<EOL><INDENT>if '<STR_LIT>' in files and '<STR_LIT>' not in files:<EOL><INDENT>files.append('<STR_LIT>')<EOL><DEDENT>for file in files:<EOL><INDENT>file = ['<STR_LIT>' %<EOL>(_static_url, version, file) for file in files]<EOL><DEDENT>return mark_safe('<STR_LIT:\n>'.join(file))<EOL><DEDENT>

Returns Twitter Bootstrap JavaScript file(s).
all returns concatenated file; full file for TEMPLATE_DEBUG, minified otherwise.

Other choice are:
    affix,
    alert,
    button,
    carousel,
    collapse,
    dropdown,
    modal,
    popover (adds tooltip if not included),
    scrollspy,
    tab,
    tooltip,
    transition.

Individual files are not minified.


if account is None:<EOL><INDENT>account = getattr(settings, '<STR_LIT>', False)<EOL><DEDENT>if account:<EOL><INDENT>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>if getattr(settings, '<STR_LIT>', False):<EOL><INDENT>return mark_safe(<EOL>'<STR_LIT>' %<EOL>(settings.DJFRONTEND_GA_SETDOMAINNAME, account))<EOL><DEDENT>else:<EOL><INDENT>return mark_safe(<EOL>'<STR_LIT>' %<EOL>(account, settings.DJFRONTEND_GA_SETDOMAINNAME))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return mark_safe(<EOL>'<STR_LIT>' % account)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>

Returns Google Analytics asynchronous snippet.
Use DJFRONTEND_GA_SETDOMAINNAME to set domain for multiple, or cross-domain tracking.
Set DJFRONTEND_GA_SETALLOWLINKER to use _setAllowLinker method on target site for cross-domain tracking.
Included in HTML5 Boilerplate.


categories = self.api.get("<STR_LIT>", {})<EOL>return categories<EOL>

Get a list of categories. List of all restaurants categorized under a particular restaurant
type can be obtained using /Search API with Category ID as inputs


params = {}<EOL>available_keys = ["<STR_LIT:q>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT:count>"]<EOL>for key in available_keys:<EOL><INDENT>if key in kwargs:<EOL><INDENT>params[key] = kwargs[key]<EOL><DEDENT><DEDENT>cities = self.api.get("<STR_LIT>", params)<EOL>return cities<EOL>

:param q: query by city name
:param lat: latitude
:param lon: longitude
:param city_ids: comma separated city_id values
:param count: number of max results to display

Find the Zomato ID and other details for a city . You can obtain the Zomato City ID in one of the following ways:
    -City Name in the Search Query - Returns list of cities matching the query
    -Using coordinates - Identifies the city details based on the coordinates of any location inside a city
If you already know the Zomato City ID, this API can be used to get other details of the city.


def getCollectionsViaCityId(self, city_id, **kwargs):

params = {"<STR_LIT>": city_id}<EOL>optional_params = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT:count>"]<EOL>for key in optional_params:<EOL><INDENT>if key in kwargs:<EOL><INDENT>params[key] = kwargs[key]<EOL><DEDENT><DEDENT>collections = self.api.get("<STR_LIT>", params)<EOL>return collections<EOL>

:param city_id: id of the city for which collections are needed
:param lat: latitude
:param lon: longitude
:param count: number of max results to display
Returns Zomato Restaurant Collections in a City. The location/City input can be provided in the following ways
 - Using Zomato City ID
 - Using coordinates of any location within a city
 - List of all restaurants listed in any particular Zomato Collection can be obtained using the '/search' API with Collection ID and Zomato City ID as the input


def getCuisines(self, city_id, **kwargs):

params = {"<STR_LIT>": city_id}<EOL>optional_params = ["<STR_LIT>", "<STR_LIT>"]<EOL>for key in optional_params:<EOL><INDENT>if key in kwargs:<EOL><INDENT>params[key] = kwargs[key]<EOL><DEDENT><DEDENT>cuisines = self.api.get("<STR_LIT>", params)<EOL>return cuisines<EOL>

:param city_id: id of the city for which collections are needed
:param lat: latitude
:param lon: longitude
Get a list of all cuisines of restaurants listed in a city.
The location/city input can be provided in the following ways
  - Using Zomato City ID
  - Using coordinates of any location within a city
List of all restaurants serving a particular cuisine can be obtained using
'/search' API with cuisine ID and location details


def getEstablishments(self, city_id, **kwargs):

params = {"<STR_LIT>": city_id}<EOL>optional_params = ["<STR_LIT>", "<STR_LIT>"]<EOL>for key in optional_params:<EOL><INDENT>if key in kwargs:<EOL><INDENT>params[key] = kwargs[key]<EOL><DEDENT><DEDENT>establishments = self.api.get("<STR_LIT>", params)<EOL>return establishments<EOL>

:param city_id: id of the city for which collections are needed
:param lat: latitude
:param lon: longitude
Get a list of restaurant types in a city. The location/City input can be provided in the following ways
- Using Zomato City ID
- Using coordinates of any location within a city
List of all restaurants categorized under a particular restaurant type can obtained using
/Search API with Establishment ID and location details as inputs


params = {"<STR_LIT>": lat, "<STR_LIT>": lon}<EOL>response = self.api.get("<STR_LIT>", params)<EOL>return response<EOL>

:param lat: latitude
:param lon: longitude
Get Foodie and Nightlife Index, list of popular cuisines and nearby restaurants around the given coordinates


def getLocationDetails(self, entity_id, entity_type):

params = {"<STR_LIT>": entity_id, "<STR_LIT>": entity_type}<EOL>location_details = self.api.get("<STR_LIT>", params)<EOL>return location_details<EOL>

:param entity_id: location id obtained from locations api
:param entity_type: location type obtained from locations api
:return:
Get Foodie Index, Nightlife Index, Top Cuisines and Best rated restaurants in a given location


def getLocations(self, query, **kwargs):

params = {"<STR_LIT>": query}<EOL>optional_params = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT:count>"]<EOL>for key in optional_params:<EOL><INDENT>if key in kwargs:<EOL><INDENT>params[key] = kwargs[key]<EOL><DEDENT><DEDENT>locations = self.api.get("<STR_LIT>", params)<EOL>return locations<EOL>

:param query: suggestion for location name
:param lat: latitude
:param lon: longitude
:param count: number of max results to display
:return: json response
Search for Zomato locations by keyword. Provide coordinates to get better search results


params = {"<STR_LIT>": restaurant_id}<EOL>daily_menu = self.api.get("<STR_LIT>", params)<EOL>return daily_menu<EOL>

:param restaurant_id: id of restaurant whose details are requested
:return: json response
Get daily menu using Zomato restaurant ID.


params = {"<STR_LIT>": restaurant_id}<EOL>restaurant_details = self.api.get("<STR_LIT>", params)<EOL>return restaurant_details<EOL>

:param restaurant_id: id of restaurant whose details are requested
:return: json response
Get detailed restaurant information using Zomato restaurant ID.
Partner Access is required to access photos and reviews.


def getRestaurantReviews(self, restaurant_id, **kwargs):

params = {"<STR_LIT>": restaurant_id}<EOL>optional_params = ["<STR_LIT:start>", "<STR_LIT:count>"]<EOL>for key in optional_params:<EOL><INDENT>if key in kwargs:<EOL><INDENT>params[key] = kwargs[key]<EOL><DEDENT><DEDENT>reviews = self.api.get("<STR_LIT>", params)<EOL>return reviews<EOL>

:param restaurant_id: id of restaurant whose details are requested
:param start: fetch results after this offset
:param count: max number of results to retrieve
:return: json response
Get restaurant reviews using the Zomato restaurant ID


params = {}<EOL>available_params = [<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT:q>", "<STR_LIT:start>",<EOL>"<STR_LIT:count>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>for key in available_params:<EOL><INDENT>if key in kwargs:<EOL><INDENT>params[key] = kwargs[key]<EOL><DEDENT><DEDENT>results = self.api.get("<STR_LIT>", params)<EOL>return results<EOL>

:param entity_id: location id
:param entity_type: location type (city, subzone, zone, lanmark, metro , group)
:param q: search keyword
:param start: fetch results after offset
:param count: max number of results to display
:param lat: latitude
:param lon: longitude
:param radius: radius around (lat,lon); to define search area, defined in meters(M)
:param cuisines: list of cuisine id's separated by comma
:param establishment_type: estblishment id obtained from establishments call
:param collection_id: collection id obtained from collections call
:param category: category ids obtained from categories call
:param sort: sort restaurants by (cost, rating, real_distance)
:param order: used with 'sort' parameter to define ascending / descending
:return: json response
The location input can be specified using Zomato location ID or coordinates. Cuisine / Establishment /
Collection IDs can be obtained from respective api calls.

Partner Access is required to access photos and reviews.

Examples:
- To search for 'Italian' restaurants in 'Manhattan, New York City',
set cuisines = 55, entity_id = 94741 and entity_type = zone
- To search for 'cafes' in 'Manhattan, New York City',
set establishment_type = 1, entity_type = zone and entity_id = 94741
- Get list of all restaurants in 'Trending this Week' collection in 'New York City' by using
entity_id = 280, entity_type = city and collection_id = 1


def within_margin(given, expected, margin=<NUM_LIT>):

return expected - margin <= given <= expected + margin<EOL>

Returns True if the given value is within +/- the margin of the
expected value.


comp = {<EOL>'<STR_LIT:A>': '<STR_LIT:T>',<EOL>'<STR_LIT:T>': '<STR_LIT:A>',<EOL>'<STR_LIT>': '<STR_LIT:C>',<EOL>'<STR_LIT:C>': '<STR_LIT>'<EOL>}<EOL>return seq == '<STR_LIT>'.join([comp[i] for i in seq][::-<NUM_LIT:1>])<EOL>

Returns True if s is symmetric (same as rev. complement)


def temp(s, DNA_c=<NUM_LIT>, Na_c=<NUM_LIT>, Mg_c=<NUM_LIT>, dNTPs_c=<NUM_LIT>, uncorrected=False):

R = <NUM_LIT>    <EOL>s = s.upper()<EOL>dh, ds = _tercorr(s)<EOL>k = DNA_c * <NUM_LIT><EOL>dh_coeffs = {"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>}<EOL>ds_coeffs = {"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>,<EOL>"<STR_LIT>": -<NUM_LIT>, "<STR_LIT>": -<NUM_LIT>}<EOL>dh = dh +sum(_overcount(s, pair) * coeff for pair, coeff in dh_coeffs.items())<EOL>ds = ds +sum(_overcount(s, pair) * coeff for pair, coeff in ds_coeffs.items())<EOL>fgc = len([filter(lambda x: x == '<STR_LIT>' or x == '<STR_LIT:C>', s)]) / float(len(s))<EOL>tm = (<NUM_LIT:1000> * dh) / (ds + (R * log(k)))<EOL>if uncorrected:<EOL><INDENT>return tm - <NUM_LIT><EOL><DEDENT>MNa = Na_c * <NUM_LIT><EOL>MMg = Mg_c * <NUM_LIT><EOL>MdNTPs = dNTPs_c * <NUM_LIT><EOL>Ka = <NUM_LIT>  <EOL>D = (Ka * MdNTPs - Ka * MMg + <NUM_LIT:1>)**<NUM_LIT:2> + (<NUM_LIT:4> * Ka * MMg)<EOL>Fmg = (-(Ka * MdNTPs - Ka * MMg + <NUM_LIT:1>) + sqrt(D)) / (<NUM_LIT:2> * Ka)<EOL>cation_ratio = sqrt(Fmg) / MNa if MNa > <NUM_LIT:0> else <NUM_LIT><EOL>if cation_ratio < <NUM_LIT>:<EOL><INDENT>tm = <NUM_LIT:1> / (<EOL>(<NUM_LIT:1> / tm) +<EOL>((<NUM_LIT> * fgc - <NUM_LIT>) * log(MNa) + <NUM_LIT> * log(MNa)**<NUM_LIT:2>) * <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>a = <NUM_LIT><EOL>d = <NUM_LIT><EOL>g = <NUM_LIT><EOL>Fmg = MMg<EOL>if cation_ratio < <NUM_LIT>:<EOL><INDENT>a = a * (<NUM_LIT> - <NUM_LIT> * sqrt(MNa) * log(MNa))<EOL>d = d *(<NUM_LIT> - <NUM_LIT> * log(MNa) * <NUM_LIT> - <NUM_LIT> * log(MNa)**<NUM_LIT:2> * <NUM_LIT>)<EOL>g = g * (<NUM_LIT> - <NUM_LIT> * log(MNa) + <NUM_LIT> * log(MNa)**<NUM_LIT:3> * <NUM_LIT>)<EOL><DEDENT>tm = <NUM_LIT:1> / (<EOL>(<NUM_LIT:1> / tm) +<EOL>(a - <NUM_LIT> * log(Fmg) + fgc * (<NUM_LIT> + d * log(Fmg)) +<EOL><NUM_LIT:1> / (<NUM_LIT:2> * (len(s) - <NUM_LIT:1>)) * (-<NUM_LIT> + <NUM_LIT> * log(Fmg) +<EOL>g * log(Fmg)**<NUM_LIT:2>)) * <NUM_LIT>)<EOL><DEDENT>return tm - <NUM_LIT><EOL>

Returns the DNA/DNA melting temp using nearest-neighbor thermodynamics.

This function returns better results than EMBOSS DAN because it uses updated
thermodynamics values and takes into account initialization parameters from
the work of SantaLucia (1998).

Corrects for mono- and divalent cation concentrations.

Arguments:
- DNA_c:   DNA concentration [nM]
- Na_c:    Na+ concentration [mM]
- Mg_c:    Mg2+ concentration [mM]
- dNTPs_c: dNTP concentration [mM]
- correction: correct for cation concentration?


summary = read_file('<STR_LIT>')<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + "<STR_LIT>",<EOL>body=summary,<EOL>status=<NUM_LIT:200>)<EOL>if empty:<EOL><INDENT>page_empty = read_file('<STR_LIT>')<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=page_empty,<EOL>status=<NUM_LIT:200>)<EOL><DEDENT>else:<EOL><INDENT>page_1 = read_file('<STR_LIT>')<EOL>page_2 = read_file('<STR_LIT>')<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=page_2,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=page_1,<EOL>status=<NUM_LIT:200>)<EOL>crate_1 = read_file('<STR_LIT>')<EOL>crate_2 = read_file('<STR_LIT>')<EOL>crate_3 = read_file('<STR_LIT>')<EOL>crate_4 = read_file('<STR_LIT>')<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_1,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_2,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_3,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_4,<EOL>status=<NUM_LIT:200>)<EOL>crate_user_1 = read_file('<STR_LIT>')<EOL>crate_user_2 = read_file('<STR_LIT>')<EOL>crate_user_3 = read_file('<STR_LIT>')<EOL>crate_user_4 = read_file('<STR_LIT>')<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_user_1,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_user_2,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_user_3,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_user_4,<EOL>status=<NUM_LIT:200>)<EOL>crate_team_1 = read_file('<STR_LIT>')<EOL>crate_team_2 = read_file('<STR_LIT>')<EOL>crate_team_3 = read_file('<STR_LIT>')<EOL>crate_team_4 = read_file('<STR_LIT>')<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_team_1,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_team_2,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_team_3,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_team_4,<EOL>status=<NUM_LIT:200>)<EOL>crate_version_downloads_1 = read_file('<STR_LIT>')<EOL>crate_version_downloads_2 = read_file('<STR_LIT>')<EOL>crate_version_downloads_3 = read_file('<STR_LIT>')<EOL>crate_version_downloads_4 = read_file('<STR_LIT>')<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_version_downloads_1,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_version_downloads_2,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_version_downloads_3,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_version_downloads_4,<EOL>status=<NUM_LIT:200>)<EOL>crate_versions_1 = read_file('<STR_LIT>')<EOL>crate_versions_2 = read_file('<STR_LIT>')<EOL>crate_versions_3 = read_file('<STR_LIT>')<EOL>crate_versions_4 = read_file('<STR_LIT>')<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_versions_1,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_versions_2,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_versions_3,<EOL>status=<NUM_LIT:200>)<EOL>httpretty.register_uri(httpretty.GET,<EOL>CRATES_API_URL + '<STR_LIT>',<EOL>body=crate_versions_4,<EOL>status=<NUM_LIT:200>)<EOL><DEDENT>


mozilla_questions_1 = read_file('<STR_LIT>')<EOL>mozilla_questions_2 = read_file('<STR_LIT>')<EOL>mozilla_questions_empty = read_file('<STR_LIT>')<EOL>mozilla_question_answers_1 = read_file('<STR_LIT>')<EOL>mozilla_question_answers_empty = read_file('<STR_LIT>')<EOL>if empty:<EOL><INDENT>mozilla_questions_1 = mozilla_questions_empty<EOL><DEDENT>def request_callback(method, uri, headers):<EOL><INDENT>page = uri.split("<STR_LIT>")[<NUM_LIT:1>].split("<STR_LIT:&>")[<NUM_LIT:0>]<EOL>if page == "<STR_LIT:1>":<EOL><INDENT>if '<STR_LIT>' in uri:<EOL><INDENT>body = mozilla_questions_1<EOL><DEDENT>else:<EOL><INDENT>question = uri.split("<STR_LIT>")[<NUM_LIT:1>].split("<STR_LIT:&>")[<NUM_LIT:0>]<EOL>body = mozilla_question_answers_1<EOL>body_json = json.loads(body)['<STR_LIT>']<EOL>if body_json[<NUM_LIT:0>]['<STR_LIT>'] != int(question):<EOL><INDENT>body = mozilla_question_answers_empty<EOL><DEDENT><DEDENT><DEDENT>elif page == "<STR_LIT:2>":<EOL><INDENT>if '<STR_LIT>' in uri:<EOL><INDENT>body = mozilla_questions_2<EOL><DEDENT>else:<EOL><INDENT>body = mozilla_question_answers_1<EOL><DEDENT><DEDENT>elif page == str(KITSUNE_SERVER_FAIL_PAGE):<EOL><INDENT>return (<NUM_LIT>, headers, '<STR_LIT>')<EOL><DEDENT>elif page == str(KITSUNE_SERVER_FAIL_PAGE + <NUM_LIT:1>):<EOL><INDENT>return (<NUM_LIT:200>, headers, mozilla_questions_2)<EOL><DEDENT>else:<EOL><INDENT>return (<NUM_LIT>, headers, '<STR_LIT>')<EOL><DEDENT>HTTPServer.requests_http.append(httpretty.last_request())<EOL>return (<NUM_LIT:200>, headers, body)<EOL><DEDENT>httpretty.register_uri(httpretty.GET,<EOL>KITSUNE_API_QUESTION,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL>httpretty.register_uri(httpretty.GET,<EOL>KITSUNE_API_ANSWER,<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL>

Configure in http the routes to be served


mozilla_bodies = {}  <EOL>for category in MOZILLA_REPS_CATEGORIES:<EOL><INDENT>mozilla_bodies[category] = {}<EOL>mozilla_bodies[category]['<STR_LIT:1>'] = read_file('<STR_LIT>' + category + '<STR_LIT>')<EOL>mozilla_bodies[category]['<STR_LIT:2>'] = read_file('<STR_LIT>' + category + '<STR_LIT>')<EOL>mozilla_bodies[category]['<STR_LIT>'] = read_file('<STR_LIT>' + category + '<STR_LIT>')<EOL><DEDENT>if empty:<EOL><INDENT>for category in MOZILLA_REPS_CATEGORIES:<EOL><INDENT>mozilla_bodies[category]['<STR_LIT:1>'] = read_file('<STR_LIT>' + category + '<STR_LIT>')<EOL><DEDENT><DEDENT>def request_callback(method, uri, headers):<EOL><INDENT>body = '<STR_LIT>'<EOL>if '<STR_LIT>' in uri:<EOL><INDENT>page = uri.split("<STR_LIT>")[<NUM_LIT:1>].split("<STR_LIT:&>")[<NUM_LIT:0>]<EOL>for category in MOZILLA_REPS_CATEGORIES:<EOL><INDENT>if category in uri:<EOL><INDENT>body = mozilla_bodies[category][page]<EOL>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for category in MOZILLA_REPS_CATEGORIES:<EOL><INDENT>if category in uri:<EOL><INDENT>body = mozilla_bodies[category]['<STR_LIT>']<EOL>break<EOL><DEDENT><DEDENT><DEDENT>HTTPServer.requests_http.append(httpretty.last_request())<EOL>return (<NUM_LIT:200>, headers, body)<EOL><DEDENT>httpretty.register_uri(httpretty.GET,<EOL>re.compile(MOZILLA_REPS_API + "<STR_LIT>"),<EOL>responses=[<EOL>httpretty.Response(body=request_callback)<EOL>])<EOL>


kwargs = {}<EOL>items = super().fetch(category, **kwargs)<EOL>return items<EOL>

Fetch events from the MozillaClub URL.

        The method retrieves, from a MozillaClub URL, the
        events. The data is a Google spreadsheet retrieved using
        the feed API REST.

        :param category: the category of items to fetch

        :returns: a generator of events


def fetch_items(self, category, **kwargs):

logger.info("<STR_LIT>", self.url)<EOL>nevents = <NUM_LIT:0>  <EOL>raw_cells = self.client.get_cells()<EOL>parser = MozillaClubParser(raw_cells)<EOL>for event in parser.parse():<EOL><INDENT>yield event<EOL>nevents += <NUM_LIT:1><EOL><DEDENT>logger.info("<STR_LIT>", nevents)<EOL>

Fetch events

        :param category: the category of items to fetch
        :param kwargs: backend arguments

        :returns: a generator of items


return True<EOL>

Returns whether it supports archiving items on the fetch process.

        :returns: this backend supports items archive


return False<EOL>

Returns whether it supports to resume the fetch process.

        :returns: this backend supports items resuming


return str(item['<STR_LIT>'] + "<STR_LIT:_>" + item['<STR_LIT>'])<EOL>

Extracts the identifier from an event item.


return CATEGORY_EVENT<EOL>

Extracts the category from a item.

        This backend only generates one type of item which is
        'event'.


date = str_to_datetime(item['<STR_LIT>'])<EOL>return float(date.timestamp())<EOL>

Extracts the update time from a MozillaClub item.

        The timestamp is extracted from 'updated' field.
        This date is in ISO format and it needs to be converted to
        a float value.

        :param item: item generated by the backend

        :returns: a UNIX timestamp


return MozillaClubClient(self.url, self.archive, from_archive)<EOL>


logger.info("<STR_LIT>")<EOL>logger.debug("<STR_LIT>", self.base_url)<EOL>raw_cells = self.fetch(self.base_url)<EOL>return raw_cells.text<EOL>

Retrieve all cells from the spreadsheet.


nevents_wrong = <NUM_LIT:0><EOL>feed_json = json.loads(self.feed)<EOL>if '<STR_LIT>' not in feed_json['<STR_LIT>']:<EOL><INDENT>return<EOL><DEDENT>self.cells = feed_json['<STR_LIT>']['<STR_LIT>']<EOL>self.ncell = <NUM_LIT:0><EOL>event_fields = self.__get_event_fields()<EOL>while self.ncell < len(self.cells):<EOL><INDENT>event = self.__get_next_event(event_fields)<EOL>if event['<STR_LIT>'] is None or event['<STR_LIT>'] is None:<EOL><INDENT>logger.warning("<STR_LIT>", event)<EOL>nevents_wrong += <NUM_LIT:1><EOL>continue<EOL><DEDENT>yield event<EOL><DEDENT>logger.info("<STR_LIT>", nevents_wrong)<EOL>

Parse the MozillaClub spreadsheet feed cells json.


event_fields = {}<EOL>while self.ncell < len(self.cells):<EOL><INDENT>cell = self.cells[self.ncell]<EOL>row = cell['<STR_LIT>']['<STR_LIT>']<EOL>if int(row) > <NUM_LIT:1>:<EOL><INDENT>break<EOL><DEDENT>ncol = int(cell['<STR_LIT>']['<STR_LIT>'])<EOL>name = cell['<STR_LIT:content>']['<STR_LIT>']<EOL>event_fields[ncol] = name<EOL>if ncol in EVENT_TEMPLATE:<EOL><INDENT>if event_fields[ncol] != EVENT_TEMPLATE[ncol]:<EOL><INDENT>logger.warning("<STR_LIT>",<EOL>name, EVENT_TEMPLATE[ncol])<EOL><DEDENT><DEDENT>else:<EOL><INDENT>logger.warning("<STR_LIT>", name)<EOL><DEDENT>self.ncell += <NUM_LIT:1><EOL><DEDENT>return event_fields<EOL>

Get the events fields (columns) from the cells received.


parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,<EOL>archive=True)<EOL>parser.parser.add_argument('<STR_LIT:url>', nargs='<STR_LIT:?>',<EOL>default=MOZILLA_CLUB_URL,<EOL>help="<STR_LIT>")<EOL>return parser<EOL>

Returns the MozillaClub argument parser.


def fetch(self, category=CATEGORY_EVENT, offset=REMO_DEFAULT_OFFSET):

if not offset:<EOL><INDENT>offset = REMO_DEFAULT_OFFSET<EOL><DEDENT>kwargs = {"<STR_LIT>": offset}<EOL>items = super().fetch(category, **kwargs)<EOL>return items<EOL>

Fetch items from the ReMo url.

        The method retrieves, from a ReMo URL, the set of items
        of the given `category`.

        :param category: the category of items to fetch
        :param offset: obtain items after offset
        :returns: a generator of items


offset = kwargs['<STR_LIT>']<EOL>logger.info("<STR_LIT>",<EOL>self.url, category, offset)<EOL>nitems = <NUM_LIT:0>  <EOL>titems = <NUM_LIT:0>  <EOL>page = int(offset / ReMoClient.ITEMS_PER_PAGE)<EOL>page_offset = page * ReMoClient.ITEMS_PER_PAGE<EOL>drop_items = offset - page_offset<EOL>logger.debug("<STR_LIT>",<EOL>drop_items, offset, page, page_offset)<EOL>current_offset = offset<EOL>for raw_items in self.client.get_items(category, offset):<EOL><INDENT>items_data = json.loads(raw_items)<EOL>titems = items_data['<STR_LIT:count>']<EOL>logger.info("<STR_LIT>",<EOL>titems - current_offset, current_offset)<EOL>items = items_data['<STR_LIT>']<EOL>for item in items:<EOL><INDENT>if drop_items > <NUM_LIT:0>:<EOL><INDENT>drop_items -= <NUM_LIT:1><EOL>continue<EOL><DEDENT>raw_item_details = self.client.fetch(item['<STR_LIT>'])<EOL>item_details = json.loads(raw_item_details)<EOL>item_details['<STR_LIT>'] = current_offset<EOL>current_offset += <NUM_LIT:1><EOL>yield item_details<EOL>nitems += <NUM_LIT:1><EOL><DEDENT><DEDENT>logger.info("<STR_LIT>", nitems, titems, offset)<EOL>

Fetch items

        :param category: the category of items to fetch
        :param kwargs: backend arguments

        :returns: a generator of items


def metadata(self, item, filter_classified=False):

item = super().metadata(item, filter_classified=filter_classified)<EOL>item['<STR_LIT>'] = item['<STR_LIT:data>'].pop('<STR_LIT>')<EOL>return item<EOL>

ReMo metadata.

        This method takes items overrides `metadata` method to add extra
        information related to Remo (offset of the item).

        :param item: an item fetched by a backend
        :param filter_classified: sets if classified fields were filtered


return True<EOL>


return str(item['<STR_LIT>'])<EOL>

Extracts the identifier from a ReMo item.


if '<STR_LIT:end>' in item:<EOL><INDENT>updated = item['<STR_LIT:end>']<EOL><DEDENT>elif '<STR_LIT>' in item:<EOL><INDENT>updated = item['<STR_LIT>']<EOL><DEDENT>elif '<STR_LIT>' in item:<EOL><INDENT>updated = item['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" + str(item))<EOL><DEDENT>return float(str_to_datetime(updated).timestamp())<EOL>

Extracts the update time from a ReMo item.

        The timestamp is extracted from 'end' field.
        This date is converted to a perceval format using a float value.

        :param item: item generated by the backend

        :returns: a UNIX timestamp


if '<STR_LIT>' in item:<EOL><INDENT>category = CATEGORY_EVENT<EOL><DEDENT>elif '<STR_LIT>' in item:<EOL><INDENT>category = CATEGORY_ACTIVITY<EOL><DEDENT>elif '<STR_LIT>' in item:<EOL><INDENT>category = CATEGORY_USER<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>" + str(item))<EOL><DEDENT>return category<EOL>

Extracts the category from a ReMo item.

        This backend generates items types 'event', 'activity'
        or 'user'. To guess the type of item, the code will look
        for unique fields.


return ReMoClient(self.url, self.archive, from_archive)<EOL>


def get_items(self, category=CATEGORY_EVENT, offset=REMO_DEFAULT_OFFSET):

more = True  <EOL>next_uri = None  <EOL>page = ReMoClient.FIRST_PAGE<EOL>page += int(offset / ReMoClient.ITEMS_PER_PAGE)<EOL>if category == CATEGORY_EVENT:<EOL><INDENT>api = self.api_events_url<EOL><DEDENT>elif category == CATEGORY_ACTIVITY:<EOL><INDENT>api = self.api_activities_url<EOL><DEDENT>elif category == CATEGORY_USER:<EOL><INDENT>api = self.api_users_url<EOL><DEDENT>else:<EOL><INDENT>raise ValueError(category + '<STR_LIT>')<EOL><DEDENT>while more:<EOL><INDENT>params = {<EOL>"<STR_LIT>": page,<EOL>"<STR_LIT>": "<STR_LIT>"<EOL>}<EOL>logger.debug("<STR_LIT>",<EOL>api, str(params))<EOL>raw_items = self.fetch(api, payload=params)<EOL>yield raw_items<EOL>items_data = json.loads(raw_items)<EOL>next_uri = items_data['<STR_LIT>']<EOL>if not next_uri:<EOL><INDENT>more = False<EOL><DEDENT>else:<EOL><INDENT>parsed_uri = urllib.parse.urlparse(next_uri)<EOL>parsed_params = urllib.parse.parse_qs(parsed_uri.query)<EOL>page = parsed_params['<STR_LIT>'][<NUM_LIT:0>]<EOL><DEDENT><DEDENT>

Retrieve all items for category using pagination


response = super().fetch(url, payload)<EOL>return response.text<EOL>

Return the textual content associated to the Response object


parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,<EOL>offset=True,<EOL>archive=True)<EOL>parser.parser.add_argument('<STR_LIT:url>', nargs='<STR_LIT:?>',<EOL>default="<STR_LIT>",<EOL>help="<STR_LIT>")<EOL>return parser<EOL>


def fetch(self, category=CATEGORY_CRATES, from_date=DEFAULT_DATETIME):

if not from_date:<EOL><INDENT>from_date = DEFAULT_DATETIME<EOL><DEDENT>from_date = datetime_to_utc(from_date)<EOL>kwargs = {"<STR_LIT>": from_date}<EOL>items = super().fetch(category, **kwargs)<EOL>return items<EOL>

Fetch package data.

        The method retrieves packages and summary from Crates.io.

        :param category: the category of items to fetch
        :param from_date: obtain packages updated since this date

        :returns: a summary and crate items


from_date = kwargs['<STR_LIT>']<EOL>if category == CATEGORY_CRATES:<EOL><INDENT>return self.__fetch_crates(from_date)<EOL><DEDENT>else:<EOL><INDENT>return self.__fetch_summary()<EOL><DEDENT>

Fetch packages and summary from Crates.io

        :param category: the category of items to fetch
        :param kwargs: backend arguments

        :returns: a generator of items


return True<EOL>

Returns whether it supports archiving items on the fetch process.

        :returns: this backend supports items archive


return False<EOL>

Returns whether it supports to resume the fetch process.

        :returns: this backend supports items resuming


if Crates.metadata_category(item) == CATEGORY_CRATES:<EOL><INDENT>return str(item['<STR_LIT:id>'])<EOL><DEDENT>else:<EOL><INDENT>ts = item['<STR_LIT>']<EOL>ts = str_to_datetime(ts)<EOL>return str(ts.timestamp())<EOL><DEDENT>

Extracts the identifier from an item depending on its type.


if Crates.metadata_category(item) == CATEGORY_CRATES:<EOL><INDENT>ts = item['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>ts = item['<STR_LIT>']<EOL><DEDENT>ts = str_to_datetime(ts)<EOL>return ts.timestamp()<EOL>

Extracts the update time from an item.

        Depending on the item, the timestamp is extracted from the
        'updated_at' or 'fetched_on' fields.
        This date is converted to UNIX timestamp format.

        :param item: item generated by the backend

        :returns: a UNIX timestamp


if '<STR_LIT>' in item:<EOL><INDENT>return CATEGORY_SUMMARY<EOL><DEDENT>else:<EOL><INDENT>return CATEGORY_CRATES<EOL><DEDENT>

Extracts the category from an item.

        This backend generates two types of item: 'summary' and 'crate'.


return CratesClient(self.sleep_time, self.archive, from_archive)<EOL>


raw_summary = self.client.summary()<EOL>summary = json.loads(raw_summary)<EOL>summary['<STR_LIT>'] = str(datetime_utcnow())<EOL>yield summary<EOL>


from_date = datetime_to_utc(from_date)<EOL>crates_groups = self.client.crates()<EOL>for raw_crates in crates_groups:<EOL><INDENT>crates = json.loads(raw_crates)<EOL>for crate_container in crates['<STR_LIT>']:<EOL><INDENT>if str_to_datetime(crate_container['<STR_LIT>']) < from_date:<EOL><INDENT>continue<EOL><DEDENT>crate_id = crate_container['<STR_LIT:id>']<EOL>crate = self.__fetch_crate_data(crate_id)<EOL>crate['<STR_LIT>'] = self.__fetch_crate_owner_team(crate_id)<EOL>crate['<STR_LIT>'] = self.__fetch_crate_owner_user(crate_id)<EOL>crate['<STR_LIT>'] = self.__fetch_crate_version_downloads(crate_id)<EOL>crate['<STR_LIT>'] = self.__fetch_crate_versions(crate_id)<EOL>yield crate<EOL><DEDENT><DEDENT>


raw_owner_team = self.client.crate_attribute(crate_id, '<STR_LIT>')<EOL>owner_team = json.loads(raw_owner_team)<EOL>return owner_team<EOL>


raw_owner_user = self.client.crate_attribute(crate_id, '<STR_LIT>')<EOL>owner_user = json.loads(raw_owner_user)<EOL>return owner_user<EOL>


raw_versions = self.client.crate_attribute(crate_id, "<STR_LIT>")<EOL>version_downloads = json.loads(raw_versions)<EOL>return version_downloads<EOL>


raw_version_downloads = self.client.crate_attribute(crate_id, "<STR_LIT>")<EOL>version_downloads = json.loads(raw_version_downloads)<EOL>return version_downloads<EOL>


raw_crate = self.client.crate(crate_id)<EOL>crate = json.loads(raw_crate)<EOL>return crate['<STR_LIT>']<EOL>


path = urijoin(CRATES_API_URL, CATEGORY_SUMMARY)<EOL>raw_content = self.fetch(path)<EOL>return raw_content<EOL>


path = urijoin(CRATES_API_URL, CATEGORY_CRATES)<EOL>raw_crates = self.__fetch_items(path, from_page)<EOL>return raw_crates<EOL>


path = urijoin(CRATES_API_URL, CATEGORY_CRATES, crate_id)<EOL>raw_crate = self.fetch(path)<EOL>return raw_crate<EOL>


def crate_attribute(self, crate_id, attribute):

path = urijoin(CRATES_API_URL, CATEGORY_CRATES, crate_id, attribute)<EOL>raw_attribute_data = self.fetch(path)<EOL>return raw_attribute_data<EOL>


def __fetch_items(self, path, page=<NUM_LIT:1>):

fetch_data = True<EOL>parsed_crates = <NUM_LIT:0><EOL>total_crates = <NUM_LIT:0><EOL>while fetch_data:<EOL><INDENT>logger.debug("<STR_LIT>", page)<EOL>try:<EOL><INDENT>payload = {'<STR_LIT>': '<STR_LIT>', '<STR_LIT>': page}<EOL>raw_content = self.fetch(path, payload=payload)<EOL>content = json.loads(raw_content)<EOL>parsed_crates += len(content['<STR_LIT>'])<EOL>if not total_crates:<EOL><INDENT>total_crates = content['<STR_LIT>']['<STR_LIT>']<EOL><DEDENT><DEDENT>except requests.exceptions.HTTPError as e:<EOL><INDENT>logger.error("<STR_LIT>", e.response.text)<EOL>raise e<EOL><DEDENT>yield raw_content<EOL>page += <NUM_LIT:1><EOL>if parsed_crates >= total_crates:<EOL><INDENT>fetch_data = False<EOL><DEDENT><DEDENT>

Return the items from Crates.io API using pagination


response = super().fetch(url, payload=payload)<EOL>return response.text<EOL>


parser = BackendCommandArgumentParser(cls.BACKEND.CATEGORIES,<EOL>from_date=True,<EOL>archive=True,<EOL>token_auth=True)<EOL>group = parser.parser.add_argument_group('<STR_LIT>')<EOL>group.add_argument('<STR_LIT>', dest='<STR_LIT>',<EOL>default=SLEEP_TIME, type=int,<EOL>help="<STR_LIT>")<EOL>return parser<EOL>