signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
def _name_value(self, s):
parts = s.split(b'<STR_LIT:U+0020>', <NUM_LIT:2>)<EOL>name = parts[<NUM_LIT:0>]<EOL>if len(parts) == <NUM_LIT:1>:<EOL><INDENT>value = None<EOL><DEDENT>else:<EOL><INDENT>size = int(parts[<NUM_LIT:1>])<EOL>value = parts[<NUM_LIT:2>]<EOL>still_to_read = size - len(value)<EOL>if still_to_read > <NUM_LIT:0>:<EOL><INDENT>rea...
Parse a (name,value) tuple from 'name value-length value'.
f11391:c1:m17
def _path(self, s):
if s.startswith(b'<STR_LIT:">'):<EOL><INDENT>if not s.endswith(b'<STR_LIT:">'):<EOL><INDENT>self.abort(errors.BadFormat, '<STR_LIT:?>', '<STR_LIT:?>', s)<EOL><DEDENT>else:<EOL><INDENT>return _unquote_c_string(s[<NUM_LIT:1>:-<NUM_LIT:1>])<EOL><DEDENT><DEDENT>return s<EOL>
Parse a path.
f11391:c1:m18
def _path_pair(self, s):
<EOL>if s.startswith(b'<STR_LIT:">'):<EOL><INDENT>parts = s[<NUM_LIT:1>:].split(b'<STR_LIT>', <NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>parts = s.split(b'<STR_LIT:U+0020>', <NUM_LIT:1>)<EOL><DEDENT>if len(parts) != <NUM_LIT:2>:<EOL><INDENT>self.abort(errors.BadFormat, '<STR_LIT:?>', '<STR_LIT:?>', s)<EOL><DEDENT>elif ...
Parse two paths separated by a space.
f11391:c1:m19
def _mode(self, s):
<EOL>if s in [b'<STR_LIT>', b'<STR_LIT>', b'<STR_LIT>']:<EOL><INDENT>return <NUM_LIT><EOL><DEDENT>elif s in [b'<STR_LIT>', b'<STR_LIT>', b'<STR_LIT>']:<EOL><INDENT>return <NUM_LIT><EOL><DEDENT>elif s in [b'<STR_LIT>', b'<STR_LIT>']:<EOL><INDENT>return <NUM_LIT><EOL><DEDENT>elif s in [b'<STR_LIT>', b'<STR_LIT>']:<EOL><I...
Check file mode format and parse into an int. :return: mode as integer
f11391:c1:m20
def parse_raw(s, lineno=<NUM_LIT:0>):
timestamp_str, timezone_str = s.split(b'<STR_LIT:U+0020>', <NUM_LIT:1>)<EOL>timestamp = float(timestamp_str)<EOL>try:<EOL><INDENT>timezone = parse_tz(timezone_str)<EOL><DEDENT>except ValueError:<EOL><INDENT>raise errors.InvalidTimezone(lineno, timezone_str)<EOL><DEDENT>return timestamp, timezone<EOL>
Parse a date from a raw string. The format must be exactly "seconds-since-epoch offset-utc". See the spec for details.
f11400:m0
def parse_tz(tz):
<EOL>sign_byte = tz[<NUM_LIT:0>:<NUM_LIT:1>]<EOL>if sign_byte not in (b'<STR_LIT:+>', b'<STR_LIT:->'):<EOL><INDENT>raise ValueError(tz)<EOL><DEDENT>sign = {b'<STR_LIT:+>': +<NUM_LIT:1>, b'<STR_LIT:->': -<NUM_LIT:1>}[sign_byte]<EOL>hours = int(tz[<NUM_LIT:1>:-<NUM_LIT:2>])<EOL>minutes = int(tz[-<NUM_LIT:2>:])<EOL>return...
Parse a timezone specification in the [+|-]HHMM format. :return: the timezone offset in seconds.
f11400:m1
def parse_rfc2822(s, lineno=<NUM_LIT:0>):
raise NotImplementedError(parse_rfc2822)<EOL>
Parse a date from a rfc2822 string. See the spec for details.
f11400:m2
def parse_now(s, lineno=<NUM_LIT:0>):
return time.time(), <NUM_LIT:0><EOL>
Parse a date from a string. The format must be exactly "now". See the spec for details.
f11400:m3
def track_heads(self, cmd):
<EOL>if cmd.from_ is not None:<EOL><INDENT>parents = [cmd.from_]<EOL><DEDENT>else:<EOL><INDENT>last_id = self.last_ids.get(cmd.ref)<EOL>if last_id is not None:<EOL><INDENT>parents = [last_id]<EOL><DEDENT>else:<EOL><INDENT>parents = []<EOL><DEDENT><DEDENT>parents.extend(cmd.merges)<EOL>self.track_heads_for_ref(cmd.ref, ...
Track the repository heads given a CommitCommand. :param cmd: the CommitCommand :return: the list of parents in terms of commit-ids
f11401:c0:m3
def pre_handler(self, cmd):
if self._finished:<EOL><INDENT>return<EOL><DEDENT>if self.interesting_commit and cmd.name == '<STR_LIT>':<EOL><INDENT>if cmd.mark == self.interesting_commit:<EOL><INDENT>print(cmd.to_string())<EOL>self._finished = True<EOL><DEDENT>return<EOL><DEDENT>if cmd.name in self.parsed_params:<EOL><INDENT>fields = self.parsed_pa...
Hook for logic before each handler starts.
f11402:c0:m1
def progress_handler(self, cmd):
pass<EOL>
Process a ProgressCommand.
f11402:c0:m2
def blob_handler(self, cmd):
pass<EOL>
Process a BlobCommand.
f11402:c0:m3
def checkpoint_handler(self, cmd):
pass<EOL>
Process a CheckpointCommand.
f11402:c0:m4
def commit_handler(self, cmd):
pass<EOL>
Process a CommitCommand.
f11402:c0:m5
def reset_handler(self, cmd):
pass<EOL>
Process a ResetCommand.
f11402:c0:m6
def tag_handler(self, cmd):
pass<EOL>
Process a TagCommand.
f11402:c0:m7
def feature_handler(self, cmd):
feature = cmd.feature_name<EOL>if feature not in commands.FEATURE_NAMES:<EOL><INDENT>self.warning("<STR_LIT>"<EOL>% (feature,))<EOL><DEDENT>
Process a FeatureCommand.
f11402:c0:m8
def progress_handler(self, cmd):
<EOL>self.keep = True<EOL>
Process a ProgressCommand.
f11403:c0:m3
def blob_handler(self, cmd):
<EOL>self.blobs[cmd.id] = cmd<EOL>self.keep = False<EOL>
Process a BlobCommand.
f11403:c0:m4
def checkpoint_handler(self, cmd):
<EOL>self.keep = True<EOL>
Process a CheckpointCommand.
f11403:c0:m5
def commit_handler(self, cmd):
<EOL>interesting_filecmds = self._filter_filecommands(cmd.iter_files)<EOL>if interesting_filecmds or not self.squash_empty_commits:<EOL><INDENT>if len(interesting_filecmds) == <NUM_LIT:1> and isinstance(<EOL>interesting_filecmds[<NUM_LIT:0>], commands.FileDeleteAllCommand):<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDEN...
Process a CommitCommand.
f11403:c0:m6
def reset_handler(self, cmd):
if cmd.from_ is None:<EOL><INDENT>self.keep = True<EOL><DEDENT>else:<EOL><INDENT>cmd.from_ = self._find_interesting_from(cmd.from_)<EOL>self.keep = cmd.from_ is not None<EOL><DEDENT>
Process a ResetCommand.
f11403:c0:m7
def tag_handler(self, cmd):
<EOL>cmd.from_ = self._find_interesting_from(cmd.from_)<EOL>self.keep = cmd.from_ is not None<EOL>
Process a TagCommand.
f11403:c0:m8
def feature_handler(self, cmd):
feature = cmd.feature_name<EOL>if feature not in commands.FEATURE_NAMES:<EOL><INDENT>self.warning("<STR_LIT>"<EOL>% (feature,))<EOL><DEDENT>self.keep = True<EOL>
Process a FeatureCommand.
f11403:c0:m9
def _print_command(self, cmd):
text = helpers.repr_bytes(cmd)<EOL>self.outf.write(text)<EOL>if not text.endswith(b'<STR_LIT:\n>'):<EOL><INDENT>self.outf.write(b'<STR_LIT:\n>')<EOL><DEDENT>
Wrapper to avoid adding unnecessary blank lines.
f11403:c0:m10
def _filter_filecommands(self, filecmd_iter):
if self.includes is None and self.excludes is None:<EOL><INDENT>return list(filecmd_iter())<EOL><DEDENT>result = []<EOL>for fc in filecmd_iter():<EOL><INDENT>if (isinstance(fc, commands.FileModifyCommand) or<EOL>isinstance(fc, commands.FileDeleteCommand)):<EOL><INDENT>if self._path_to_be_kept(fc.path):<EOL><INDENT>fc.p...
Return the filecommands filtered by includes & excludes. :return: a list of FileCommand objects
f11403:c0:m11
def _path_to_be_kept(self, path):
if self.excludes and (path in self.excludes<EOL>or helpers.is_inside_any(self.excludes, path)):<EOL><INDENT>return False<EOL><DEDENT>if self.includes:<EOL><INDENT>return (path in self.includes<EOL>or helpers.is_inside_any(self.includes, path))<EOL><DEDENT>return True<EOL>
Does the given path pass the filtering criteria?
f11403:c0:m12
def _adjust_for_new_root(self, path):
if self.new_root is None:<EOL><INDENT>return path<EOL><DEDENT>elif path.startswith(self.new_root):<EOL><INDENT>return path[len(self.new_root):]<EOL><DEDENT>else:<EOL><INDENT>return path<EOL><DEDENT>
Adjust a path given the new root directory of the output.
f11403:c0:m13
def _convert_rename(self, fc):
old = fc.old_path<EOL>new = fc.new_path<EOL>keep_old = self._path_to_be_kept(old)<EOL>keep_new = self._path_to_be_kept(new)<EOL>if keep_old and keep_new:<EOL><INDENT>fc.old_path = self._adjust_for_new_root(old)<EOL>fc.new_path = self._adjust_for_new_root(new)<EOL>return fc<EOL><DEDENT>elif keep_old:<EOL><INDENT>old = s...
Convert a FileRenameCommand into a new FileCommand. :return: None if the rename is being ignored, otherwise a new FileCommand based on the whether the old and new paths are inside or outside of the interesting locations.
f11403:c0:m17
def _convert_copy(self, fc):
src = fc.src_path<EOL>dest = fc.dest_path<EOL>keep_src = self._path_to_be_kept(src)<EOL>keep_dest = self._path_to_be_kept(dest)<EOL>if keep_src and keep_dest:<EOL><INDENT>fc.src_path = self._adjust_for_new_root(src)<EOL>fc.dest_path = self._adjust_for_new_root(dest)<EOL>return fc<EOL><DEDENT>elif keep_src:<EOL><INDENT>...
Convert a FileCopyCommand into a new FileCommand. :return: None if the copy is being ignored, otherwise a new FileCommand based on the whether the source and destination paths are inside or outside of the interesting locations.
f11403:c0:m18
def _found(b):
return ['<STR_LIT>', '<STR_LIT>'][b]<EOL>
Format a found boolean as a string.
f11404:m0
def _iterable_as_config_list(s):
items = sorted(s)<EOL>if len(items) == <NUM_LIT:1>:<EOL><INDENT>return "<STR_LIT>" % (items[<NUM_LIT:0>],)<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT:U+002CU+0020>".join(items)<EOL><DEDENT>
Format an iterable as a sequence of comma-separated strings. To match what ConfigObj expects, a single item list has a trailing comma.
f11404:m1
def _dump_stats_group(self, title, items, normal_formatter=None,<EOL>verbose_formatter=None):
if self.verbose:<EOL><INDENT>self.outf.write("<STR_LIT>" % (title,))<EOL>for name, value in items:<EOL><INDENT>if verbose_formatter is not None:<EOL><INDENT>value = verbose_formatter(value)<EOL><DEDENT>if type(name) == str:<EOL><INDENT>name = name.replace('<STR_LIT:U+0020>', '<STR_LIT:->')<EOL><DEDENT>self.outf.write("...
Dump a statistics group. In verbose mode, do so as a config file so that other processors can load the information if they want to. :param normal_formatter: the callable to apply to the value before displaying it in normal mode :param verbose_formatter: the callable to apply t...
f11404:c0:m3
def progress_handler(self, cmd):
self.cmd_counts[cmd.name] += <NUM_LIT:1><EOL>
Process a ProgressCommand.
f11404:c0:m4
def blob_handler(self, cmd):
self.cmd_counts[cmd.name] += <NUM_LIT:1><EOL>if cmd.mark is None:<EOL><INDENT>self.blobs['<STR_LIT>'].add(cmd.id)<EOL><DEDENT>else:<EOL><INDENT>self.blobs['<STR_LIT>'].add(cmd.id)<EOL>try:<EOL><INDENT>self.blobs['<STR_LIT>'].remove(cmd.id)<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>
Process a BlobCommand.
f11404:c0:m5
def checkpoint_handler(self, cmd):
self.cmd_counts[cmd.name] += <NUM_LIT:1><EOL>
Process a CheckpointCommand.
f11404:c0:m6
def commit_handler(self, cmd):
self.cmd_counts[cmd.name] += <NUM_LIT:1><EOL>self.committers.add(cmd.committer)<EOL>if cmd.author is not None:<EOL><INDENT>self.separate_authors_found = True<EOL><DEDENT>for fc in cmd.iter_files():<EOL><INDENT>self.file_cmd_counts[fc.name] += <NUM_LIT:1><EOL>if isinstance(fc, commands.FileModifyCommand):<EOL><INDENT>if...
Process a CommitCommand.
f11404:c0:m7
def reset_handler(self, cmd):
self.cmd_counts[cmd.name] += <NUM_LIT:1><EOL>if cmd.ref.startswith('<STR_LIT>'):<EOL><INDENT>self.lightweight_tags += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>if cmd.from_ is not None:<EOL><INDENT>self.reftracker.track_heads_for_ref(<EOL>cmd.ref, cmd.from_)<EOL><DEDENT><DEDENT>
Process a ResetCommand.
f11404:c0:m8
def tag_handler(self, cmd):
self.cmd_counts[cmd.name] += <NUM_LIT:1><EOL>
Process a TagCommand.
f11404:c0:m9
def feature_handler(self, cmd):
self.cmd_counts[cmd.name] += <NUM_LIT:1><EOL>feature = cmd.feature_name<EOL>if feature not in commands.FEATURE_NAMES:<EOL><INDENT>self.warning("<STR_LIT>"<EOL>% (feature,))<EOL><DEDENT>
Process a FeatureCommand.
f11404:c0:m10
def check_path(path):
if path is None or path == b'<STR_LIT>' or path.startswith(b'<STR_LIT:/>'):<EOL><INDENT>raise ValueError("<STR_LIT>" % path)<EOL><DEDENT>if (<EOL>(sys.version_info[<NUM_LIT:0>] >= <NUM_LIT:3> and not isinstance(path, bytes)) and<EOL>(sys.version_info[<NUM_LIT:0>] == <NUM_LIT:2> and not isinstance(path, str))<EOL>):<EOL...
Check that a path is legal. :return: the path if all is OK :raise ValueError: if the path is illegal
f11405:m0
def format_path(p, quote_spaces=False):
if b'<STR_LIT:\n>' in p:<EOL><INDENT>p = re.sub(b'<STR_LIT:\n>', b'<STR_LIT>', p)<EOL>quote = True<EOL><DEDENT>else:<EOL><INDENT>quote = p[<NUM_LIT:0>] == b'<STR_LIT:">' or (quote_spaces and b'<STR_LIT:U+0020>' in p)<EOL><DEDENT>if quote:<EOL><INDENT>extra = GIT_FAST_IMPORT_NEEDS_EXTRA_SPACE_AFTER_QUOTE and b'<STR_LIT:...
Format a path in utf8, quoting it if necessary.
f11405:m1
def format_who_when(fields):
offset = fields[<NUM_LIT:3>]<EOL>if offset < <NUM_LIT:0>:<EOL><INDENT>offset_sign = b'<STR_LIT:->'<EOL>offset = abs(offset)<EOL><DEDENT>else:<EOL><INDENT>offset_sign = b'<STR_LIT:+>'<EOL><DEDENT>offset_hours = offset // <NUM_LIT><EOL>offset_minutes = offset // <NUM_LIT> - offset_hours * <NUM_LIT><EOL>offset_str = offse...
Format a tuple of name,email,secs-since-epoch,utc-offset-secs as a string.
f11405:m2
def format_property(name, value):
result = b'<STR_LIT>'<EOL>utf8_name = utf8_bytes_string(name)<EOL>result = b'<STR_LIT>' + utf8_name<EOL>if value is not None:<EOL><INDENT>utf8_value = utf8_bytes_string(value)<EOL>result += b'<STR_LIT:U+0020>' + ('<STR_LIT>' % len(utf8_value)).encode('<STR_LIT:ascii>') + b'<STR_LIT:U+0020>' + utf8_value<EOL><DEDENT>ret...
Format the name and value (both unicode) of a property as a string.
f11405:m3
def dump_str(self, names=None, child_lists=None, verbose=False):
interesting = {}<EOL>if names is None:<EOL><INDENT>fields = [<EOL>k for k in list(self.__dict__.keys())<EOL>if not k.startswith(b'<STR_LIT:_>')<EOL>]<EOL><DEDENT>else:<EOL><INDENT>fields = names<EOL><DEDENT>for field in fields:<EOL><INDENT>value = self.__dict__.get(field)<EOL>if field in self._binary and value is not N...
Dump fields as a string. For debugging. :param names: the list of fields to include or None for all public fields :param child_lists: dictionary of child command names to fields for that child command to include :param verbose: if True, prefix each line with the...
f11405:c0:m4
def to_string(self, use_features=True, include_file_contents=False):
if self.mark is None:<EOL><INDENT>mark_line = b'<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>if isinstance(self.mark, (int)):<EOL><INDENT>mark_line = b'<STR_LIT>' + str(self.mark).encode('<STR_LIT:utf-8>')<EOL><DEDENT>else:<EOL><INDENT>mark_line = b'<STR_LIT>' + self.mark<EOL><DEDENT><DEDENT>if self.author is None:<EOL><IN...
@todo the name to_string is ambiguous since the method actually returns bytes.
f11405:c3:m3
def iter_files(self):
<EOL>if callable(self.file_iter):<EOL><INDENT>return self.file_iter()<EOL><DEDENT>return iter(self.file_iter)<EOL>
Iterate over files.
f11405:c3:m5
def common_path(path1, path2):
return b'<STR_LIT>'.join(_common_path_and_rest(path1, path2)[<NUM_LIT:0>])<EOL>
Find the common bit of 2 paths.
f11407:m1
def common_directory(paths):
import posixpath<EOL>def get_dir_with_slash(path):<EOL><INDENT>if path == b'<STR_LIT>' or path.endswith(b'<STR_LIT:/>'):<EOL><INDENT>return path<EOL><DEDENT>else:<EOL><INDENT>dirname, basename = posixpath.split(path)<EOL>if dirname == b'<STR_LIT>':<EOL><INDENT>return dirname<EOL><DEDENT>else:<EOL><INDENT>return dirname...
Find the deepest common directory of a list of paths. :return: if no paths are provided, None is returned; if there is no common directory, '' is returned; otherwise the common directory with a trailing / is returned.
f11407:m2
def is_inside(directory, fname):
<EOL>if directory == fname:<EOL><INDENT>return True<EOL><DEDENT>if directory == b'<STR_LIT>':<EOL><INDENT>return True<EOL><DEDENT>if not directory.endswith(b'<STR_LIT:/>'):<EOL><INDENT>directory += b'<STR_LIT:/>'<EOL><DEDENT>return fname.startswith(directory)<EOL>
True if fname is inside directory. The parameters should typically be passed to osutils.normpath first, so that . and .. and repeated slashes are eliminated, and the separators are canonical for the platform. The empty string as a dir name is taken as top-of-tree and matches everything.
f11407:m3
def is_inside_any(dir_list, fname):
for dirname in dir_list:<EOL><INDENT>if is_inside(dirname, fname):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>
True if fname is inside any of given dirs.
f11407:m4
def utf8_bytes_string(s):
if sys.version_info[<NUM_LIT:0>] == <NUM_LIT:2>:<EOL><INDENT>if isinstance(s, str):<EOL><INDENT>return s<EOL><DEDENT>else:<EOL><INDENT>return s.encode('<STR_LIT:utf8>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if isinstance(s, str):<EOL><INDENT>return bytes(s, encoding='<STR_LIT:utf8>')<EOL><DEDENT>else:<EOL><INDENT>retur...
Convert a string to a bytes string (if necessary, encode in utf8)
f11407:m5
def repr_bytes(obj):
if sys.version_info[<NUM_LIT:0>] == <NUM_LIT:2>:<EOL><INDENT>return repr(obj)<EOL><DEDENT>else:<EOL><INDENT>return bytes(obj)<EOL><DEDENT>
Return a bytes representation of the object
f11407:m6
def binary_stream(stream):
try:<EOL><INDENT>import os<EOL>if os.name == '<STR_LIT>':<EOL><INDENT>fileno = getattr(stream, '<STR_LIT>', None)<EOL>if fileno:<EOL><INDENT>no = fileno()<EOL>if no >= <NUM_LIT:0>: <EOL><INDENT>import msvcrt<EOL>msvcrt.setmode(no, os.O_BINARY)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except ImportError:<EOL><INDENT>pass...
Ensure a stream is binary on Windows. :return: the stream
f11407:m7
def invert_dictset(d):
<EOL>result = {}<EOL>for k, c in d.items():<EOL><INDENT>for v in c:<EOL><INDENT>keys = result.setdefault(v, [])<EOL>keys.append(k)<EOL><DEDENT><DEDENT>return result<EOL>
Invert a dictionary with keys matching a set of values, turned into lists.
f11407:m8
def invert_dict(d):
<EOL>result = {}<EOL>for k, v in d.items():<EOL><INDENT>keys = result.setdefault(v, [])<EOL>keys.append(k)<EOL><DEDENT>return result<EOL>
Invert a dictionary with keys matching each value turned into a list.
f11407:m9
def defines_to_dict(defines):
if defines is None:<EOL><INDENT>return None<EOL><DEDENT>result = {}<EOL>for define in defines:<EOL><INDENT>kv = define.split('<STR_LIT:=>', <NUM_LIT:1>)<EOL>if len(kv) == <NUM_LIT:1>:<EOL><INDENT>result[define.strip()] = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>result[kv[<NUM_LIT:0>].strip()] = kv[<NUM_LIT:1>].strip()...
Convert a list of definition strings to a dictionary.
f11407:m10
def __native__(self):
return object(self)<EOL>
Hook for the future.utils.native() function
f11407:c0:m4
def validate_parameters(self):
for p in self.params:<EOL><INDENT>if p not in self.known_params:<EOL><INDENT>raise errors.UnknownParameter(p, self.known_params)<EOL><DEDENT><DEDENT>
Validate that the parameters are correctly specified.
f11408:c0:m1
def process(self, command_iter):
self._process(command_iter)<EOL>
Import data into Bazaar by processing a stream of commands. :param command_iter: an iterator providing commands
f11408:c0:m2
def warning(self, msg, *args):
pass<EOL>
Output a warning but timestamp it.
f11408:c0:m4
def debug(self, mgs, *args):
pass<EOL>
Output a debug message.
f11408:c0:m5
def _time_of_day(self):
<EOL>return time.strftime("<STR_LIT>")<EOL>
Time of day as a string.
f11408:c0:m6
def pre_process(self):
pass<EOL>
Hook for logic at start of processing.
f11408:c0:m7
def post_process(self):
pass<EOL>
Hook for logic at end of processing.
f11408:c0:m8
def pre_handler(self, cmd):
pass<EOL>
Hook for logic before each handler starts.
f11408:c0:m9
def post_handler(self, cmd):
pass<EOL>
Hook for logic after each handler finishes.
f11408:c0:m10
def progress_handler(self, cmd):
raise NotImplementedError(self.progress_handler)<EOL>
Process a ProgressCommand.
f11408:c0:m11
def blob_handler(self, cmd):
raise NotImplementedError(self.blob_handler)<EOL>
Process a BlobCommand.
f11408:c0:m12
def checkpoint_handler(self, cmd):
raise NotImplementedError(self.checkpoint_handler)<EOL>
Process a CheckpointCommand.
f11408:c0:m13
def commit_handler(self, cmd):
raise NotImplementedError(self.commit_handler)<EOL>
Process a CommitCommand.
f11408:c0:m14
def reset_handler(self, cmd):
raise NotImplementedError(self.reset_handler)<EOL>
Process a ResetCommand.
f11408:c0:m15
def tag_handler(self, cmd):
raise NotImplementedError(self.tag_handler)<EOL>
Process a TagCommand.
f11408:c0:m16
def feature_handler(self, cmd):
raise NotImplementedError(self.feature_handler)<EOL>
Process a FeatureCommand.
f11408:c0:m17
def warning(self, msg, *args):
pass<EOL>
Output a warning but add context.
f11408:c1:m2
def pre_process_files(self):
pass<EOL>
Prepare for committing.
f11408:c1:m3
def post_process_files(self):
pass<EOL>
Save the revision.
f11408:c1:m4
def modify_handler(self, filecmd):
raise NotImplementedError(self.modify_handler)<EOL>
Handle a filemodify command.
f11408:c1:m5
def delete_handler(self, filecmd):
raise NotImplementedError(self.delete_handler)<EOL>
Handle a filedelete command.
f11408:c1:m6
def copy_handler(self, filecmd):
raise NotImplementedError(self.copy_handler)<EOL>
Handle a filecopy command.
f11408:c1:m7
def rename_handler(self, filecmd):
raise NotImplementedError(self.rename_handler)<EOL>
Handle a filerename command.
f11408:c1:m8
def deleteall_handler(self, filecmd):
raise NotImplementedError(self.deleteall_handler)<EOL>
Handle a filedeleteall command.
f11408:c1:m9
def modular_sqrt(a, p):
<EOL>if legendre_symbol(a, p) != <NUM_LIT:1>:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>elif a == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>elif p == <NUM_LIT:2>:<EOL><INDENT>return p<EOL><DEDENT>elif p % <NUM_LIT:4> == <NUM_LIT:3>:<EOL><INDENT>return pow(a, (p + <NUM_LIT:1>) / <NUM_LIT:4>, p)<EOL><DEDEN...
Find a quadratic residue (mod p) of 'a'. p must be an odd prime. Solve the congruence of the form: x^2 = a (mod p) And returns x. Note that p - x is also a root. 0 is returned is no square root exists for these a and p. The Tonelli-Shanks algorithm is used (except for some simple case...
f11423:m0
def legendre_symbol(a, p):
ls = pow(a, (p - <NUM_LIT:1>) / <NUM_LIT:2>, p)<EOL>return -<NUM_LIT:1> if ls == p - <NUM_LIT:1> else ls<EOL>
Compute the Legendre symbol a|p using Euler's criterion. p is a prime, a is relatively prime to p (if p divides a, then a|p = 0) Returns 1 if a has a square root modulo p, -1 otherwise.
f11423:m1
@classmethod<EOL><INDENT>def from_signature(klass, sig, recid, h, curve):<DEDENT>
from ecdsa import util, numbertheory<EOL>import msqr<EOL>curveFp = curve.curve<EOL>G = curve.generator<EOL>order = G.order()<EOL>r, s = util.sigdecode_string(sig, order)<EOL>x = r + (recid/<NUM_LIT:2>) * order<EOL>alpha = ( x * x * x + curveFp.a() * x + curveFp.b() ) % curveFp.p()<EOL>beta = msqr.modular_sqrt(alpha, c...
See http://www.secg.org/download/aid-780/sec1-v2.pdf, chapter 4.1.6
f11424:c0:m0
def run(self):
try:<EOL><INDENT>import unittest2 as unittest<EOL><DEDENT>except ImportError:<EOL><INDENT>import unittest<EOL><DEDENT>if self.verbose:<EOL><INDENT>verbosity=<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>verbosity=<NUM_LIT:0><EOL><DEDENT>loader = unittest.defaultTestLoader<EOL>suite = unittest.TestSuite()<EOL>if self.test_s...
Run the test suite.
f11442:c0:m2
@property<EOL><INDENT>def cache(self):<DEDENT>
if self._cache is None:<EOL><INDENT>self._cache = django_cache.get_cache(self.cache_name)<EOL><DEDENT>return self._cache<EOL>
Memoize access to the cache backend.
f11445:c0:m1
def get(self, key, default=None):
raise NotImplementedError()<EOL>
Retrieve the current value for a key. Args: key (str): the key whose value should be retrieved default (object): the value to use when no value exist for the key
f11446:c0:m0
def set(self, key, value):
raise NotImplementedError()<EOL>
Set a new value for a given key.
f11446:c0:m1
def mget(self, *keys, **kwargs):
default = kwargs.get('<STR_LIT:default>')<EOL>coherent = kwargs.get('<STR_LIT>', False)<EOL>for key in keys:<EOL><INDENT>yield self.get(key, default=default)<EOL><DEDENT>
Retrieve values for a set of keys. Args: keys (str list): the list of keys whose value should be retrieved Keyword arguements: default (object): the value to use for non-existent keys coherent (bool): whether all fetched values should be "coherent", ...
f11446:c0:m2
def mset(self, values):
for key, value in values.items():<EOL><INDENT>self.set(key, value)<EOL><DEDENT>
Set the value of several keys at once. Args: values (dict): maps a key to its value.
f11446:c0:m3
def incr(self, key, amount, default=<NUM_LIT:0>):
old_value = self.get(key, default)<EOL>self.set(key, old_value + amount)<EOL>return old_value + amount<EOL>
Increment the value of a key by a given amount. Also works for decrementing it. Args: key (str): the key whose value should be incremented amount (int): the amount by which the value should be incremented default (int): the default value to use if the key was never ...
f11446:c0:m4
@property<EOL><INDENT>def key_amount(self):<DEDENT>
return '<STR_LIT>' % (self.key, '<STR_LIT>')<EOL>
Name of the key used to store the current amount.
f11447:c0:m1
@property<EOL><INDENT>def key_last_leak(self):<DEDENT>
return '<STR_LIT>' % (self.key, '<STR_LIT>')<EOL>
Name of the key used to store the time of the last leak.
f11447:c0:m2
def leak(self):
capacity, last_leak = self.storage.mget(self.key_amount, self.key_last_leak,<EOL>coherent=True)<EOL>now = time.time()<EOL>if last_leak:<EOL><INDENT>elapsed = now - last_leak<EOL>decrement = elapsed * self.rate<EOL>new_capacity = max(int(capacity - decrement), <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>new_capacity = <N...
Leak the adequate amount of data from the bucket. This should be called before any consumption takes place. Returns: int: the new capacity of the bucket
f11447:c0:m3
def _incr(self, amount):
self.storage.incr(self.key_amount, amount)<EOL>
Handle an atomic increment to the bucket.
f11447:c0:m4
def consume(self, amount=<NUM_LIT:1>):
<EOL>current = self.leak()<EOL>if current + amount > self.capacity:<EOL><INDENT>return False<EOL><DEDENT>self._incr(amount)<EOL>return True<EOL>
Consume one or more units from the bucket.
f11447:c0:m5
def get_bucket(self, key, rate=None, capacity=None, **kwargs):
return buckets.Bucket(<EOL>key=key,<EOL>rate=rate or self.rate,<EOL>capacity=capacity or self.capacity,<EOL>storate=self.storate,<EOL>**kwargs)<EOL>
Fetch a Bucket for the given key. rate and capacity might be overridden from the Throttler defaults. Args: rate (float): Units regenerated by second, or None to keep Throttler defaults capacity (int): Maximum units available, or None to keep Throttler ...
f11448:c1:m1
def consume(self, key, amount=<NUM_LIT:1>, rate=None, capacity=None, **kwargs):
bucket = self.get_bucket(key, rate, capacity, **kwargs)<EOL>return bucket.consume(amount)<EOL>
Consume an amount for a given key. Non-default rate/capacity can be given to override Throttler defaults. Returns: bool: whether the units could be consumed
f11448:c1:m2
def throttle(self, key, amount=<NUM_LIT:1>, rate=None, capacity=None,<EOL>exc_class=Throttled, **kwargs):
if not self.consume(key, amount, rate, capacity, **kwargs):<EOL><INDENT>raise exc_class("<STR_LIT>"<EOL>% (amount, key))<EOL><DEDENT>
Consume an amount for a given key, or raise a Throttled exception.
f11448:c1:m3