def append_default(self, new_default_name: str) -> None:

stripped_default_name = new_default_name.strip(WS)<EOL>if stripped_default_name == self.name.strip(WS):<EOL><INDENT>return<EOL><DEDENT>dig = True<EOL>innermost_param = self<EOL>while dig:<EOL><INDENT>dig = False<EOL>default = innermost_param.default<EOL>for p in innermost_param.parameters:<EOL><INDENT>if p.string == default:<EOL><INDENT>if stripped_default_name == p.name.strip(WS):<EOL><INDENT>return<EOL><DEDENT>innermost_param = p<EOL>dig = True<EOL><DEDENT><DEDENT><DEDENT>innermost_default = innermost_param.default<EOL>if innermost_default is None:<EOL><INDENT>innermost_param.insert(-<NUM_LIT:3>, '<STR_LIT>' + new_default_name + '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>name = innermost_param.name<EOL>innermost_param[<EOL>len('<STR_LIT>' + name + '<STR_LIT:|>'):<EOL>len('<STR_LIT>' + name + '<STR_LIT:|>' + innermost_default)<EOL>] = '<STR_LIT>' + new_default_name + '<STR_LIT:|>' + innermost_default + '<STR_LIT>'<EOL><DEDENT>

Append a new default parameter in the appropriate place.

        Add the new default to the innter-most parameter.
        If the parameter already exists among defaults, don't change anything.

        Example:
            >>> p = Parameter('{{{p1|{{{p2|}}}}}}')
            >>> p.append_default('p3')
            >>> p
            Parameter("'{{{p1|{{{p2|{{{p3|}}}}}}}}}'")


@text.setter<EOL><INDENT>def text(self, newtext: str) -> None:<DEDENT>

string = self.string<EOL>if string[<NUM_LIT:0>] == '<STR_LIT:[>':<EOL><INDENT>text = self.text<EOL>if text:<EOL><INDENT>self[-len(text) - <NUM_LIT:1>:-<NUM_LIT:1>] = newtext<EOL>return<EOL><DEDENT>self.insert(-<NUM_LIT:1>, '<STR_LIT:U+0020>' + newtext)<EOL>return<EOL><DEDENT>self.insert(len(string), '<STR_LIT:U+0020>' + newtext + '<STR_LIT:]>')<EOL>self.insert(<NUM_LIT:0>, '<STR_LIT:[>')<EOL>

Set a new text.

        Automatically put the ExternalLink in brackets if it's not already.


@property<EOL><INDENT>def in_brackets(self) -> bool:<DEDENT>

return self[<NUM_LIT:0>] == '<STR_LIT:[>'<EOL>

Return true if the ExternalLink is in brackets. False otherwise.


@property<EOL><INDENT>def url(self) -> str:<DEDENT>

if self[<NUM_LIT:0>] == '<STR_LIT:[>':<EOL><INDENT>return self[<NUM_LIT:1>:URL_MATCH(self._ext_link_shadow, <NUM_LIT:1>).end()]<EOL><DEDENT>return self.string<EOL>


@contents.setter<EOL><INDENT>def contents(self, value: str) -> None:<DEDENT>

level = self.level<EOL>if level == <NUM_LIT:0>:<EOL><INDENT>self[:] = value<EOL>return<EOL><DEDENT>contents = self.contents<EOL>start = level + len(self.title) + level + <NUM_LIT:1><EOL>self[start:start + len(contents)] = value<EOL>

Set value as the contents of this section.


@property<EOL><INDENT>def title(self) -> str:<DEDENT>

level = self.level<EOL>if level == <NUM_LIT:0>:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return self._atomic_partition(<NUM_LIT:10>)[<NUM_LIT:0>].rstrip(WS)[level:-level]<EOL>

Return title of this section. Return '' for lead sections.


@level.setter<EOL><INDENT>def level(self, value: int) -> None:<DEDENT>

old_level = self.level<EOL>title = self.title<EOL>new_equals = '<STR_LIT:=>' * value<EOL>self[<NUM_LIT:0>:old_level + len(title) + old_level] =new_equals + title + new_equals<EOL>


@property<EOL><INDENT>def level(self) -> int:<DEDENT>

m = HEADER_MATCH(self._shadow)<EOL>if m:<EOL><INDENT>return len(m.group(<NUM_LIT:1>))<EOL><DEDENT>return <NUM_LIT:0><EOL>

Return level of this section.

        Level is in range(1,7) or 0 for the lead section.


def _lstrip_increase(shadow: bytearray, pos: int) -> int:

length = len(shadow)<EOL>while pos < length and shadow[pos:pos + <NUM_LIT:1>].isspace():<EOL><INDENT>pos += <NUM_LIT:1><EOL><DEDENT>return pos<EOL>

Return the new position to lstrip the shadow.


@property<EOL><INDENT>def arguments(self) -> List[Argument]:<DEDENT>

shadow = self._shadow<EOL>split_spans = self._args_matcher(shadow).spans('<STR_LIT>')<EOL>if not split_spans:<EOL><INDENT>return []<EOL><DEDENT>arguments = []<EOL>arguments_append = arguments.append<EOL>type_to_spans = self._type_to_spans<EOL>ss, se = span = self._span<EOL>type_ = id(span)<EOL>lststr = self._lststr<EOL>string = lststr[<NUM_LIT:0>]<EOL>arg_spans = type_to_spans.setdefault(type_, [])<EOL>span_tuple_to_span_get = {(s[<NUM_LIT:0>], s[<NUM_LIT:1>]): s for s in arg_spans}.get<EOL>for arg_self_start, arg_self_end in split_spans:<EOL><INDENT>s, e = arg_span = [ss + arg_self_start, ss + arg_self_end]<EOL>old_span = span_tuple_to_span_get((s, e))<EOL>if old_span is None:<EOL><INDENT>insort(arg_spans, arg_span)<EOL><DEDENT>else:<EOL><INDENT>arg_span = old_span<EOL><DEDENT>arg = Argument(lststr, type_to_spans, arg_span, type_)<EOL>arg._shadow_cache = (<EOL>string[s:e], shadow[arg_self_start:arg_self_end])<EOL>arguments_append(arg)<EOL><DEDENT>return arguments<EOL>

Parse template content. Create self.name and self.arguments.


def __delitem__(self, key: Union[slice, int]) -> None:

start, stop = self._check_index(key)<EOL>lststr = self._lststr<EOL>lststr0 = lststr[<NUM_LIT:0>]<EOL>lststr[<NUM_LIT:0>] = lststr0[:start] + lststr0[stop:]<EOL>self._shrink_update(start, stop)<EOL>

Remove the specified range or character from self.string.

        Note: If an operation involves both insertion and deletion, it'll be
        safer to use the `insert` function first. Otherwise there is a
        possibility of insertion into the wrong spans.


def __init__(<EOL>self,<EOL>string: Union[MutableSequence[str], str],<EOL>_type_to_spans: Dict[str, List[List[int]]] = None,<EOL>) -> None:

if _type_to_spans is not None:<EOL><INDENT>self._type_to_spans = _type_to_spans<EOL>self._lststr = string  <EOL>return<EOL><DEDENT>self._lststr = [string]<EOL>span = self._span = [<NUM_LIT:0>, len(string)]<EOL>byte_array = bytearray(string, '<STR_LIT:ascii>', '<STR_LIT:replace>')<EOL>_type = self._type<EOL>if _type not in SPAN_PARSER_TYPES:<EOL><INDENT>type_to_spans = self._type_to_spans = parse_to_spans(byte_array)<EOL>type_to_spans[_type] = [span]<EOL>self._shadow_cache = string, byte_array<EOL><DEDENT>else:<EOL><INDENT>head = byte_array[:<NUM_LIT:2>]<EOL>tail = byte_array[-<NUM_LIT:2>:]<EOL>byte_array[-<NUM_LIT:2>:] = byte_array[:<NUM_LIT:2>] = b'<STR_LIT>'<EOL>type_to_spans = parse_to_spans(byte_array)<EOL>self._shadow_cache = string, byte_array<EOL>type_to_spans[_type].insert(<NUM_LIT:0>, span)<EOL>self._type_to_spans = type_to_spans<EOL>byte_array[:<NUM_LIT:2>] = head<EOL>byte_array[-<NUM_LIT:2>:] = tail<EOL><DEDENT>

Initialize the object.

        Set the initial values for self._lststr, self._type_to_spans.

        :param string: The string to be parsed or a list containing the string
            of the parent object.
        :param _type_to_spans: If the lststr is already parsed, pass its
            _type_to_spans property as _type_to_spans to avoid parsing it
            again.


@property<EOL><INDENT>def tables(self) -> List['<STR_LIT>']:<DEDENT>

tables = []  <EOL>tables_append = tables.append<EOL>type_to_spans = self._type_to_spans<EOL>lststr = self._lststr<EOL>shadow = self._shadow[:]<EOL>ss, se = self._span<EOL>spans = type_to_spans.setdefault('<STR_LIT>', [])<EOL>if not spans:<EOL><INDENT>m = True  <EOL>while m:<EOL><INDENT>m = False<EOL>for m in TABLE_FINDITER(shadow):<EOL><INDENT>ms, me = m.span()<EOL>span = [ss + ms + len(m[<NUM_LIT:1>]), ss + me]<EOL>spans.append(span)<EOL>tables_append(Table(lststr, type_to_spans, span, '<STR_LIT>'))<EOL>shadow[ms:me] = b'<STR_LIT:_>' * (me - ms)<EOL><DEDENT><DEDENT>return tables<EOL><DEDENT>span_tuple_to_span_get = {(s[<NUM_LIT:0>], s[<NUM_LIT:1>]): s for s in spans}.get<EOL>m = True<EOL>while m:<EOL><INDENT>m = False<EOL>for m in TABLE_FINDITER(shadow):<EOL><INDENT>ms, me = m.span()<EOL>s, e = ss + ms + len(m[<NUM_LIT:1>]), ss + me<EOL>old_span = span_tuple_to_span_get((s, e))<EOL>if old_span is None:<EOL><INDENT>span = [s, e]<EOL>insort(spans, span)<EOL><DEDENT>else:<EOL><INDENT>span = old_span<EOL><DEDENT>tables_append(Table(lststr, type_to_spans, span, '<STR_LIT>'))<EOL>shadow[ms:me] = b'<STR_LIT:_>' * (me - ms)<EOL><DEDENT><DEDENT>return tables<EOL>


def __contains__(self, value: Union[str, '<STR_LIT>']) -> bool:

<EOL>if isinstance(value, str):<EOL><INDENT>return value in self.string<EOL><DEDENT>if self._lststr is not value._lststr:<EOL><INDENT>return False<EOL><DEDENT>ps, pe = value._span<EOL>ss, se = self._span<EOL>if ss <= ps and se >= pe:<EOL><INDENT>return True<EOL><DEDENT>return False<EOL>

Return True if parsed_wikitext is inside self. False otherwise.

        Also self and parsed_wikitext should belong to the same parsed
        wikitext object for this function to return True.


@staticmethod<EOL><INDENT>def parent(type_: Optional[str] = None) -> None:<DEDENT>

return None<EOL>

Return None (The parent of the root node is None).


@property<EOL><INDENT>def sections(self) -> List['<STR_LIT>']:<DEDENT>

sections = []  <EOL>sections_append = sections.append<EOL>type_to_spans = self._type_to_spans<EOL>lststr = self._lststr<EOL>ss, se = _span = self._span<EOL>type_spans = type_to_spans.setdefault('<STR_LIT>', [])<EOL>full_match = SECTIONS_FULLMATCH(self._shadow)<EOL>section_spans = full_match.spans('<STR_LIT>')<EOL>levels = [len(eq) for eq in full_match.captures('<STR_LIT>')]<EOL>if not type_spans:<EOL><INDENT>spans_append = type_spans.append<EOL>for current_index, (current_level, (s, e)) in enumerate(<EOL>zip(levels, section_spans), <NUM_LIT:1><EOL>):<EOL><INDENT>for section_index, section_level in enumerate(<EOL>levels[current_index:], current_index<EOL>):<EOL><INDENT>if current_level and section_level > current_level:<EOL><INDENT>e = section_spans[section_index][<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>span = [ss + s, ss + e]<EOL>spans_append(span)<EOL>sections_append(<EOL>Section(lststr, type_to_spans, span, '<STR_LIT>'))<EOL><DEDENT>return sections<EOL><DEDENT>span_tuple_to_span = {(s[<NUM_LIT:0>], s[<NUM_LIT:1>]): s for s in type_spans}.get<EOL>for current_index, (current_level, (s, e)) in enumerate(<EOL>zip(levels, section_spans), <NUM_LIT:1><EOL>):<EOL><INDENT>for section_index, section_level in enumerate(<EOL>levels[current_index:], current_index<EOL>):<EOL><INDENT>if current_level and section_level > current_level:<EOL><INDENT>e = section_spans[section_index][<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>s, e = ss + s, ss + e<EOL>old_span = span_tuple_to_span((s, e))<EOL>if old_span is None:<EOL><INDENT>span = [s, e]<EOL>insort(type_spans, span)<EOL><DEDENT>else:<EOL><INDENT>span = old_span<EOL><DEDENT>sections_append(Section(lststr, type_to_spans, span, '<STR_LIT>'))<EOL><DEDENT>return sections<EOL>

Return a list of section in current wikitext.

        The first section will always be the lead section, even if it is an
        empty string.


def _subspans(self, _type: str) -> Generator[int, None, None]:

ss, se = self._span<EOL>spans = self._type_to_spans[_type]<EOL>b = bisect(spans, [ss])<EOL>for span in spans[b:bisect(spans, [se], b)]:<EOL><INDENT>if span[<NUM_LIT:1>] <= se:<EOL><INDENT>yield span<EOL><DEDENT><DEDENT>

Yield all the sub-span indices excluding self._span.


return '<STR_LIT>'.format(type(self).__name__, repr(self.string))<EOL>

Return the string representation of self.


return self.string<EOL>


def _subspans(self, type_: str) -> List[List[int]]:

return self._type_to_spans[type_]<EOL>

Return all the sub-span including self._span.


def pprint(self, indent: str = '<STR_LIT:U+0020>', remove_comments=False):

warn(<EOL>'<STR_LIT>',<EOL>DeprecationWarning,<EOL>)<EOL>return self.pformat(indent, remove_comments)<EOL>


def _shrink_update(self, rmstart: int, rmstop: int) -> None:

<EOL>for spans in self._type_to_spans.values():<EOL><INDENT>i = len(spans) - <NUM_LIT:1><EOL>while i >= <NUM_LIT:0>:<EOL><INDENT>s, e = span = spans[i]<EOL>if rmstop <= s:<EOL><INDENT>rmlength = rmstop - rmstart<EOL>span[:] = s - rmlength, e - rmlength<EOL>i -= <NUM_LIT:1><EOL>continue<EOL><DEDENT>break<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT>while True:<EOL><INDENT>if rmstart <= s:<EOL><INDENT>if rmstop < e:<EOL><INDENT>span[:] = rmstart, e + rmstart - rmstop<EOL>i -= <NUM_LIT:1><EOL>if i < <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>s, e = span = spans[i]<EOL>continue<EOL><DEDENT>spans.pop(i)[:] = -<NUM_LIT:1>, -<NUM_LIT:1><EOL>i -= <NUM_LIT:1><EOL>if i < <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>s, e = span = spans[i]<EOL>continue<EOL><DEDENT>break<EOL><DEDENT>while i >= <NUM_LIT:0>:<EOL><INDENT>if e <= rmstart:<EOL><INDENT>i -= <NUM_LIT:1><EOL>if i < <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>s, e = span = spans[i]<EOL>continue<EOL><DEDENT>span[<NUM_LIT:1>] -= rmstop - rmstart<EOL>i -= <NUM_LIT:1><EOL>if i < <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>s, e = span = spans[i]<EOL>continue<EOL><DEDENT><DEDENT>

Update self._type_to_spans according to the removed span.

        Warning: If an operation involves both _shrink_update and
        _insert_update, you might wanna consider doing the
        _insert_update before the _shrink_update as this function
        can cause data loss in self._type_to_spans.


@string.deleter<EOL><INDENT>def string(self) -> None:<DEDENT>

del self[:]<EOL>

Set a new string for this object. Note the old data will be lost.


@contents.setter<EOL><INDENT>def contents(self, contents: str) -> None:<DEDENT>

match = self._match<EOL>start, end = match.span('<STR_LIT>')<EOL>if start != -<NUM_LIT:1>:<EOL><INDENT>self[start:end] = contents<EOL><DEDENT>else:<EOL><INDENT>s, e = match.span('<STR_LIT>')<EOL>self[s:e] = '<STR_LIT>'.format(contents, match['<STR_LIT:name>'].decode())<EOL><DEDENT>

Set new contents.

        Note that if the tag is self-closing, then it will be expanded to
        have a start tag and an end tag. For example:
        >>> t = Tag('<t/>')
        >>> t.contents = 'n'
        >>> t.string
        '<t>n</t>'


@property<EOL><INDENT>def _match(self) -> Any:<DEDENT>

cached_match, cached_string = self._match_cache<EOL>string = self.string<EOL>if cached_string == string:<EOL><INDENT>return cached_match<EOL><DEDENT>match = TAG_FULLMATCH(self._shadow)<EOL>self._match_cache = match, string<EOL>return match<EOL>

Return the match object for the current tag. Cache the result.


@property<EOL><INDENT>def name(self) -> str:<DEDENT>

return self._match['<STR_LIT:name>'].decode()<EOL>


@property<EOL><INDENT>def items(self) -> List[str]:<DEDENT>

items = []  <EOL>append = items.append<EOL>string = self.string<EOL>match = self._match<EOL>ms = match.start()<EOL>for s, e in match.spans('<STR_LIT>'):<EOL><INDENT>append(string[s - ms:e - ms])<EOL><DEDENT>return items<EOL>

Return items as a list of strings.

        Don't include sub-items and the start pattern.


@classmethod<EOL><INDENT>def readonly(cls, *args, **kwargs):<DEDENT>

fridge = cls(*args, **kwargs)<EOL>fridge.close()<EOL>return fridge<EOL>

Return an already closed read-only instance of Fridge.
Arguments are the same as for the constructor.


a = bl.Waterfall(voyager_h5)<EOL>b = bl.Waterfall(voyager_fil)<EOL>print("<STR_LIT>")<EOL>assert a.beam_axis == b.beam_axis<EOL>assert a.freq_axis == b.freq_axis<EOL>assert a.time_axis == b.time_axis<EOL>assert a.calc_n_coarse_chan() == b.calc_n_coarse_chan()<EOL>assert a.file_shape == b.file_shape<EOL>assert a.n_channels_in_file == b.n_channels_in_file<EOL>assert a.n_ints_in_file == b.n_ints_in_file<EOL>assert a.selection_shape == b.selection_shape<EOL>print("<STR_LIT>")<EOL>a.populate_freqs()<EOL>a.populate_timestamps()<EOL>a.info()<EOL>a.blank_dc(<NUM_LIT:1>)<EOL>a.calibrate_band_pass_N1()<EOL>b.populate_freqs()<EOL>b.populate_timestamps()<EOL>b.info()<EOL>b.blank_dc(<NUM_LIT:1>)<EOL>b.calibrate_band_pass_N1()<EOL>dir_a = dir(a)<EOL>dir_b = dir(b)<EOL>print("<STR_LIT>")<EOL>for item in dir_a:<EOL><INDENT>if item not in dir_b:<EOL><INDENT>print(item)<EOL><DEDENT><DEDENT>print("<STR_LIT>")<EOL>for item in dir_b:<EOL><INDENT>if item not in dir_a:<EOL><INDENT>print(item)<EOL><DEDENT><DEDENT>


<EOL>filfile=open(filename,'<STR_LIT:rb>')<EOL>filfile.seek(<NUM_LIT:0>)<EOL>round1 = filfile.read(<NUM_LIT:1000>)<EOL>headersize = round1.find('<STR_LIT>')+len('<STR_LIT>')<EOL>return headersize<EOL>

Script to find the header size of a filterbank file


def write_polfils(str, str_I, **kwargs):

lin,circ=fracpols(str, **kwargs)<EOL>obs = Waterfall(str_I, max_load=<NUM_LIT>)<EOL>obs.data = lin<EOL>obs.write_to_fil(str[:-<NUM_LIT:15>]+'<STR_LIT>')   <EOL>obs.data = circ<EOL>obs.write_to_fil(str[:-<NUM_LIT:15>]+'<STR_LIT>')<EOL>

Writes two new filterbank files containing fractional linear and
    circular polarization data


<EOL>num_coarse = data.size/chan_per_coarse<EOL>data_shaped = np.array(np.reshape(data,(num_coarse,chan_per_coarse)))<EOL>return np.mean(data_shaped[:,<NUM_LIT:2>:-<NUM_LIT:1>],axis=<NUM_LIT:1>)<EOL>

Converts a data array with length n_chans to an array of length n_coarse_chans
by averaging over the coarse channels


I,Q,U,V,L=get_stokes(str, **kwargs)<EOL>return L/I,V/I<EOL>

Output fractional linear and circular polarizations for a
    rawspec cross polarization .fil file. NOT STANDARD USE


plt.figure("<STR_LIT>", figsize=(<NUM_LIT:12>,<NUM_LIT:9>))<EOL>left, width = <NUM_LIT>,<NUM_LIT><EOL>bottom, height = <NUM_LIT>,<NUM_LIT:0.5><EOL>width2 = <NUM_LIT><EOL>bottom2, height2 = <NUM_LIT>,<NUM_LIT><EOL>rect_uncal = [left,bottom,width,height]<EOL>rect_cal = [left+width+<NUM_LIT>,bottom,width,height]<EOL>rect_fold = [left,bottom2,width2,<NUM_LIT>]<EOL>rect_gain1 = [left+width2+<NUM_LIT:0.1>,bottom2,width2,height2]<EOL>rect_phase1 = [left+width2*<NUM_LIT:2>+<NUM_LIT:0.1>*<NUM_LIT:2>,bottom2,width2,height2]<EOL>rect_gain2 = [left+width2+<NUM_LIT:0.1>,bottom2+height2+<NUM_LIT>,width2,height2]<EOL>rect_phase2 = [left+width2*<NUM_LIT:2>+<NUM_LIT:0.1>*<NUM_LIT:2>,bottom2+height2+<NUM_LIT>,width2,height2]<EOL>axFold = plt.axes(rect_fold)<EOL>print('<STR_LIT>')<EOL>plot_diode_fold(dio_cross,bothfeeds=False,feedtype=feedtype,min_samp=<NUM_LIT>,max_samp=<NUM_LIT>,legend=False,**kwargs)<EOL>print('<STR_LIT>')<EOL>plot_gain_offsets(dio_cross,feedtype=feedtype,ax1=rect_gain2,ax2=rect_gain1,legend=False,**kwargs)<EOL>print('<STR_LIT>')<EOL>plot_phase_offsets(dio_cross,feedtype=feedtype,ax1=rect_phase1,ax2=rect_phase2,legend=False,**kwargs)<EOL>plt.ylabel('<STR_LIT>')<EOL>ax_uncal = plt.axes(rect_uncal)<EOL>print('<STR_LIT>')<EOL>plot_Stokes_diode(dio_cross,feedtype=feedtype,**kwargs)<EOL>ax_cal = plt.axes(rect_cal,sharey=ax_uncal)<EOL>print('<STR_LIT>')<EOL>plot_calibrated_diode(dio_cross,feedtype=feedtype,**kwargs)<EOL>plt.ylabel('<STR_LIT>')<EOL>plt.setp(ax_cal.get_yticklabels(),visible=False)<EOL>plt.savefig(dio_cross[:-<NUM_LIT:4>]+'<STR_LIT>',dpi=<NUM_LIT>)<EOL>plt.show()<EOL>

Generates and shows five plots: Uncalibrated diode, calibrated diode, fold information,
phase offsets, and gain offsets for a noise diode measurement. Most useful diagnostic plot to
make sure calibration proceeds correctly.


<EOL>obs = Waterfall(dio_cross,max_load=<NUM_LIT>)<EOL>freqs = obs.populate_freqs()<EOL>tsamp = obs.header['<STR_LIT>']<EOL>data = obs.data<EOL>obs = None<EOL>I,Q,U,V = get_stokes(data,feedtype)<EOL>data = None<EOL>psis = phase_offsets(I,Q,U,V,tsamp,chan_per_coarse,feedtype,**kwargs)<EOL>G = gain_offsets(I,Q,U,V,tsamp,chan_per_coarse,feedtype,**kwargs)<EOL>I,Q,U,V = apply_Mueller(I,Q,U,V,G,psis,chan_per_coarse,feedtype)<EOL>I_OFF,I_ON = foldcal(I,tsamp,**kwargs)<EOL>Q_OFF,Q_ON = foldcal(Q,tsamp,**kwargs)<EOL>U_OFF,U_ON = foldcal(U,tsamp,**kwargs)<EOL>V_OFF,V_ON = foldcal(V,tsamp,**kwargs)<EOL>I = None<EOL>Q = None<EOL>U = None<EOL>V = None<EOL>plt.plot(freqs,I_ON-I_OFF,'<STR_LIT>',label='<STR_LIT:I>')<EOL>plt.plot(freqs,Q_ON-Q_OFF,'<STR_LIT>',label='<STR_LIT>')<EOL>plt.plot(freqs,U_ON-U_OFF,'<STR_LIT>',label='<STR_LIT>')<EOL>plt.plot(freqs,V_ON-V_OFF,'<STR_LIT>',label='<STR_LIT>')<EOL>plt.legend()<EOL>plt.xlabel('<STR_LIT>')<EOL>plt.title('<STR_LIT>')<EOL>plt.ylabel('<STR_LIT>')<EOL>

Plots the corrected noise diode spectrum for a given noise diode measurement
after application of the inverse Mueller matrix for the electronics chain.


<EOL>obs = Waterfall(dio_cross,max_load=<NUM_LIT>)<EOL>freqs = obs.populate_freqs()<EOL>tsamp = obs.header['<STR_LIT>']<EOL>data = obs.data<EOL>obs = None<EOL>I,Q,U,V = get_stokes(data,feedtype)<EOL>I_OFF,I_ON = foldcal(I,tsamp,**kwargs)<EOL>Q_OFF,Q_ON = foldcal(Q,tsamp,**kwargs)<EOL>U_OFF,U_ON = foldcal(U,tsamp,**kwargs)<EOL>V_OFF,V_ON = foldcal(V,tsamp,**kwargs)<EOL>Idiff = I_ON-I_OFF<EOL>Qdiff = Q_ON-Q_OFF<EOL>Udiff = U_ON-U_OFF<EOL>Vdiff = V_ON-V_OFF<EOL>return Idiff,Qdiff,Udiff,Vdiff,freqs<EOL>

Returns ON-OFF for all Stokes parameters given a cross_pols noise diode measurement


start_idx = self.file_obj.tell()<EOL>key, val = '<STR_LIT>', '<STR_LIT>'<EOL>header_dict = {}<EOL>keep_reading = True<EOL>first_line = self.file_obj<EOL>try:<EOL><INDENT>while keep_reading:<EOL><INDENT>if start_idx + <NUM_LIT> > self.filesize:<EOL><INDENT>keep_reading = False<EOL>raise EndOfFileError("<STR_LIT>")<EOL><DEDENT>line = self.file_obj.read(<NUM_LIT>)<EOL>if PYTHON3:<EOL><INDENT>line = line.decode("<STR_LIT:utf-8>")<EOL><DEDENT>if line.startswith('<STR_LIT>'):<EOL><INDENT>keep_reading = False<EOL>break<EOL><DEDENT>else:<EOL><INDENT>key, val = line.split('<STR_LIT:=>')<EOL>key, val = key.strip(), val.strip()<EOL>if "<STR_LIT:'>" in val:<EOL><INDENT>val = str(val.strip("<STR_LIT:'>").strip())<EOL><DEDENT>elif "<STR_LIT:.>" in val:<EOL><INDENT>val = float(val)<EOL><DEDENT>else:<EOL><INDENT>val = int(val)<EOL><DEDENT><DEDENT>header_dict[key] = val<EOL><DEDENT><DEDENT>except ValueError:<EOL><INDENT>print("<STR_LIT>", line)<EOL>print("<STR_LIT>", start_idx)<EOL>print("<STR_LIT>", self.filesize)<EOL>print("<STR_LIT>")<EOL>print(self.file_obj.read(<NUM_LIT>))<EOL>raise<EOL><DEDENT>data_idx = self.file_obj.tell()<EOL>if "<STR_LIT>" in header_dict.keys():<EOL><INDENT>if int(header_dict["<STR_LIT>"]) == <NUM_LIT:1>:<EOL><INDENT>if data_idx % <NUM_LIT>:<EOL><INDENT>data_idx += (<NUM_LIT> - data_idx % <NUM_LIT>)<EOL><DEDENT><DEDENT><DEDENT>self.file_obj.seek(start_idx)<EOL>return header_dict, data_idx<EOL>

Read next header (multiple headers in file)

        Returns:
            (header, data_idx) - a dictionary of keyword:value header data and
            also the byte index of where the corresponding data block resides.


def generate_filterbank_header(self, nchans=<NUM_LIT:1>, ):

gp_head = self.read_first_header()<EOL>fb_head = {}<EOL>telescope_str = gp_head.get("<STR_LIT>", "<STR_LIT>")<EOL>if telescope_str in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>fb_head["<STR_LIT>"] = <NUM_LIT:6><EOL><DEDENT>elif telescope_str in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>fb_head["<STR_LIT>"] = <NUM_LIT:7><EOL><DEDENT>else:<EOL><INDENT>fb_head["<STR_LIT>"] = <NUM_LIT:0><EOL><DEDENT>fb_head["<STR_LIT>"] = gp_head.get("<STR_LIT>", "<STR_LIT>")<EOL>fb_head["<STR_LIT>"] = gp_head.get("<STR_LIT>", <NUM_LIT:0>)<EOL>fb_head["<STR_LIT>"] = gp_head.get("<STR_LIT>", <NUM_LIT:0>)<EOL>fb_head["<STR_LIT>"] = Angle(str(gp_head.get("<STR_LIT>", <NUM_LIT:0.0>)) + "<STR_LIT>")<EOL>fb_head["<STR_LIT>"] = Angle(str(gp_head.get("<STR_LIT>", <NUM_LIT:0.0>)) + "<STR_LIT>")<EOL>fb_head["<STR_LIT>"] = self.filename<EOL>fb_head["<STR_LIT>"] = <NUM_LIT:20><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:1>  <EOL>fb_head["<STR_LIT>"] = <NUM_LIT:0><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:0><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:32><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:0.0><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:1.0><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:0.0><EOL>fb_head["<STR_LIT>"] = <NUM_LIT> / nchans<EOL>fb_head["<STR_LIT>"] = nchans<EOL>fb_head["<STR_LIT>"] = <NUM_LIT:1><EOL>fb_head["<STR_LIT>"] = <NUM_LIT:1><EOL>return fb_head<EOL>


self.file_obj.seek(<NUM_LIT:0>)<EOL>header_dict, pos = self.read_header()<EOL>self.file_obj.seek(<NUM_LIT:0>)<EOL>return header_dict<EOL>

Read first header in file

        Returns:
            header (dict): keyword:value pairs of header metadata


def __exit__(self, exception_type, exception_value, traceback):

closes the file after `with` block has exited
:param exception_type:
:param exception_value:
:param traceback:
:return:


def plot_spectrum(self, filename=None, plot_db=True):

header, data = self.read_next_data_block()<EOL>print("<STR_LIT>")<EOL>d_xx_fft = np.abs(np.fft.fft(data[..., <NUM_LIT:0>]))<EOL>d_xx_fft = d_xx_fft.flatten()<EOL>dec_fac_x = <NUM_LIT:1><EOL>if d_xx_fft.shape[<NUM_LIT:0>] > MAX_PLT_POINTS:<EOL><INDENT>dec_fac_x = d_xx_fft.shape[<NUM_LIT:0>] / MAX_PLT_POINTS<EOL><DEDENT>d_xx_fft = rebin(d_xx_fft, dec_fac_x)<EOL>print("<STR_LIT>")<EOL>if plot_db:<EOL><INDENT>plt.plot(<NUM_LIT:10> * np.log10(d_xx_fft))<EOL>plt.ylabel("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>plt.plot(d_xx_fft)<EOL>plt.ylabel("<STR_LIT>")<EOL>plt.xlabel("<STR_LIT>")<EOL><DEDENT>plt.title(self.filename)<EOL>if filename:<EOL><INDENT>plt.savefig(filename)<EOL><DEDENT>plt.show()<EOL>

Do a (slow) numpy FFT and take power of data


<EOL>if self.selection_shape[self.freq_axis] > chunk_dim[self.freq_axis]*MAX_BLOB_MB:<EOL><INDENT>freq_axis_size = self.selection_shape[self.freq_axis]<EOL><INDENT>while freq_axis_size > chunk_dim[self.freq_axis]*MAX_BLOB_MB:<EOL><INDENT>freq_axis_size /= <NUM_LIT:2><EOL><DEDENT><DEDENT>time_axis_size = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>freq_axis_size = self.selection_shape[self.freq_axis]<EOL>time_axis_size = np.min([chunk_dim[self.time_axis] * MAX_BLOB_MB * chunk_dim[self.freq_axis] / freq_axis_size, self.selection_shape[self.time_axis]])<EOL><DEDENT>blob_dim = (int(time_axis_size), <NUM_LIT:1>, freq_axis_size)<EOL>return blob_dim<EOL>

Sets the blob dimmentions, trying to read around 1024 MiB at a time.
            This is assuming a chunk is about 1 MiB.


<EOL>if np.abs(self.header[b'<STR_LIT>']) < <NUM_LIT>:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>chunk_dim = (<NUM_LIT:1>,<NUM_LIT:1>,<NUM_LIT>) <EOL>return chunk_dim<EOL><DEDENT>elif np.abs(self.header[b'<STR_LIT>']) < <NUM_LIT>:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>chunk_dim = (<NUM_LIT>,<NUM_LIT:1>,<NUM_LIT>) <EOL>return chunk_dim<EOL><DEDENT>elif np.abs(self.header[b'<STR_LIT>']) < <NUM_LIT> and np.abs(self.header[b'<STR_LIT>'])  >= <NUM_LIT>:<EOL><INDENT>logger.info('<STR_LIT>')<EOL>chunk_dim = (<NUM_LIT:10>,<NUM_LIT:1>,<NUM_LIT>)  <EOL><INDENT>chunk_dim = (<NUM_LIT:1>,<NUM_LIT:1>,<NUM_LIT>/<NUM_LIT:4>)<EOL><DEDENT>return chunk_dim<EOL><DEDENT>else:<EOL><INDENT>logger.warning('<STR_LIT>')<EOL>chunk_dim = (<NUM_LIT:1>,<NUM_LIT:1>,<NUM_LIT>)<EOL>return chunk_dim<EOL><DEDENT>

Sets the chunking dimmentions depending on the file type.


def __write_to_fil_heavy(self, filename_out, *args, **kwargs):

<EOL>chunk_dim = self.__get_chunk_dimensions()<EOL>blob_dim = self.__get_blob_dimensions(chunk_dim)<EOL>n_blobs = self.container.calc_n_blobs(blob_dim)<EOL>n_bytes  = self.header[b'<STR_LIT>'] / <NUM_LIT:8><EOL>with open(filename_out, "<STR_LIT:wb>") as fileh:<EOL><INDENT>fileh.write(generate_sigproc_header(self)) <EOL><DEDENT>logger.info('<STR_LIT>'% n_blobs)<EOL>for ii in range(<NUM_LIT:0>, n_blobs):<EOL><INDENT>logger.info('<STR_LIT>' % (ii + <NUM_LIT:1>, n_blobs))<EOL>bob = self.container.read_blob(blob_dim,n_blob=ii)<EOL>with open(filename_out, "<STR_LIT:a>") as fileh:<EOL><INDENT>j = bob<EOL>if n_bytes == <NUM_LIT:4>:<EOL><INDENT>np.float32(j.ravel()).tofile(fileh)<EOL><DEDENT>elif n_bytes == <NUM_LIT:2>:<EOL><INDENT>np.int16(j.ravel()).tofile(fileh)<EOL><DEDENT>elif n_bytes == <NUM_LIT:1>:<EOL><INDENT>np.int8(j.ravel()).tofile(fileh)<EOL><DEDENT><DEDENT><DEDENT>

Write data to .fil file.

        Args:
            filename_out (str): Name of output file


n_coarse_chan = self.container.calc_n_coarse_chan(chan_bw)<EOL>return n_coarse_chan<EOL>

This makes an attempt to calculate the number of coarse channels in a given freq selection.
            It assumes for now that a single coarse channel is 2.9296875 MHz


def __write_to_hdf5_light(self, filename_out, *args, **kwargs):

block_size = <NUM_LIT:0><EOL>with h5py.File(filename_out, '<STR_LIT:w>') as h5:<EOL><INDENT>h5.attrs[b'<STR_LIT>']   = b'<STR_LIT>'<EOL>h5.attrs[b'<STR_LIT>'] = b'<STR_LIT:1.0>'<EOL>if HAS_BITSHUFFLE:<EOL><INDENT>bs_compression = bitshuffle.h5.H5FILTER<EOL>bs_compression_opts = (block_size, bitshuffle.h5.H5_COMPRESS_LZ4)<EOL><DEDENT>else:<EOL><INDENT>bs_compression = None<EOL>bs_compression_opts = None<EOL>logger.warning("<STR_LIT>")<EOL><DEDENT>dset = h5.create_dataset('<STR_LIT:data>',<EOL>data=self.data,<EOL>compression='<STR_LIT>')<EOL><INDENT>compression=bs_compression,<EOL>compression_opts=bs_compression_opts)<EOL>dset_mask = h5.create_dataset('<STR_LIT>',<EOL>shape=self.file_shape,<EOL><INDENT>compression='<STR_LIT>',<EOL><DEDENT>compression=bs_compression,<EOL>compression_opts=bs_compression_opts,<EOL>dtype='<STR_LIT>')<EOL>dset.dims[<NUM_LIT:0>].label = b"<STR_LIT>"<EOL>dset.dims[<NUM_LIT:1>].label = b"<STR_LIT>"<EOL>dset.dims[<NUM_LIT:2>].label = b"<STR_LIT:time>"<EOL>dset_mask.dims[<NUM_LIT:0>].label = b"<STR_LIT>"<EOL>dset_mask.dims[<NUM_LIT:1>].label = b"<STR_LIT>"<EOL>dset_mask.dims[<NUM_LIT:2>].label = b"<STR_LIT:time>"<EOL>for key, value in self.header.items():<EOL>dset.attrs[key] = value<EOL>

Write data to HDF5 file in one go.

        Args:
            filename_out (str): Name of output file


def grab_data(self, f_start=None, f_stop=None,t_start=None, t_stop=None, if_id=<NUM_LIT:0>):

self.freqs = self.populate_freqs()<EOL>self.timestamps = self.populate_timestamps()<EOL>if f_start is None:<EOL><INDENT>f_start = self.freqs[<NUM_LIT:0>]<EOL><DEDENT>if f_stop is None:<EOL><INDENT>f_stop = self.freqs[-<NUM_LIT:1>]<EOL><DEDENT>i0 = np.argmin(np.abs(self.freqs - f_start))<EOL>i1 = np.argmin(np.abs(self.freqs - f_stop))<EOL>if i0 < i1:<EOL><INDENT>plot_f    = self.freqs[i0:i1 + <NUM_LIT:1>]<EOL>plot_data = np.squeeze(self.data[t_start:t_stop, ..., i0:i1 + <NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>plot_f    = self.freqs[i1:i0 + <NUM_LIT:1>]<EOL>plot_data = np.squeeze(self.data[t_start:t_stop, ..., i1:i0 + <NUM_LIT:1>])<EOL><DEDENT>return plot_f, plot_data<EOL>

Extract a portion of data by frequency range.

        Args:
            f_start (float): start frequency in MHz
            f_stop (float): stop frequency in MHz
            if_id (int): IF input identification (req. when multiple IFs in file)

        Returns:
            (freqs, data) (np.arrays): frequency axis in MHz and data subset


<EOL>ii_start, ii_stop = <NUM_LIT:0>, self.n_ints_in_file<EOL>if self.t_start:<EOL><INDENT>ii_start = self.t_start<EOL><DEDENT>if self.t_stop:<EOL><INDENT>ii_stop = self.t_stop<EOL><DEDENT>t0 = self.header[b'<STR_LIT>']<EOL>t_delt = self.header[b'<STR_LIT>']<EOL>if update_header:<EOL><INDENT>timestamps = ii_start * t_delt / <NUM_LIT>/<NUM_LIT>/<NUM_LIT> + t0<EOL><DEDENT>else:<EOL><INDENT>timestamps = np.arange(ii_start, ii_stop) * t_delt / <NUM_LIT>/<NUM_LIT>/<NUM_LIT> + t0<EOL><DEDENT>return timestamps<EOL>

Populate time axis.
            IF update_header then only return tstart


<EOL>self._setup_chans()<EOL>blob_time_start = self.t_start<EOL>blob_freq_start = self.chan_start_idx<EOL>blob_start = blob_time_start * self.n_channels_in_file + blob_freq_start<EOL>return blob_start<EOL>


def _setup_selection_range(self, f_start=None, f_stop=None, t_start=None, t_stop=None, init=False):

<EOL>if init is True:<EOL><INDENT>if t_start is None:<EOL><INDENT>t_start = self.t_begin<EOL><DEDENT>if t_stop is None:<EOL><INDENT>t_stop = self.t_end<EOL><DEDENT>if f_start is None:<EOL><INDENT>f_start = self.f_begin<EOL><DEDENT>if f_stop is None:<EOL><INDENT>f_stop = self.f_end<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if f_start is None:<EOL><INDENT>f_start = self.f_start<EOL><DEDENT>if f_stop is None:<EOL><INDENT>f_stop = self.f_stop<EOL><DEDENT>if t_start is None:<EOL><INDENT>t_start = self.t_start<EOL><DEDENT>if t_stop is None:<EOL><INDENT>t_stop = self.t_stop<EOL><DEDENT><DEDENT>if t_stop >= <NUM_LIT:0> and t_start >= <NUM_LIT:0> and t_stop < t_start:<EOL><INDENT>t_stop, t_start = t_start,t_stop<EOL>logger.warning('<STR_LIT>')<EOL><DEDENT>if f_stop and f_start and f_stop < f_start:<EOL><INDENT>f_stop, f_start = f_start,f_stop<EOL>logger.warning('<STR_LIT>')<EOL><DEDENT>if t_start >= self.t_begin and t_start < self.t_end:<EOL><INDENT>self.t_start = int(t_start)<EOL><DEDENT>else:<EOL><INDENT>if init is False or t_start != None:<EOL><INDENT>logger.warning('<STR_LIT>'%self.t_begin)<EOL><DEDENT>self.t_start = self.t_begin<EOL><DEDENT>if t_stop <= self.t_end  and t_stop > self.t_begin:<EOL><INDENT>self.t_stop = int(t_stop)<EOL><DEDENT>else:<EOL><INDENT>if init is False or t_stop:<EOL><INDENT>logger.warning('<STR_LIT>'%self.t_end)<EOL><DEDENT>self.t_stop = self.t_end<EOL><DEDENT>if f_start >= self.f_begin and f_start < self.f_end:<EOL><INDENT>self.f_start = f_start<EOL><DEDENT>else:<EOL><INDENT>if init is False or f_start:<EOL><INDENT>logger.warning('<STR_LIT>'%self.f_begin)<EOL><DEDENT>self.f_start = self.f_begin<EOL><DEDENT>if f_stop <= self.f_end and f_stop > self.f_begin:<EOL><INDENT>self.f_stop = f_stop<EOL><DEDENT>else:<EOL><INDENT>if init is False or f_stop:<EOL><INDENT>logger.warning('<STR_LIT>'%self.f_end)<EOL><DEDENT>self.f_stop = self.f_end<EOL><DEDENT>self.selection_shape = self._calc_selection_shape()<EOL>

Making sure the selection if time and frequency are within the file limits.

        Args:
            init (bool): If call during __init__


self.n_ints_in_file = sigproc.calc_n_ints_in_file(self.filename)<EOL>

Calculate the number of integrations in the file.


from argparse import ArgumentParser<EOL>if not HAS_BITSHUFFLE:<EOL><INDENT>print("<STR_LIT>")<EOL>exit()<EOL><DEDENT>parser = ArgumentParser(description="<STR_LIT>")<EOL>parser.add_argument('<STR_LIT:filename>', type=str, help='<STR_LIT>')<EOL>args = parser.parse_args()<EOL>fileroot = args.filename.split('<STR_LIT>')[<NUM_LIT:0>]<EOL>filelist = glob.glob(fileroot + '<STR_LIT>')<EOL>filelist = sorted(filelist)<EOL>r = GuppiRaw(filelist[<NUM_LIT:0>])<EOL>header, data = r.read_next_data_block()<EOL>dshape = data.shape <EOL>print(dshape)<EOL>n_blocks_total = <NUM_LIT:0><EOL>for filename in filelist:<EOL><INDENT>print(filename)<EOL>r = GuppiRaw(filename)<EOL>n_blocks_total += r.n_blocks<EOL><DEDENT>print(n_blocks_total)<EOL>full_dshape = np.concatenate(((n_blocks_total,), dshape))<EOL>h5 = h5py.File(fileroot + '<STR_LIT>', '<STR_LIT:w>')<EOL>h5.attrs['<STR_LIT>'] = '<STR_LIT>'<EOL>block_size = <NUM_LIT:0>      <EOL>dset = h5.create_dataset('<STR_LIT:data>',<EOL>shape=full_dshape,<EOL>dtype=data.dtype) <EOL>h5_idx = <NUM_LIT:0><EOL>for filename in filelist:<EOL><INDENT>print("<STR_LIT>" % filename)<EOL>r = GuppiRaw(filename)<EOL>h5 = h5py.File(filename + '<STR_LIT>', '<STR_LIT:w>')<EOL>header, data = r.read_next_data_block()<EOL>for ii in range(<NUM_LIT:0>, r.n_blocks):<EOL><INDENT>t0 = time.time()<EOL>print("<STR_LIT>" % (h5_idx+<NUM_LIT:1>, full_dshape[<NUM_LIT:0>]))<EOL>header, data = r.read_next_data_block()<EOL>t1 = time.time()<EOL>t2 = time.time()<EOL>print("<STR_LIT>" % (h5_idx+<NUM_LIT:1>, full_dshape[<NUM_LIT:0>]))<EOL>dset[h5_idx, :] = data<EOL>t3 = time.time()<EOL>print("<STR_LIT>" % ((t1-t0), (t3-t2)))<EOL>h5_idx += <NUM_LIT:1><EOL>for key, value in header.items():<EOL><INDENT>dset.attrs[key] = value<EOL><DEDENT><DEDENT>h5.close()<EOL>t1 = time.time()<EOL>print("<STR_LIT>" % (t1- t0))<EOL><DEDENT>

Command line tool for converting guppi raw into HDF5 versions of guppi raw


with open(filename, '<STR_LIT:rb>') as fh:<EOL><INDENT>header_dict = {}<EOL>header_idxs = {}<EOL>keyword, value, idx = read_next_header_keyword(fh)<EOL>try:<EOL><INDENT>assert keyword == b'<STR_LIT>'<EOL><DEDENT>except AssertionError:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>while True:<EOL><INDENT>keyword, value, idx = read_next_header_keyword(fh)<EOL>if keyword == b'<STR_LIT>':<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>header_dict[keyword] = value<EOL>header_idxs[keyword] = idx<EOL><DEDENT><DEDENT><DEDENT>if return_idxs:<EOL><INDENT>return header_idxs<EOL><DEDENT>else:<EOL><INDENT>return header_dict<EOL><DEDENT>

Read blimpy header and return a Python dictionary of key:value pairs

    Args:
        filename (str): name of file to open

    Optional args:
        return_idxs (bool): Default False. If true, returns the file offset indexes
                            for values

    returns


<EOL>h = read_header(filename)<EOL>n_bytes  = int(h[b'<STR_LIT>'] / <NUM_LIT:8>)<EOL>n_chans = h[b'<STR_LIT>']<EOL>n_ifs   = h[b'<STR_LIT>']<EOL>idx_data = len_header(filename)<EOL>f = open(filename, '<STR_LIT:rb>')<EOL>f.seek(idx_data)<EOL>filesize = os.path.getsize(filename)<EOL>n_bytes_data = filesize - idx_data<EOL>if h[b'<STR_LIT>'] == <NUM_LIT:2>:<EOL><INDENT>n_ints = int(<NUM_LIT:4> * n_bytes_data / (n_chans * n_ifs))<EOL><DEDENT>else:<EOL><INDENT>n_ints = int(n_bytes_data / (n_bytes * n_chans * n_ifs))<EOL><DEDENT>return n_ints<EOL>

Calculate number of integrations in a given file


n_bytes = np.fromstring(fh.read(<NUM_LIT:4>), dtype='<STR_LIT>')[<NUM_LIT:0>]<EOL>if n_bytes > <NUM_LIT:255>:<EOL><INDENT>n_bytes = <NUM_LIT:16><EOL><DEDENT>keyword = fh.read(n_bytes)<EOL>if keyword == b'<STR_LIT>' or keyword == b'<STR_LIT>':<EOL><INDENT>return keyword, <NUM_LIT:0>, fh.tell()<EOL><DEDENT>else:<EOL><INDENT>dtype = header_keyword_types[keyword]<EOL>idx = fh.tell()<EOL>if dtype == b'<STR_LIT>':<EOL><INDENT>val = struct.unpack(dtype, fh.read(<NUM_LIT:4>))[<NUM_LIT:0>]<EOL><DEDENT>if dtype == b'<STR_LIT>':<EOL><INDENT>val = struct.unpack(dtype, fh.read(<NUM_LIT:8>))[<NUM_LIT:0>]<EOL><DEDENT>if dtype == b'<STR_LIT:str>':<EOL><INDENT>str_len = np.fromstring(fh.read(<NUM_LIT:4>), dtype='<STR_LIT>')[<NUM_LIT:0>]<EOL>val = fh.read(str_len)<EOL><DEDENT>if dtype == b'<STR_LIT>':<EOL><INDENT>val = struct.unpack('<STR_LIT>', fh.read(<NUM_LIT:8>))[<NUM_LIT:0>]<EOL>val = fil_double_to_angle(val)<EOL>if keyword == b'<STR_LIT>':<EOL><INDENT>val = Angle(val, unit=u.hour)<EOL><DEDENT>else:<EOL><INDENT>val = Angle(val, unit=u.deg)<EOL><DEDENT><DEDENT>return keyword, val, idx<EOL><DEDENT>

Args:
    fh (file): file handler

Returns:


if nbit > <NUM_LIT:8>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if <NUM_LIT:8> % nbit != <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if data.dtype not in (np.uint8, np.int8):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if nbit == <NUM_LIT:8>:<EOL><INDENT>return data<EOL><DEDENT>elif nbit == <NUM_LIT:4>:<EOL><INDENT>data = unpack_4to8(data)<EOL>return data<EOL><DEDENT>elif nbit == <NUM_LIT:2>:<EOL><INDENT>data = unpack_2to8(data)<EOL>return data<EOL><DEDENT>elif nbit == <NUM_LIT:1>:<EOL><INDENT>data = unpack_1to8(data)<EOL>return data<EOL><DEDENT>

upgrade data from nbits to 8bits

    Notes: Pretty sure this function is a little broken!


if d.ndim == <NUM_LIT:2>:<EOL><INDENT>if n_y is None:<EOL><INDENT>n_y = <NUM_LIT:1><EOL><DEDENT>if n_x is None:<EOL><INDENT>n_x = <NUM_LIT:1><EOL><DEDENT>d = d[:int(d.shape[<NUM_LIT:0>] // n_x) * n_x, :int(d.shape[<NUM_LIT:1>] // n_y) * n_y]<EOL>d = d.reshape((d.shape[<NUM_LIT:0>] // n_x, n_x, d.shape[<NUM_LIT:1>] // n_y, n_y))<EOL>d = d.mean(axis=<NUM_LIT:3>)<EOL>d = d.mean(axis=<NUM_LIT:1>)<EOL><DEDENT>elif d.ndim == <NUM_LIT:1>:<EOL><INDENT>d = d[:int(d.shape[<NUM_LIT:0>] // n_x) * n_x]<EOL>d = d.reshape((d.shape[<NUM_LIT:0>] // n_x, n_x))<EOL>d = d.mean(axis=<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>return d<EOL>

Rebin data by averaging bins together

    Args:
    d (np.array): data
    n_x (int): number of bins in x dir to rebin into one
    n_y (int): number of bins in y dir to rebin into one

    Returns:
    d: rebinned data with shape (n_x, n_y)


if self.header[b'<STR_LIT>'] == <NUM_LIT:6>:<EOL><INDENT>self.coords = gbt_coords<EOL><DEDENT>elif self.header[b'<STR_LIT>'] == <NUM_LIT:4>:<EOL><INDENT>self.coords = parkes_coords<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>if HAS_SLALIB:<EOL><INDENT>dut1 = <NUM_LIT:0.0><EOL>mjd = self.header[b'<STR_LIT>']<EOL>tellong = np.deg2rad(self.coords[<NUM_LIT:1>])<EOL>last = s.sla_gmst(mjd) - tellong + s.sla_eqeqx(mjd) + dut1<EOL>if last < <NUM_LIT:0.0> : last = last + <NUM_LIT>*np.pi<EOL>return last<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>


from argparse import ArgumentParser<EOL>parser = ArgumentParser(description="<STR_LIT>")<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>',  default='<STR_LIT>', dest='<STR_LIT>', type=str,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT:filename>', type=str,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=float,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=float,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=int,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default=None, dest='<STR_LIT>', type=int,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store_true>', default=False, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store_true>', default=False, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store>', default='<STR_LIT>', dest='<STR_LIT>', type=str,<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT:store_true>', default=False, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', action='<STR_LIT>', default=True, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT:-c>', action='<STR_LIT:store_true>', default=False, dest='<STR_LIT>',<EOL>help='<STR_LIT>')<EOL>args = parser.parse_args()<EOL>filename = args.filename<EOL>load_data = not args.info_only<EOL>wtp = args.what_to_plot<EOL>if not wtp or '<STR_LIT:s>' in wtp:<EOL><INDENT>if args.t_start == None:<EOL><INDENT>t_start = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>t_start = args.t_start<EOL><DEDENT>t_stop  = t_start + <NUM_LIT:1><EOL>if args.average:<EOL><INDENT>t_start = None<EOL>t_stop  = None<EOL><DEDENT><DEDENT>else:<EOL><INDENT>t_start = args.t_start<EOL>t_stop  = args.t_stop<EOL><DEDENT>if args.info_only:<EOL><INDENT>args.blank_dc = False<EOL>args.calibrate_band_pass = False<EOL><DEDENT>fil = Filterbank(filename, f_start=args.f_start, f_stop=args.f_stop,<EOL>t_start=t_start, t_stop=t_stop,<EOL>load_data=load_data,blank_dc=args.blank_dc,<EOL>cal_band_pass=args.calibrate_band_pass)<EOL>fil.info()<EOL>if not args.info_only:<EOL><INDENT>if args.what_to_plot == "<STR_LIT:w>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:8>, <NUM_LIT:6>))<EOL>fil.plot_waterfall(f_start=args.f_start, f_stop=args.f_stop)<EOL><DEDENT>elif args.what_to_plot == "<STR_LIT:s>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:8>, <NUM_LIT:6>))<EOL>fil.plot_spectrum(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='<STR_LIT:all>')<EOL><DEDENT>elif args.what_to_plot == "<STR_LIT>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:8>, <NUM_LIT:6>))<EOL>fil.plot_spectrum_min_max(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='<STR_LIT:all>')<EOL><DEDENT>elif args.what_to_plot == "<STR_LIT:k>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:8>, <NUM_LIT:6>))<EOL>fil.plot_kurtosis(f_start=args.f_start, f_stop=args.f_stop)<EOL><DEDENT>elif args.what_to_plot == "<STR_LIT:t>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:8>, <NUM_LIT:6>))<EOL>fil.plot_time_series(f_start=args.f_start, f_stop=args.f_stop,orientation='<STR_LIT:h>')<EOL><DEDENT>elif args.what_to_plot == "<STR_LIT:a>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:12>, <NUM_LIT:9>),facecolor='<STR_LIT>')<EOL>fil.plot_all(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='<STR_LIT:all>')<EOL><DEDENT>elif args.what_to_plot == "<STR_LIT>":<EOL><INDENT>plt.figure("<STR_LIT>", figsize=(<NUM_LIT:12>, <NUM_LIT:9>),facecolor='<STR_LIT>')<EOL>fil.plot_all(logged=True, f_start=args.f_start, f_stop=args.f_stop, t='<STR_LIT:all>',kurtosis=False)<EOL><DEDENT>if args.plt_filename != '<STR_LIT>':<EOL><INDENT>plt.savefig(args.plt_filename)<EOL><DEDENT>if not args.save_only:<EOL><INDENT>if '<STR_LIT>' in os.environ.keys():<EOL><INDENT>plt.show()<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>

Command line tool for plotting and viewing info on filterbank files


def grab_data(self, f_start=None, f_stop=None, t_start=None, t_stop=None, if_id=<NUM_LIT:0>):

if f_start is None:<EOL><INDENT>f_start = self.freqs[<NUM_LIT:0>]<EOL><DEDENT>if f_stop is None:<EOL><INDENT>f_stop = self.freqs[-<NUM_LIT:1>]<EOL><DEDENT>i0 = np.argmin(np.abs(self.freqs - f_start))<EOL>i1 = np.argmin(np.abs(self.freqs - f_stop))<EOL>if i0 < i1:<EOL><INDENT>plot_f    = self.freqs[i0:i1 + <NUM_LIT:1>]<EOL>plot_data = np.squeeze(self.data[t_start:t_stop, ..., i0:i1 + <NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>plot_f    = self.freqs[i1:i0 + <NUM_LIT:1>]<EOL>plot_data = np.squeeze(self.data[t_start:t_stop, ..., i1:i0 + <NUM_LIT:1>])<EOL><DEDENT>return plot_f, plot_data<EOL>


def _setup_time_axis(self, t_start=None, t_stop=None):

<EOL>ii_start, ii_stop = <NUM_LIT:0>, self.n_ints_in_file<EOL>if t_start:<EOL><INDENT>ii_start = t_start<EOL><DEDENT>if t_stop:<EOL><INDENT>ii_stop = t_stop<EOL><DEDENT>n_ints = ii_stop - ii_start<EOL>t0 = self.header[b'<STR_LIT>']<EOL>t_delt = self.header[b'<STR_LIT>']<EOL>self.timestamps = np.arange(<NUM_LIT:0>, n_ints) * t_delt / <NUM_LIT>/<NUM_LIT>/<NUM_LIT> + t0<EOL>return ii_start, ii_stop, n_ints<EOL>


def _setup_freqs(self, f_start=None, f_stop=None):

<EOL>f0 = self.header[b'<STR_LIT>']<EOL>f_delt = self.header[b'<STR_LIT>']<EOL>i_start, i_stop = <NUM_LIT:0>, self.header[b'<STR_LIT>']<EOL>if f_start:<EOL><INDENT>i_start = int((f_start - f0) / f_delt)<EOL><DEDENT>if f_stop:<EOL><INDENT>i_stop  = int((f_stop - f0)  / f_delt)<EOL><DEDENT>chan_start_idx = np.int(i_start)<EOL>chan_stop_idx  = np.int(i_stop)<EOL>if i_start < i_stop:<EOL><INDENT>i_vals = np.arange(chan_start_idx, chan_stop_idx)<EOL><DEDENT>else:<EOL><INDENT>i_vals = np.arange(chan_stop_idx, chan_start_idx)<EOL><DEDENT>self.freqs = f_delt * i_vals + f0<EOL><INDENT>if f_delt < <NUM_LIT:0>:<EOL><INDENT>self.freqs = self.freqs[::-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if chan_stop_idx < chan_start_idx:<EOL><INDENT>chan_stop_idx, chan_start_idx = chan_start_idx,chan_stop_idx<EOL><DEDENT>return i_start, i_stop, chan_start_idx, chan_stop_idx<EOL>


df = self.team_stats_per_game()<EOL>if not df.empty:<EOL><INDENT>return df.index.tolist()<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>')<EOL>return []<EOL><DEDENT>

Returns a list of the team IDs for the given year.
        :returns: List of team IDs.


html = sportsref.utils.get_html(self._subpage_url(subpage))<EOL>return pq(html)<EOL>

Returns PyQuery object for a given subpage URL.
        :subpage: The subpage of the season, e.g. 'per_game'.
        :returns: PyQuery object.


doc = self.get_sub_doc(identifier)<EOL>table = doc('<STR_LIT>'.format(identifier))<EOL>df = sportsref.utils.parse_table(table)<EOL>return df<EOL>

Helper function for player season stats.

        :identifier: string identifying the type of stat, e.g. 'per_game'.
        :returns: A DataFrame of stats.


doc = self.get_sub_doc('<STR_LIT>')<EOL>east_table = doc('<STR_LIT>')<EOL>east_df = pd.DataFrame(sportsref.utils.parse_table(east_table))<EOL>east_df.sort_values('<STR_LIT>', ascending=False, inplace=True)<EOL>east_df['<STR_LIT>'] = range(<NUM_LIT:1>, len(east_df) + <NUM_LIT:1>)<EOL>east_df['<STR_LIT>'] = '<STR_LIT:E>'<EOL>west_table = doc('<STR_LIT>')<EOL>west_df = sportsref.utils.parse_table(west_table)<EOL>west_df.sort_values('<STR_LIT>', ascending=False, inplace=True)<EOL>west_df['<STR_LIT>'] = range(<NUM_LIT:1>, len(west_df) + <NUM_LIT:1>)<EOL>west_df['<STR_LIT>'] = '<STR_LIT>'<EOL>full_df = pd.concat([east_df, west_df], axis=<NUM_LIT:0>).reset_index(drop=True)<EOL>full_df['<STR_LIT>'] = full_df.team_id.str.extract(r'<STR_LIT>', expand=False)<EOL>full_df['<STR_LIT>'] = [gb if isinstance(gb, int) or isinstance(gb, float) else <NUM_LIT:0><EOL>for gb in full_df['<STR_LIT>']]<EOL>full_df = full_df.drop('<STR_LIT>', axis=<NUM_LIT:1>)<EOL>expanded_table = doc('<STR_LIT>')<EOL>expanded_df = sportsref.utils.parse_table(expanded_table)<EOL>full_df = pd.merge(full_df, expanded_df, on='<STR_LIT>')<EOL>return full_df<EOL>

Returns a DataFrame containing standings information.


return self._get_team_stats_table('<STR_LIT>')<EOL>

Returns a Pandas DataFrame of miscellaneous stats about each team's
        season.


Returns a Pandas DataFrame of each team's basic stat totals for the
        season.


return self._get_player_stats_table('<STR_LIT>')<EOL>

Returns a DataFrame of per-game player stats for a season.


raise NotImplementedError('<STR_LIT>')<EOL>

Returns the team ID for the loser of that year's NBA Finals.
        :returns: 3-letter team ID for runner-up.


raise Exception('<STR_LIT>')<EOL>

Returns the year the player was selected (or undrafted).
        :returns: TODO


doc = self.get_sub_doc('<STR_LIT>'.format(year))<EOL>table = (doc('<STR_LIT>')<EOL>if kind == '<STR_LIT:P>' else doc('<STR_LIT>'))<EOL>df = sportsref.utils.parse_table(table)<EOL>return df<EOL>

Returns a table of a player's advanced game-by-game stats for a
        season.

        :param year: The year representing the desired season.
        :param kind: specifies regular season, playoffs, or both. One of 'R',
            'P', 'B'. Defaults to 'R'.
        :returns: A DataFrame of the player's advanced stats from each game of
            the season.
        :rtype: pd.DataFrame


@sportsref.decorators.memoize<EOL><INDENT>def age(self, year, month=<NUM_LIT:2>, day=<NUM_LIT:1>):<DEDENT>

doc = self.get_main_doc()<EOL>date_string = doc('<STR_LIT>').attr('<STR_LIT>')<EOL>regex = r'<STR_LIT>'<EOL>date_args = map(int, re.match(regex, date_string).groups())<EOL>birth_date = datetime.date(*date_args)<EOL>age_date = datetime.date(year=year, month=month, day=day)<EOL>delta = age_date - birth_date<EOL>age = delta.days / <NUM_LIT><EOL>return age<EOL>

Returns the age of the player on a given date.

        :year: int representing the year.
        :month: int representing the month (1-12).
        :day: int representing the day within the month (1-31).
        :returns: Age in years as a float.


doc = self.get_main_doc()<EOL>return doc('<STR_LIT>').text()<EOL>

Returns the name of the player as a string.


linescore = self.linescore()<EOL>return linescore.loc['<STR_LIT>', '<STR_LIT>']<EOL>

Returns away team ID.
        :returns: 3-character string representing away team's ID.


d = self.date()<EOL>if d.month >= <NUM_LIT:9>:<EOL><INDENT>return d.year + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>return d.year<EOL><DEDENT>

Returns the year ID of the season in which this game took place.

:returns: An int representing the year of the season.


return self._get_player_stats('<STR_LIT>')<EOL>

Returns a DataFrame of basic player stats from the game.


linescore = self.linescore()<EOL>return linescore.loc['<STR_LIT>', '<STR_LIT:T>']<EOL>

Returns score of the home team.
        :returns: int of the home score.


doc = self.get_main_doc()<EOL>table = doc('<STR_LIT>')<EOL>columns = [th.text() for th in table('<STR_LIT>').items('<STR_LIT>')]<EOL>columns[<NUM_LIT:0>] = '<STR_LIT>'<EOL>data = [<EOL>[sportsref.utils.flatten_links(td) for td in tr('<STR_LIT>').items()]<EOL>for tr in table('<STR_LIT>').next_all('<STR_LIT>').items()<EOL>]<EOL>return pd.DataFrame(data, index=['<STR_LIT>', '<STR_LIT>'],<EOL>columns=columns, dtype='<STR_LIT:float>')<EOL>

Returns the linescore for the game as a DataFrame.


<EOL>doc = self.get_main_doc()<EOL>tms = self.away(), self.home()<EOL>tm_ids = [table_id_fmt.format(tm) for tm in tms]<EOL>tables = [doc('<STR_LIT>'.format(tm_id).lower()) for tm_id in tm_ids]<EOL>dfs = [sportsref.utils.parse_table(table) for table in tables]<EOL>for i, (tm, df) in enumerate(zip(tms, dfs)):<EOL><INDENT>no_time = df['<STR_LIT>'] == <NUM_LIT:0><EOL>stat_cols = [col for col, dtype in df.dtypes.items()<EOL>if dtype != '<STR_LIT:object>']<EOL>df.loc[no_time, stat_cols] = <NUM_LIT:0><EOL>df['<STR_LIT>'] = tm<EOL>df['<STR_LIT>'] = i == <NUM_LIT:1><EOL>df['<STR_LIT>'] = [p < <NUM_LIT:5> for p in range(df.shape[<NUM_LIT:0>])]<EOL>df.drop_duplicates(subset='<STR_LIT>', keep='<STR_LIT>', inplace=True)<EOL><DEDENT>return pd.concat(dfs)<EOL>

Returns a DataFrame of player stats from the game (either basic or
        advanced, depending on the argument.

        :param table_id_fmt: Format string for str.format with a placeholder
            for the team ID (e.g. 'box_{}_basic')
        :returns: DataFrame of player stats


Returns home team ID.
        :returns: 3-character string representing home team's ID.


return sportsref.nfl.teams.team_names(self.yr)<EOL>

Mapping from 3-letter team IDs to full team names.

        :returns: Dictionary with team IDs as keys and full team strings as
            values.


return sportsref.nfl.teams.team_ids(self.yr)<EOL>

Mapping from full team names to 3-letter team IDs.
        :returns: Dictionary with tean names as keys and team IDs as values.


doc = self.get_doc()<EOL>table = (doc('<STR_LIT>') if kind == '<STR_LIT:R>' else<EOL>doc('<STR_LIT>'))<EOL>df = sportsref.utils.parse_table(table)<EOL>return df<EOL>

Gets yearly defense stats for the player (also has AV stats for OL).

        :kind: One of 'R', 'P', or 'B'. Case-insensitive; defaults to 'R'.
        :returns: Pandas DataFrame with rushing/receiving stats.


doc = self.get_doc()<EOL>table = doc('<STR_LIT>'.format(award_id))<EOL>return list(map(int, sportsref.utils.parse_awards_table(table)))<EOL>

Template for simple award functions that simply list years, such as
        pro bowls and first-team all pro.

        :award_id: The div ID that is appended to "leaderboard_" in selecting
        the table's div.
        :returns: List of years for the award.


url = self._subpage_url('<STR_LIT>', None)  <EOL>doc = pq(sportsref.utils.get_html(url))<EOL>table = (doc('<STR_LIT>') if kind == '<STR_LIT:R>' else<EOL>doc('<STR_LIT>'))<EOL>df = sportsref.utils.parse_table(table)<EOL>if year is not None:<EOL><INDENT>df = df.query('<STR_LIT>').reset_index(drop=True)<EOL><DEDENT>return df<EOL>

Gets the career gamelog of the given player.
        :kind: One of 'R', 'P', or 'B' (for regular season, playoffs, or both).
        Case-insensitive; defaults to 'R'.
        :year: The year for which the gamelog should be returned; if None,
        return entire career gamelog. Defaults to None.
        :returns: A DataFrame with the player's career gamelog.


Gets yearly passing stats for the player.

        :kind: One of 'R', 'P', or 'B'. Case-insensitive; defaults to 'R'.
        :returns: Pandas DataFrame with passing stats.


<EOL>if os.path.isfile(PSF_CONSTANTS_FILENAME):<EOL><INDENT>modtime = int(os.path.getmtime(PSF_CONSTANTS_FILENAME))<EOL>curtime = int(time.time())<EOL><DEDENT>if (os.path.isfile(PSF_CONSTANTS_FILENAME)<EOL>and curtime - modtime <= <NUM_LIT:7> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT>):<EOL><INDENT>with open(PSF_CONSTANTS_FILENAME, '<STR_LIT:r>') as const_f:<EOL><INDENT>def_dict = json.load(const_f)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>print('<STR_LIT>')<EOL>html = utils.get_html(PSF_URL)<EOL>doc = pq(html)<EOL>def_dict = {}<EOL>for inp in doc('<STR_LIT>'):<EOL><INDENT>name = inp.attrib['<STR_LIT:name>']<EOL>if name not in def_dict:<EOL><INDENT>def_dict[name] = {<EOL>'<STR_LIT:value>': set(),<EOL>'<STR_LIT>': set(),<EOL>'<STR_LIT:type>': inp.attrib['<STR_LIT:type>']<EOL>}<EOL><DEDENT>if inp.attrib['<STR_LIT:type>'] in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if '<STR_LIT>' in inp.attrib:<EOL><INDENT>def_dict[name]['<STR_LIT:value>'].add(inp.attrib['<STR_LIT:value>'])<EOL><DEDENT>def_dict[name]['<STR_LIT>'].add(inp.attrib['<STR_LIT:value>'])<EOL><DEDENT>else:<EOL><INDENT>def_dict[name]['<STR_LIT:value>'].add(inp.attrib.get('<STR_LIT:value>', '<STR_LIT>'))<EOL><DEDENT><DEDENT>for sel in doc.items('<STR_LIT>'):<EOL><INDENT>name = sel.attr['<STR_LIT:name>']<EOL>if name not in def_dict:<EOL><INDENT>def_dict[name] = {<EOL>'<STR_LIT:value>': set(),<EOL>'<STR_LIT>': set(),<EOL>'<STR_LIT:type>': '<STR_LIT>'<EOL>}<EOL><DEDENT>defaultOpt = sel('<STR_LIT>')<EOL>if len(defaultOpt):<EOL><INDENT>defaultOpt = defaultOpt[<NUM_LIT:0>]<EOL>def_dict[name]['<STR_LIT:value>'].add(defaultOpt.attrib.get('<STR_LIT:value>', '<STR_LIT>'))<EOL><DEDENT>else:<EOL><INDENT>def_dict[name]['<STR_LIT:value>'].add(<EOL>sel('<STR_LIT>')[<NUM_LIT:0>].attrib.get('<STR_LIT:value>', '<STR_LIT>')<EOL>)<EOL><DEDENT>def_dict[name]['<STR_LIT>'] = {<EOL>opt.attrib['<STR_LIT:value>'] for opt in sel('<STR_LIT>')<EOL>if opt.attrib.get('<STR_LIT:value>')<EOL>}<EOL><DEDENT>def_dict.pop('<STR_LIT>', None)<EOL>def_dict.pop('<STR_LIT>', None)<EOL>with open(PSF_CONSTANTS_FILENAME, '<STR_LIT>') as f:<EOL><INDENT>for k in def_dict:<EOL><INDENT>try:<EOL><INDENT>def_dict[k]['<STR_LIT:value>'] = sorted(<EOL>list(def_dict[k]['<STR_LIT:value>']), key=int<EOL>)<EOL>def_dict[k]['<STR_LIT>'] = sorted(<EOL>list(def_dict[k]['<STR_LIT>']), key=int<EOL>)<EOL><DEDENT>except Exception:<EOL><INDENT>def_dict[k]['<STR_LIT:value>'] = sorted(list(def_dict[k]['<STR_LIT:value>']))<EOL>def_dict[k]['<STR_LIT>'] = sorted(<EOL>list(def_dict[k]['<STR_LIT>'])<EOL>)<EOL><DEDENT><DEDENT>json.dump(def_dict, f)<EOL><DEDENT><DEDENT>return def_dict<EOL>

Handles scraping options for player-season finder form.

    :returns: {'name1': {'value': val, 'options': [opt1, ...] }, ... }


<EOL>inpOptDef = inputs_options_defaults()<EOL>opts = {<EOL>name: dct['<STR_LIT:value>']<EOL>for name, dct in inpOptDef.items()<EOL>}<EOL>for k, v in kwargs.items():<EOL><INDENT>if k.lower() in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>del kwargs[k]<EOL>kwargs['<STR_LIT>'] = v<EOL><DEDENT>if k == '<STR_LIT>':<EOL><INDENT>if v.startswith('<STR_LIT>'):<EOL><INDENT>kwargs[k] = utils.rel_url_to_id(v)<EOL><DEDENT><DEDENT>if isinstance(v, bool):<EOL><INDENT>kwargs[k] = '<STR_LIT:Y>' if v else '<STR_LIT:N>'<EOL><DEDENT>if k.lower() in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>del kwargs[k]<EOL>kwargs['<STR_LIT>'] = v<EOL><DEDENT>if k.lower() in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>del kwargs[k]<EOL>if k.lower() == '<STR_LIT>':<EOL><INDENT>kwargs['<STR_LIT>'] = int(v)<EOL><DEDENT>else:<EOL><INDENT>kwargs['<STR_LIT>'] = int(v)<EOL><DEDENT><DEDENT>if k.lower() in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>del kwargs[k]<EOL>if k.lower() == '<STR_LIT>':<EOL><INDENT>kwargs['<STR_LIT>'] = int(v)<EOL><DEDENT>else:<EOL><INDENT>kwargs['<STR_LIT>'] = int(v)<EOL><DEDENT><DEDENT>if k.lower() in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>del kwargs[k]<EOL>if isinstance(v, collections.Iterable):<EOL><INDENT>lst = list(v)<EOL>kwargs['<STR_LIT>'] = min(lst)<EOL>kwargs['<STR_LIT>'] = max(lst)<EOL><DEDENT>elif isinstance(v, basestring):<EOL><INDENT>v = list(map(int, v.split('<STR_LIT:U+002C>')))<EOL>kwargs['<STR_LIT>'] = min(v)<EOL>kwargs['<STR_LIT>'] = max(v)<EOL><DEDENT>else:<EOL><INDENT>kwargs['<STR_LIT>'] = v<EOL>kwargs['<STR_LIT>'] = v<EOL><DEDENT><DEDENT>if k.lower() in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>del kwargs[k]<EOL>if isinstance(v, collections.Iterable):<EOL><INDENT>lst = list(v)<EOL>kwargs['<STR_LIT>'] = min(lst)<EOL>kwargs['<STR_LIT>'] = max(lst)<EOL><DEDENT>elif isinstance(v, basestring):<EOL><INDENT>v = list(map(int, v.split('<STR_LIT:U+002C>')))<EOL>kwargs['<STR_LIT>'] = min(v)<EOL>kwargs['<STR_LIT>'] = max(v)<EOL><DEDENT>else:<EOL><INDENT>kwargs['<STR_LIT>'] = v<EOL>kwargs['<STR_LIT>'] = v<EOL><DEDENT><DEDENT>if k == '<STR_LIT>':<EOL><INDENT>kwargs['<STR_LIT>'] = '<STR_LIT:P>'<EOL><DEDENT>if isinstance(v, basestring):<EOL><INDENT>v = v.split('<STR_LIT:U+002C>')<EOL><DEDENT>if not isinstance(v, collections.Iterable):<EOL><INDENT>v = [v]<EOL><DEDENT><DEDENT>for k in kwargs:<EOL><INDENT>if k in opts:<EOL><INDENT>opts[k] = []<EOL><DEDENT><DEDENT>for k, v in kwargs.items():<EOL><INDENT>if k in opts:<EOL><INDENT>if isinstance(v, basestring):<EOL><INDENT>v = v.split('<STR_LIT:U+002C>')<EOL><DEDENT>elif not isinstance(v, collections.Iterable):<EOL><INDENT>v = [v]<EOL><DEDENT>for val in v:<EOL><INDENT>opts[k].append(val)<EOL><DEDENT><DEDENT><DEDENT>opts['<STR_LIT>'] = [<NUM_LIT:1>]<EOL>qs = '<STR_LIT:&>'.join('<STR_LIT>'.format(name, val)<EOL>for name, vals in sorted(opts.items()) for val in vals)<EOL>return qs<EOL>

Converts kwargs given to GPF to a querystring.

    :returns: the querystring.


doc = self.get_doc()<EOL>raw = doc('<STR_LIT>').attr['<STR_LIT>']<EOL>match = re.match(<EOL>r'<STR_LIT>'.format(self.season()), raw<EOL>)<EOL>if match:<EOL><INDENT>return int(match.group(<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>return <NUM_LIT><EOL><DEDENT>

Returns the week in which this game took place. 18 is WC round, 19
        is Div round, 20 is CC round, 21 is SB.
        :returns: Integer from 1 to 21.


<EOL>doc = self.get_doc()<EOL>table_ids = ('<STR_LIT>', '<STR_LIT>')<EOL>tms = (self.away(), self.home())<EOL>df = pd.concat([<EOL>sportsref.utils.parse_table(doc('<STR_LIT>'.format(table_id)))<EOL>.assign(is_home=bool(i), team=tms[i], opp=tms[i*-<NUM_LIT:1>+<NUM_LIT:1>])<EOL>for i, table_id in enumerate(table_ids)<EOL>])<EOL>if df.empty:<EOL><INDENT>return df<EOL><DEDENT>return df.set_index('<STR_LIT>')<EOL>

Gets the snap counts for both teams' players and returns them in a
        DataFrame. Note: only goes back to 2012.

        :returns: DataFrame of snap count data


doc = self.get_doc()<EOL>table = doc('<STR_LIT>')<EOL>return sportsref.utils.parse_info_table(table)<EOL>

Gets a dictionary of ref positions and the ref IDs of the refs for
        that game.

        :returns: A dictionary of ref positions and IDs.


doc = self.get_doc()<EOL>table = doc('<STR_LIT>')<EOL>giTable = sportsref.utils.parse_info_table(table)<EOL>if '<STR_LIT>' in giTable:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>

Gets information relating to the opening coin toss.

        Keys are:
        * wonToss - contains the ID of the team that won the toss
        * deferred - bool whether the team that won the toss deferred it

        :returns: Dictionary of coin toss-related info.


days = ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>']<EOL>date = self.date()<EOL>wd = date.weekday()<EOL>return days[wd]<EOL>

Returns the day of the week on which the game occurred.
        :returns: String representation of the day of the week for the game.


doc = self.get_doc()<EOL>table = doc('<STR_LIT>')<EOL>relURL = table('<STR_LIT>').eq(<NUM_LIT:1>)('<STR_LIT:a>').eq(<NUM_LIT:2>).attr['<STR_LIT>']<EOL>away = sportsref.utils.rel_url_to_id(relURL)<EOL>return away<EOL>

Returns away team ID.
        :returns: 3-character string representing away team's ID.


doc = self.get_year_doc(year)<EOL>table = doc('<STR_LIT>')<EOL>df = sportsref.utils.parse_table(table)<EOL>return df.loc[df.player_id == '<STR_LIT>'].iloc[<NUM_LIT:0>]<EOL>

Returns a Series (dict-like) of the team's opponent's stats from the
        team-season page.

        :year: Int representing the season.
        :returns: A Series of team stats.


doc = self.get_year_doc(year)<EOL>table = doc('<STR_LIT>')<EOL>df = sportsref.utils.parse_table(table)<EOL>if df.empty:<EOL><INDENT>return pd.Series()<EOL><DEDENT>return df.loc[df.player_id == '<STR_LIT>'].iloc[<NUM_LIT:0>]<EOL>

Returns a Series (dict-like) of team stats from the team-season
        page.

        :year: Int representing the season.
        :returns: A Series of team stats.


names = team_names(year)<EOL>return {v: k for k, v in names.items()}<EOL>

Returns a mapping from team name to team ID for a given season. Inverse
    mapping of team_names. Example of a full team name: "New England Patriots"

    :year: The year of the season in question (as an int).
    :returns: A dictionary with full team name keys and teamID values.


anchor = self._year_info_pq(year, '<STR_LIT>')('<STR_LIT:a>')<EOL>return sportsref.utils.rel_url_to_id(anchor.attr['<STR_LIT>'])<EOL>

Returns the ID for the stadium in which the team played in a given
        year.

        :year: The year in question.
        :returns: A string representing the stadium ID.


doc = self.get_year_doc(year)<EOL>table = doc('<STR_LIT>')<EOL>df = sportsref.utils.parse_table(table)<EOL>if df.empty:<EOL><INDENT>return pd.DataFrame()<EOL><DEDENT>df = df.loc[df['<STR_LIT>'].notnull()]<EOL>df['<STR_LIT>'] = np.arange(len(df)) + <NUM_LIT:1><EOL>df['<STR_LIT>'] = df['<STR_LIT>'] == '<STR_LIT>'<EOL>df['<STR_LIT>'] = df['<STR_LIT>'] == '<STR_LIT:L>'<EOL>df['<STR_LIT>'] = df['<STR_LIT>'] == '<STR_LIT:T>'<EOL>df['<STR_LIT>'] = df['<STR_LIT>'].isnull()<EOL>df['<STR_LIT>'] = df['<STR_LIT>'].notnull()<EOL>return df<EOL>

Returns a DataFrame with schedule information for the given year.

        :year: The year for the season in question.
        :returns: Pandas DataFrame with schedule information.


doc = self.get_year_doc(year)<EOL>table = doc('<STR_LIT>')<EOL>df = sportsref.utils.parse_table(table)<EOL>if df.empty:<EOL><INDENT>return np.array([])<EOL><DEDENT>return df.boxscore_id.values<EOL>

Gets list of BoxScore objects corresponding to the box scores from
        that year.

        :year: The year for which we want the boxscores; defaults to current
        year.
        :returns: np.array of strings representing boxscore IDs.


doc = self.get_year_doc('<STR_LIT>'.format(year))<EOL>tables = doc('<STR_LIT>')<EOL>dfs = [sportsref.utils.parse_table(table) for table in tables.items()]<EOL>dfs = [<EOL>df.assign(split=df.columns[<NUM_LIT:0>])<EOL>.rename(columns={df.columns[<NUM_LIT:0>]: '<STR_LIT>'})<EOL>for df in dfs<EOL>]<EOL>if not dfs:<EOL><INDENT>return pd.DataFrame()<EOL><DEDENT>return pd.concat(dfs).reset_index(drop=True)<EOL>

Returns a DataFrame of defensive team splits (i.e. opponent splits)
        for a season.

        :year: int representing the season.
        :returns: Pandas DataFrame of split data.


global last_request_time<EOL>with throttle_process_lock:<EOL><INDENT>with throttle_thread_lock:<EOL><INDENT>wait_left = THROTTLE_DELAY - (time.time() - last_request_time.value)<EOL>if wait_left > <NUM_LIT:0>:<EOL><INDENT>time.sleep(wait_left)<EOL><DEDENT>response = requests.get(url)<EOL>last_request_time.value = time.time()<EOL><DEDENT><DEDENT>if <NUM_LIT> <= response.status_code < <NUM_LIT>:<EOL><INDENT>raise ValueError(<EOL>'<STR_LIT>'<EOL>.format(response.status_code, url)<EOL>)<EOL><DEDENT>html = response.text<EOL>html = html.replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT>', '<STR_LIT>')<EOL>return html<EOL>

Gets the HTML for the given URL using a GET request.

    :url: the absolute URL of the desired page.
    :returns: a string of HTML.


@funcutils.wraps(fun)<EOL>def wrapper(*args, **kwargs):<EOL><INDENT>do_memoization = sportsref.get_option('<STR_LIT>')<EOL>if not do_memoization:<EOL><INDENT>return fun(*args, **kwargs)<EOL><DEDENT>hash_args = tuple(args)<EOL>hash_kwargs = frozenset(sorted(kwargs.items()))<EOL>key = (hash_args, hash_kwargs)<EOL>def _copy(v):<EOL><INDENT>if isinstance(v, pq):<EOL><INDENT>return v.clone()<EOL><DEDENT>else:<EOL><INDENT>return copy.deepcopy(v)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>ret = _copy(cache[key])<EOL>return ret<EOL><DEDENT>except KeyError:<EOL><INDENT>cache[key] = fun(*args, **kwargs)<EOL>ret = _copy(cache[key])<EOL>return ret<EOL><DEDENT>except TypeError:<EOL><INDENT>print('<STR_LIT>'<EOL>.format(fun.__name__, key))<EOL>raise<EOL><DEDENT><DEDENT>cache = {}<EOL>return wrapper<EOL>

A decorator for memoizing functions.

    Only works on functions that take simple arguments - arguments that take
    list-like or dict-like arguments will not be memoized, and this function
    will raise a TypeError.


try:<EOL><INDENT>data = os.read(self._fileno, self.max_size)<EOL><DEDENT>except InterruptedError:<EOL><INDENT>pass<EOL><DEDENT>except OSError as exc:<EOL><INDENT>self._fatal_error(exc, "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>if data:<EOL><INDENT>self._protocol.data_received(data)<EOL><DEDENT>else:<EOL><INDENT>if self._loop.get_debug():<EOL><INDENT>logger.info("<STR_LIT>", self)<EOL><DEDENT>self._closing = False<EOL>self.pause_reading()<EOL>self._loop.call_soon(self._protocol.eof_received)<EOL>self._loop.call_soon(self._call_connection_lost, None)<EOL><DEDENT><DEDENT>

Called by the event loop whenever the fd is ready for reading.


reader = asyncio.StreamReader(loop=loop)<EOL>protocol = asyncio.StreamReaderProtocol(reader, loop=loop)<EOL>waiter = asyncio.futures.Future(loop=loop)<EOL>transport = UnixFileDescriptorTransport(<EOL>loop=loop,<EOL>fileno=fd,<EOL>protocol=protocol,<EOL>waiter=waiter,<EOL>)<EOL>try:<EOL><INDENT>yield from waiter<EOL><DEDENT>except Exception:<EOL><INDENT>transport.close()<EOL><DEDENT>if loop.get_debug():<EOL><INDENT>logger.debug("<STR_LIT>", fd, transport, protocol)<EOL><DEDENT>return reader, transport<EOL>

Recieve a streamer for a given file descriptor.


self._loop.remove_reader(self._fileno)<EOL>self._active = False<EOL>

Public API: pause reading the transport.


if not self._closing:<EOL><INDENT>self._close()<EOL><DEDENT>


PyFunceble.INTERN["<STR_LIT>"] = "<STR_LIT>"<EOL>self.file = (<EOL>PyFunceble.CURRENT_DIRECTORY<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>)<EOL>self.expected_content = {<EOL>PyFunceble.INTERN["<STR_LIT>"]: {<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:state>": "<STR_LIT>",<EOL>},<EOL>"<STR_LIT>": {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT:state>": "<STR_LIT>",<EOL>},<EOL>}<EOL>}<EOL>


self.to_test = {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": {"<STR_LIT>", "<STR_LIT:hello>"},<EOL>"<STR_LIT>": ["<STR_LIT>", "<STR_LIT>"],<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": ["<STR_LIT>"],<EOL>}<EOL>


PyFunceble.initiate(True)<EOL>PyFunceble.load_config(True)<EOL>BaseStdout.setUp(self)<EOL>logo =


PyFunceble.load_config(True)<EOL>self.domains = [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>]<EOL>

Setup everything that is needed for the tests.


PyFunceble.load_config(True)<EOL>self.file = "<STR_LIT>"<EOL>self.to_print = {<EOL>"<STR_LIT>": {"<STR_LIT:hello>": <NUM_LIT:5>, "<STR_LIT>": <NUM_LIT:6>, "<STR_LIT>": <NUM_LIT:7>, "<STR_LIT>": <NUM_LIT:8>, "<STR_LIT>": <NUM_LIT:10>},<EOL>"<STR_LIT>": [<NUM_LIT:5>, <NUM_LIT:6>, <NUM_LIT:7>, <NUM_LIT:8>, <NUM_LIT:9>, <NUM_LIT:10>],<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": {"<STR_LIT>": <NUM_LIT:7>, "<STR_LIT>": <NUM_LIT:11>},<EOL>}<EOL>


if "<STR_LIT>" not in PyFunceble.INTERN or not PyFunceble.INTERN["<STR_LIT>"]:<EOL><INDENT>PyFunceble.INTERN["<STR_LIT>"] = self.iana_db<EOL><DEDENT>

Initiate the IANA database if it is not the case.


<EOL>dir_structure_link = PyFunceble.CONFIGURATION["<STR_LIT>"]["<STR_LIT>"]<EOL>dir_structure_link = Version(True).right_url_from_version(dir_structure_link)<EOL>destination = (<EOL>PyFunceble.CURRENT_DIRECTORY<EOL>+ PyFunceble.CONFIGURATION["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>)<EOL>if not Version(True).is_cloned() or not PyFunceble.path.isfile(destination):<EOL><INDENT>data = Download(dir_structure_link, destination, return_data=True).text()<EOL>File(destination).write(data, overwrite=True)<EOL>return True<EOL><DEDENT>return None<EOL>

Download the latest version of `dir_structure_production.json`.


@classmethod<EOL><INDENT>def check_versions_literally(cls, local, upstream):<DEDENT>

return local == upstream<EOL>

Compare the given versions literally.

:param local: The local version converted by split_versions().
:type local: str

:param upstream: The upstream version converted by split_versions().
:type upstream: str

:return:
    - True: local == upstream
    - False: local != upstream
:rtype: bool


if not PyFunceble.path.isdir("<STR_LIT>"):<EOL><INDENT>return False<EOL><DEDENT>list_of_file = [<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>]<EOL>list_of_dir = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>for file in list_of_file:<EOL><INDENT>if not PyFunceble.path.isfile(file):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>for directory in list_of_dir:<EOL><INDENT>if not PyFunceble.path.isdir(directory):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>

Let us know if we are currently in the cloned version of
PyFunceble which implicitly mean that we are in developement mode.


if "<STR_LIT>" in PyFunceble.VERSION:<EOL><INDENT>return url.replace("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>return url.replace("<STR_LIT>", "<STR_LIT>")<EOL>

Convert the GitHub URL to the right one depending of the
branch or version we are working with.

:param url: The URL to convert.
:type url: str

:return: The converted URL.
:rtype: str


if self.upstream_data["<STR_LIT>"]["<STR_LIT:status>"]:<EOL><INDENT>for minimal in self.upstream_data["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>checked = self.check_versions(<EOL>self.local_splited, self.split_versions(minimal)<EOL>)<EOL>if not PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>if checked or checked is not False and not checked:<EOL><INDENT>message = (<EOL>PyFunceble.Style.BRIGHT<EOL>+ PyFunceble.Fore.RED<EOL>+ "<STR_LIT>"<EOL>+ PyFunceble.Style.RESET_ALL<EOL>)  <EOL>message += (<EOL>PyFunceble.Style.BRIGHT<EOL>+ PyFunceble.Fore.GREEN<EOL>+ "<STR_LIT>"<EOL>+ PyFunceble.Style.RESET_ALL<EOL>)  <EOL>print(message)<EOL>exit(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>elif checked or checked is not False and not checked:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"  <EOL>)<EOL><DEDENT><DEDENT><DEDENT>for version in self.upstream_data["<STR_LIT>"]:<EOL><INDENT>checked = self.check_versions(<EOL>self.local_splited, self.split_versions(version)<EOL>)<EOL>if (<EOL>not PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>and checked<EOL>or checked is not False<EOL>and not checked<EOL>):<EOL><INDENT>message = (<EOL>PyFunceble.Style.BRIGHT<EOL>+ PyFunceble.Fore.RED<EOL>+ "<STR_LIT>"<EOL>+ PyFunceble.Style.RESET_ALL<EOL>)  <EOL>message += (<EOL>PyFunceble.Style.BRIGHT<EOL>+ PyFunceble.Fore.GREEN<EOL>+ "<STR_LIT>"<EOL>+ PyFunceble.Style.RESET_ALL<EOL>)  <EOL>print(message)<EOL>return<EOL><DEDENT>if checked or checked is not False and not checked:<EOL><INDENT>print("<STR_LIT>")<EOL>return<EOL><DEDENT><DEDENT>status = self.check_versions(<EOL>self.local_splited,<EOL>self.split_versions(self.upstream_data["<STR_LIT>"]),<EOL>)<EOL>if status is not None and not status and not PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>message = (<EOL>PyFunceble.Style.BRIGHT<EOL>+ PyFunceble.Fore.CYAN<EOL>+ "<STR_LIT>"  <EOL>+ PyFunceble.Style.RESET_ALL<EOL>)<EOL>message += (<EOL>PyFunceble.Style.BRIGHT<EOL>+ "<STR_LIT>"<EOL>+ PyFunceble.Style.RESET_ALL<EOL>+ PyFunceble.VERSION<EOL>+ "<STR_LIT:\n>"<EOL>)<EOL>message += (<EOL>PyFunceble.Style.BRIGHT<EOL>+ "<STR_LIT>"<EOL>+ PyFunceble.Style.RESET_ALL<EOL>+ self.upstream_data["<STR_LIT>"]<EOL>+ "<STR_LIT:\n>"<EOL>)<EOL>print(message)<EOL><DEDENT>elif status:<EOL><INDENT>if not PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>message = (<EOL>PyFunceble.Style.BRIGHT<EOL>+ PyFunceble.Fore.YELLOW<EOL>+ "<STR_LIT>"<EOL>+ PyFunceble.Style.RESET_ALL<EOL>)  <EOL>message += (<EOL>PyFunceble.Style.BRIGHT<EOL>+ "<STR_LIT>"<EOL>+ PyFunceble.Style.RESET_ALL<EOL>+ PyFunceble.VERSION<EOL>+ "<STR_LIT:\n>"<EOL>)  <EOL>message += (<EOL>PyFunceble.Style.BRIGHT<EOL>+ "<STR_LIT>"<EOL>+ PyFunceble.Style.RESET_ALL<EOL>+ self.upstream_data[  <EOL>"<STR_LIT>"<EOL>]<EOL>+ "<STR_LIT:\n>"<EOL>)<EOL>print(message)<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT><DEDENT>return<EOL>

Compare the current version with the upstream saved version.


if (<EOL>not PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>or self.template == "<STR_LIT>"<EOL>or do_not_print<EOL>):<EOL><INDENT>if (<EOL>self.template.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]<EOL>or self.template == "<STR_LIT>"<EOL>):<EOL><INDENT>to_print = self.headers["<STR_LIT>"]<EOL>if (<EOL>self.template.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]<EOL>and PyFunceble.HTTP_CODE["<STR_LIT>"]<EOL>):<EOL><INDENT>to_print = Dict(to_print).remove_key("<STR_LIT>")<EOL><DEDENT><DEDENT>elif self.template.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>to_print = self.headers[PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"]]<EOL><DEDENT>elif self.template.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>to_print = self.headers[PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"]]<EOL><DEDENT>elif self.template.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>to_print = self.headers[PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"]]<EOL><DEDENT>elif self.template.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>to_print = self.headers[PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"]]<EOL><DEDENT>elif (<EOL>self.template == "<STR_LIT>"<EOL>or self.template == "<STR_LIT>"<EOL>or self.template == "<STR_LIT>"<EOL>):  <EOL><INDENT>to_print = self.headers[self.template]<EOL>if self.template == "<STR_LIT>" and not PyFunceble.HTTP_CODE["<STR_LIT>"]:<EOL><INDENT>to_print["<STR_LIT>"] = <NUM_LIT:10><EOL><DEDENT><DEDENT>if not PyFunceble.HTTP_CODE["<STR_LIT>"]:<EOL><INDENT>to_print = Dict(to_print).remove_key("<STR_LIT>")<EOL><DEDENT>self.currently_used_header = to_print<EOL>if not do_not_print:<EOL><INDENT>self._before_header()<EOL>for formatted_template in self._header_constructor(to_print):<EOL><INDENT>if not self.only_on_file:<EOL><INDENT>print(formatted_template)<EOL><DEDENT>if not PyFunceble.CONFIGURATION["<STR_LIT>"] and self.output:<EOL><INDENT>File(self.output).write(formatted_template + "<STR_LIT:\n>")<EOL><DEDENT><DEDENT><DEDENT><DEDENT>

Management and creation of templates of header.
Please consider as "header" the title of each columns.

:param do_not_print:
    Tell us if we have to print the header or not.
:type do_not_print: bool


if isinstance(self.data_to_print, list):<EOL><INDENT>to_print = {}<EOL>to_print_size = []<EOL>alone_cases = ["<STR_LIT>", "<STR_LIT>"]<EOL>without_header = ["<STR_LIT>", "<STR_LIT>"]<EOL>if self.template.lower() == "<STR_LIT>":<EOL><INDENT>if not PyFunceble.CONFIGURATION["<STR_LIT>"] and self.output:<EOL><INDENT>return self._json_print()<EOL><DEDENT>return None<EOL><DEDENT>if self.template not in alone_cases and self.template not in without_header:<EOL><INDENT>self.header(True)<EOL>to_print_size = self._size_from_header(self.currently_used_header)<EOL><DEDENT>elif self.template in without_header:<EOL><INDENT>for data in self.data_to_print:<EOL><INDENT>to_print_size.append(str(len(data)))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>to_print_size = self._size_from_header(self.headers[self.template])<EOL><DEDENT>to_print = self._data_constructor(to_print_size)<EOL>self._before_header()<EOL>for data in self._header_constructor(to_print, False):<EOL><INDENT>if self.template.lower() in PyFunceble.STATUS["<STR_LIT:list>"][<EOL>"<STR_LIT>"<EOL>] or self.template in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>if not self.only_on_file:<EOL><INDENT>colorified_data = self._colorify(data)<EOL>print(colorified_data)<EOL><DEDENT><DEDENT>if not PyFunceble.CONFIGURATION["<STR_LIT>"] and self.output:<EOL><INDENT>File(self.output).write(data + "<STR_LIT:\n>")<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>

Management and input of data to the table.

:raises:
    :code:`Exception`
        When self.data_to_print is not a list.


<EOL>directory = PyFunceble.OUTPUT_DIRECTORY + PyFunceble.OUTPUTS["<STR_LIT>"]<EOL>if not directory.endswith(PyFunceble.directory_separator):  <EOL><INDENT>directory += PyFunceble.directory_separator<EOL><DEDENT>result = []<EOL>for root, _, files in PyFunceble.walk(directory):<EOL><INDENT>for file in files:<EOL><INDENT>if file not in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>if root.endswith(PyFunceble.directory_separator):<EOL><INDENT>result.append(root + file)<EOL><DEDENT>else:<EOL><INDENT>result.append(<EOL>root + PyFunceble.directory_separator + file<EOL>)  <EOL><DEDENT><DEDENT><DEDENT><DEDENT>return result<EOL>


@classmethod<EOL><INDENT>def databases_to_delete(cls):  <DEDENT>

<EOL>directory = PyFunceble.CURRENT_DIRECTORY<EOL>result = []<EOL>result.append(<EOL>directory<EOL>+ PyFunceble.CONFIGURATION["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>)<EOL>result.append(<EOL>directory + PyFunceble.CONFIGURATION["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>)<EOL>result.append(<EOL>directory<EOL>+ PyFunceble.CONFIGURATION["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>)<EOL>result.append(<EOL>directory<EOL>+ PyFunceble.CONFIGURATION["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>)<EOL>result.append(<EOL>directory + PyFunceble.CONFIGURATION["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>)<EOL>result.append(<EOL>directory + PyFunceble.CONFIGURATION["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>)<EOL>return result<EOL>


<EOL>percentages = {<EOL>"<STR_LIT>": PyFunceble.INTERN["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.INTERN["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.INTERN["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>}<EOL>for percentage in percentages:<EOL><INDENT>calculation = (<EOL>percentages[percentage]<EOL>* <NUM_LIT:100><EOL>// PyFunceble.INTERN["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>)<EOL>PyFunceble.INTERN["<STR_LIT>"]["<STR_LIT>"].update({percentage: calculation})<EOL><DEDENT>

Calculate the percentage of each status.


if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>try:<EOL><INDENT>build_dir = PyFunceble.environ["<STR_LIT>"]<EOL>commands = [<EOL>"<STR_LIT>" % (build_dir),<EOL>"<STR_LIT>" % (build_dir),<EOL>"<STR_LIT>" % (build_dir),<EOL>"<STR_LIT>"<EOL>% (build_dir + PyFunceble.directory_separator),<EOL>r"<STR_LIT>" % (build_dir),<EOL>]<EOL>for command in commands:<EOL><INDENT>Command(command).execute()<EOL><DEDENT>if Command("<STR_LIT>").execute() == "<STR_LIT>":<EOL><INDENT>Command("<STR_LIT>").execute()<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>

Set permissions in order to avoid issues before commiting.


if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>try:<EOL><INDENT>_ = PyFunceble.environ["<STR_LIT>"]<EOL>time_autorisation = False<EOL>try:<EOL><INDENT>time_autorisation = int(PyFunceble.time()) >= int(<EOL>PyFunceble.INTERN["<STR_LIT:start>"]<EOL>) + (int(PyFunceble.CONFIGURATION["<STR_LIT>"]) * <NUM_LIT>)<EOL><DEDENT>except KeyError:<EOL><INDENT>if self.last and not self.bypass:<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>if self.last or time_autorisation or self.bypass:<EOL><INDENT>Percentage().log()<EOL>self.travis_permissions()<EOL>command = '<STR_LIT>'<EOL>if self.last or self.bypass:<EOL><INDENT>if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>for line in Command(<EOL>PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>).run():<EOL><INDENT>sys_stdout.write("<STR_LIT>".format(line))<EOL><DEDENT>self.travis_permissions()<EOL><DEDENT>message = (<EOL>PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>+ "<STR_LIT>"<EOL>)<EOL>Command(command % message).execute()<EOL><DEDENT>else:<EOL><INDENT>if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>for line in Command(<EOL>PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>).run():<EOL><INDENT>sys_stdout.write("<STR_LIT>".format(line))<EOL><DEDENT>self.travis_permissions()<EOL><DEDENT>Command(<EOL>command % PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>).execute()<EOL><DEDENT>print(<EOL>Command(<EOL>"<STR_LIT>"<EOL>% PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>).execute()<EOL>)<EOL>exit(<NUM_LIT:0>)<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>


def analytic_file(self, new_status, old_status=None):

if not old_status:<EOL><INDENT>old_status = self.domain_status<EOL><DEDENT>if "<STR_LIT>" in PyFunceble.INTERN and PyFunceble.INTERN["<STR_LIT>"]:<EOL><INDENT>output = (<EOL>self.output_parent_dir<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>+ "<STR_LIT>"<EOL>)<EOL>if new_status.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>output = output % (<EOL>PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>)<EOL>Generate("<STR_LIT>").info_files()<EOL><DEDENT>elif new_status.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>output = output % (<EOL>PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>)<EOL>Generate("<STR_LIT>").info_files()<EOL><DEDENT>elif new_status.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>output = output % (<EOL>PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>)<EOL>Generate("<STR_LIT>").info_files()<EOL><DEDENT>else:<EOL><INDENT>output = output % (<EOL>PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>)<EOL>Generate("<STR_LIT>").info_files()<EOL><DEDENT>Prints(<EOL>[<EOL>self.tested,<EOL>old_status,<EOL>PyFunceble.INTERN["<STR_LIT>"],<EOL>PyFunceble.CURRENT_TIME,<EOL>],<EOL>"<STR_LIT>",<EOL>output,<EOL>True,<EOL>).data()<EOL><DEDENT>

Generate :code:`Analytic/*` files based on the given old and
new statuses.

:param new_status: The new status of the domain.
:type new_status: str

:param old_status: The old status of the domain.
:type old_status: str


if PyFunceble.INTERN["<STR_LIT>"]:<EOL><INDENT>output = (<EOL>self.output_parent_dir<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ self.domain_status<EOL>)<EOL>if PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>Prints(<EOL>[self.tested, self.domain_status, self.source], "<STR_LIT>", output, True<EOL>).data()<EOL><DEDENT>elif PyFunceble.CONFIGURATION["<STR_LIT>"]:<EOL><INDENT>if self.domain_status.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>if PyFunceble.HTTP_CODE["<STR_LIT>"]:<EOL><INDENT>data_to_print = [<EOL>self.tested,<EOL>self.expiration_date,<EOL>self.source,<EOL>PyFunceble.INTERN["<STR_LIT>"],<EOL>PyFunceble.CURRENT_TIME,<EOL>]<EOL><DEDENT>else:<EOL><INDENT>data_to_print = [<EOL>self.tested,<EOL>self.expiration_date,<EOL>self.source,<EOL>PyFunceble.CURRENT_TIME,<EOL>]<EOL><DEDENT>Prints(<EOL>data_to_print, PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"], output, True<EOL>).data()<EOL><DEDENT>elif self.domain_status.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>data_to_print = [self.tested, self.source, PyFunceble.CURRENT_TIME]<EOL>Prints(<EOL>data_to_print,<EOL>PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>output,<EOL>True,<EOL>).data()<EOL><DEDENT>elif self.domain_status.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>if PyFunceble.HTTP_CODE["<STR_LIT>"]:<EOL><INDENT>data_to_print = [<EOL>self.tested,<EOL>PyFunceble.INTERN["<STR_LIT>"],<EOL>self.domain_status,<EOL>self.source,<EOL>PyFunceble.INTERN["<STR_LIT>"],<EOL>PyFunceble.CURRENT_TIME,<EOL>]<EOL><DEDENT>else:<EOL><INDENT>data_to_print = [<EOL>self.tested,<EOL>PyFunceble.INTERN["<STR_LIT>"],<EOL>self.domain_status,<EOL>self.source,<EOL>PyFunceble.CURRENT_TIME,<EOL>]<EOL><DEDENT>Prints(<EOL>data_to_print,<EOL>PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>output,<EOL>True,<EOL>).data()<EOL><DEDENT>elif self.domain_status.lower() in PyFunceble.STATUS["<STR_LIT:list>"]["<STR_LIT>"]:<EOL><INDENT>if PyFunceble.HTTP_CODE["<STR_LIT>"]:<EOL><INDENT>data_to_print = [<EOL>self.tested,<EOL>self.source,<EOL>PyFunceble.INTERN["<STR_LIT>"],<EOL>PyFunceble.CURRENT_TIME,<EOL>]<EOL><DEDENT>else:<EOL><INDENT>data_to_print = [<EOL>self.tested,<EOL>self.source,<EOL>PyFunceble.CURRENT_TIME,<EOL>]<EOL><DEDENT>Prints(<EOL>data_to_print,<EOL>PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>output,<EOL>True,<EOL>).data()<EOL><DEDENT><DEDENT><DEDENT>

Logic behind the printing (in file) when generating status file.


if "<STR_LIT>" in PyFunceble.INTERN:<EOL><INDENT>Generate(self.domain_status, self.source, self.expiration_date).info_files()<EOL>Percentage(self.domain_status).count()<EOL>self._prints_status_screen()<EOL>if self._do_not_produce_file():<EOL><INDENT>return None<EOL><DEDENT>if (<EOL>not PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>and PyFunceble.CONFIGURATION["<STR_LIT>"]<EOL>):<EOL><INDENT>self._prints_status_file()<EOL><DEDENT>else:<EOL><INDENT>self.unified_file()<EOL><DEDENT><DEDENT>

Generate a file according to the domain status.


if isinstance(element, list):<EOL><INDENT>return [self._extract_base(x) for x in element]<EOL><DEDENT>base = self.checker.is_url_valid(url=element, return_base=True)<EOL>if base:<EOL><INDENT>return base<EOL><DEDENT>if "<STR_LIT:/>" in element:<EOL><INDENT>return element.split("<STR_LIT:/>")[<NUM_LIT:0>]<EOL><DEDENT>return element<EOL>

Extract the base of the given element.

.. example:
    given "hello/world?world=beautiful" return "hello"

:param element: The element we are working with.
:type element: str|list


def _format_decoded(self, to_format, result=None):

if not result:<EOL><INDENT>result = []<EOL><DEDENT>for data in List(to_format).format():<EOL><INDENT>if data:<EOL><INDENT>if "<STR_LIT>" in data:<EOL><INDENT>return self._format_decoded(data.split("<STR_LIT>"), result)<EOL><DEDENT>if "<STR_LIT:#>" in data:<EOL><INDENT>return self._format_decoded(data.split("<STR_LIT:#>"), result)<EOL><DEDENT>if "<STR_LIT:U+002C>" in data:<EOL><INDENT>return self._format_decoded(data.split("<STR_LIT:U+002C>"), result)<EOL><DEDENT>if "<STR_LIT:!>" in data:<EOL><INDENT>return self._format_decoded(data.split("<STR_LIT:!>"), result)<EOL><DEDENT>if "<STR_LIT:|>" in data:<EOL><INDENT>return self._format_decoded(data.split("<STR_LIT:|>"), result)<EOL><DEDENT>if data:<EOL><INDENT>data = self._extract_base(data)<EOL>if data and (<EOL>self.checker.is_domain_valid(data)<EOL>or self.checker.is_ip_valid(data)<EOL>):<EOL><INDENT>result.append(data)<EOL><DEDENT>elif data:<EOL><INDENT>url_base = self.checker.is_url_valid(data, return_base=True)<EOL>if url_base:<EOL><INDENT>result.append(url_base)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return result<EOL>

Format the exctracted adblock line before passing it to the system.

:param to_format: The extracted line from the file.
:type to_format: str

:param result: A list of the result of this method.
:type result: list

:return: The list of domains or IP to test.
:rtype: list


<EOL>result = []<EOL>regex_domain_option = r"<STR_LIT>"<EOL>for option in options:<EOL><INDENT>try:<EOL><INDENT>domains = Regex(<EOL>option, regex_domain_option, return_data=True, rematch=True, group=<NUM_LIT:0><EOL>).match()[-<NUM_LIT:1>]<EOL>if domains:<EOL><INDENT>if self.aggressive:  <EOL><INDENT>result.extend(<EOL>[<EOL>x<EOL>for x in domains.split("<STR_LIT:|>")<EOL>if x and not x.startswith("<STR_LIT>")<EOL>]<EOL>)<EOL><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT><DEDENT><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return result<EOL>

Handle the data from the options.

:param options: The list of options from the rule.
:type options: list

:return: The list of domains to return globally.
:rtype: list


return [x for x in list_from_file if not self._is_to_ignore(x)]<EOL>

Removed the ignored element from the given list.

:param list_from_file:
    The list which represent the file we are decoding.
:type list_from_list: list

:return: The filtered list.
:rtype: list


<EOL>to_ignore = [r"<STR_LIT>"]  <EOL>for element in to_ignore:<EOL><INDENT>if Regex(line, element, return_data=False).match():<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>

Check if we have to ignore the given line.

:param line: The line from the file.
:type line: str


<EOL>to_replace_base_map = {"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]}<EOL>to_replace_map = {<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"][<EOL>"<STR_LIT>"<EOL>]<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"][<EOL>"<STR_LIT>"<EOL>]["<STR_LIT>"]<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"][<EOL>"<STR_LIT>"<EOL>]["<STR_LIT>"]<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"][<EOL>"<STR_LIT>"<EOL>]["<STR_LIT>"]<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"][<EOL>"<STR_LIT>"<EOL>]["<STR_LIT>"]<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"][<EOL>"<STR_LIT>"<EOL>]<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.STATUS["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>+ PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"],<EOL>"<STR_LIT>": PyFunceble.OUTPUTS["<STR_LIT>"]["<STR_LIT>"],<EOL>}<EOL>to_replace = {}<EOL>for mapped, declared in to_replace_map.items():<EOL><INDENT>declared = Directory(declared).fix_path()<EOL>to_replace.update({mapped: declared})<EOL><DEDENT>to_replace_base = {}<EOL>for mapped, declared in to_replace_base_map.items():<EOL><INDENT>declared = Directory(declared).fix_path()<EOL>to_replace_base.update({mapped: declared})<EOL><DEDENT>structure = Dict(structure).rename_key(to_replace_base)<EOL>structure[PyFunceble.OUTPUTS["<STR_LIT>"]] = Dict(<EOL>structure[PyFunceble.OUTPUTS["<STR_LIT>"]]<EOL>).rename_key(to_replace)<EOL>try:<EOL><INDENT>Dict(structure).to_json(self.structure)<EOL><DEDENT>except FileNotFoundError:<EOL><INDENT>PyFunceble.mkdir(<EOL>PyFunceble.directory_separator.join(<EOL>self.structure.split(PyFunceble.directory_separator)[:-<NUM_LIT:1>]<EOL>)<EOL>)<EOL>Dict(structure).to_json(self.structure)<EOL><DEDENT>return structure<EOL>

Update the paths according to configs.

:param structure: The read structure.
:type structure: dict


<EOL>structure = self._get_structure()<EOL>list_of_key = list(structure.keys())<EOL>structure = structure[list_of_key[<NUM_LIT:0>]]<EOL>parent_path = list_of_key[<NUM_LIT:0>]<EOL>if not parent_path.endswith(PyFunceble.directory_separator):<EOL><INDENT>parent_path += PyFunceble.directory_separator<EOL><DEDENT>replacement_status = self._restore_replace()<EOL>for directory in structure:<EOL><INDENT>base = self.base + parent_path + directory<EOL>if not base.endswith(PyFunceble.directory_separator):<EOL><INDENT>base += PyFunceble.directory_separator<EOL><DEDENT>self._create_directory(base)<EOL>for file in structure[directory]:<EOL><INDENT>file_path = base + file<EOL>content_to_write = structure[directory][file]["<STR_LIT:content>"]<EOL>online_sha = structure[directory][file]["<STR_LIT>"]<EOL>content_to_write = Regex(<EOL>content_to_write, "<STR_LIT>", escape=True, replace_with="<STR_LIT>"<EOL>).replace()<EOL>git_to_keep = file_path.replace("<STR_LIT>", "<STR_LIT>")<EOL>keep_to_git = file_path.replace("<STR_LIT>", "<STR_LIT>")<EOL>if replacement_status:<EOL><INDENT>if (<EOL>PyFunceble.path.isfile(file_path)<EOL>and Hash(file_path, "<STR_LIT>", True).get() == online_sha<EOL>):<EOL><INDENT>PyFunceble.rename(file_path, git_to_keep)<EOL>write = False<EOL><DEDENT>else:<EOL><INDENT>File(file_path).delete()<EOL>file_path = git_to_keep<EOL>write = True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if (<EOL>PyFunceble.path.isfile(keep_to_git)<EOL>and Hash(file_path, "<STR_LIT>", True).get() == online_sha<EOL>):<EOL><INDENT>PyFunceble.rename(file_path, keep_to_git)<EOL>write = False<EOL><DEDENT>else:<EOL><INDENT>File(keep_to_git).delete()<EOL>file_path = keep_to_git<EOL>write = True<EOL><DEDENT><DEDENT>if write:<EOL><INDENT>File(file_path).write(content_to_write + "<STR_LIT:\n>", True)<EOL><DEDENT><DEDENT><DEDENT>self.delete_uneeded()<EOL>

Restore the 'output/' directory structure based on the `dir_structure.json` file.


@classmethod<EOL><INDENT>def _create_directory(cls, directory, loop=False):<DEDENT>

if not loop and PyFunceble.directory_separator in directory:<EOL><INDENT>splited_directory = directory.split(PyFunceble.directory_separator)<EOL>full_path_to_create = "<STR_LIT>"<EOL>for single_directory in splited_directory:<EOL><INDENT>full_path_to_create += single_directory + PyFunceble.directory_separator<EOL>cls._create_directory(full_path_to_create, True)<EOL><DEDENT><DEDENT>if not PyFunceble.path.isdir(directory):<EOL><INDENT>AutoSave.travis_permissions()<EOL>PyFunceble.mkdir(directory)<EOL>AutoSave.travis_permissions()<EOL><DEDENT>

Creates the given directory if it does not exists.

:param directory: The directory to create.
:type directory: str

:param loop: Tell us if we are in the creation loop or not.
:type loop: bool