partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
valid
LockType.acquire
Dummy implementation of acquire(). For blocking calls, self.locked_status is automatically set to True and returned appropriately based on value of ``waitflag``. If it is non-blocking, then the value is actually checked and not set if it is already acquired. This is all done so that threading.Condition's assert statements aren't triggered and throw a little fit.
third_party/stdlib/dummy_thread.py
def acquire(self, waitflag=None): """Dummy implementation of acquire(). For blocking calls, self.locked_status is automatically set to True and returned appropriately based on value of ``waitflag``. If it is non-blocking, then the value is actually checked and not set if it is already acquired. This is all done so that threading.Condition's assert statements aren't triggered and throw a little fit. """ if waitflag is None or waitflag: self.locked_status = True return True else: if not self.locked_status: self.locked_status = True return True else: return False
def acquire(self, waitflag=None): """Dummy implementation of acquire(). For blocking calls, self.locked_status is automatically set to True and returned appropriately based on value of ``waitflag``. If it is non-blocking, then the value is actually checked and not set if it is already acquired. This is all done so that threading.Condition's assert statements aren't triggered and throw a little fit. """ if waitflag is None or waitflag: self.locked_status = True return True else: if not self.locked_status: self.locked_status = True return True else: return False
[ "Dummy", "implementation", "of", "acquire", "()", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/dummy_thread.py#L95-L114
[ "def", "acquire", "(", "self", ",", "waitflag", "=", "None", ")", ":", "if", "waitflag", "is", "None", "or", "waitflag", ":", "self", ".", "locked_status", "=", "True", "return", "True", "else", ":", "if", "not", "self", ".", "locked_status", ":", "sel...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
round_to_nearest
Python 3 style round: round a float x to the nearest int, but unlike the builtin Python 2.x round function: - return an int, not a float - do round-half-to-even, not round-half-away-from-zero. We assume that x is finite and nonnegative; except wrong results if you use this for negative x.
third_party/pypy/_struct.py
def round_to_nearest(x): """Python 3 style round: round a float x to the nearest int, but unlike the builtin Python 2.x round function: - return an int, not a float - do round-half-to-even, not round-half-away-from-zero. We assume that x is finite and nonnegative; except wrong results if you use this for negative x. """ int_part = int(x) frac_part = x - int_part if frac_part > 0.5 or frac_part == 0.5 and int_part & 1 == 1: int_part += 1 return int_part
def round_to_nearest(x): """Python 3 style round: round a float x to the nearest int, but unlike the builtin Python 2.x round function: - return an int, not a float - do round-half-to-even, not round-half-away-from-zero. We assume that x is finite and nonnegative; except wrong results if you use this for negative x. """ int_part = int(x) frac_part = x - int_part if frac_part > 0.5 or frac_part == 0.5 and int_part & 1 == 1: int_part += 1 return int_part
[ "Python", "3", "style", "round", ":", "round", "a", "float", "x", "to", "the", "nearest", "int", "but", "unlike", "the", "builtin", "Python", "2", ".", "x", "round", "function", ":" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/_struct.py#L144-L159
[ "def", "round_to_nearest", "(", "x", ")", ":", "int_part", "=", "int", "(", "x", ")", "frac_part", "=", "x", "-", "int_part", "if", "frac_part", ">", "0.5", "or", "frac_part", "==", "0.5", "and", "int_part", "&", "1", "==", "1", ":", "int_part", "+="...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
float_unpack
Convert a 32-bit or 64-bit integer created by float_pack into a Python float.
third_party/pypy/_struct.py
def float_unpack(Q, size, le): """Convert a 32-bit or 64-bit integer created by float_pack into a Python float.""" if size == 8: MIN_EXP = -1021 # = sys.float_info.min_exp MAX_EXP = 1024 # = sys.float_info.max_exp MANT_DIG = 53 # = sys.float_info.mant_dig BITS = 64 elif size == 4: MIN_EXP = -125 # C's FLT_MIN_EXP MAX_EXP = 128 # FLT_MAX_EXP MANT_DIG = 24 # FLT_MANT_DIG BITS = 32 else: raise ValueError("invalid size value") if Q >> BITS: raise ValueError("input out of range") # extract pieces sign = Q >> BITS - 1 exp = (Q & ((1 << BITS - 1) - (1 << MANT_DIG - 1))) >> MANT_DIG - 1 mant = Q & ((1 << MANT_DIG - 1) - 1) if exp == MAX_EXP - MIN_EXP + 2: # nan or infinity result = float('nan') if mant else float('inf') elif exp == 0: # subnormal or zero result = math.ldexp(float(mant), MIN_EXP - MANT_DIG) else: # normal mant += 1 << MANT_DIG - 1 result = math.ldexp(float(mant), exp + MIN_EXP - MANT_DIG - 1) return -result if sign else result
def float_unpack(Q, size, le): """Convert a 32-bit or 64-bit integer created by float_pack into a Python float.""" if size == 8: MIN_EXP = -1021 # = sys.float_info.min_exp MAX_EXP = 1024 # = sys.float_info.max_exp MANT_DIG = 53 # = sys.float_info.mant_dig BITS = 64 elif size == 4: MIN_EXP = -125 # C's FLT_MIN_EXP MAX_EXP = 128 # FLT_MAX_EXP MANT_DIG = 24 # FLT_MANT_DIG BITS = 32 else: raise ValueError("invalid size value") if Q >> BITS: raise ValueError("input out of range") # extract pieces sign = Q >> BITS - 1 exp = (Q & ((1 << BITS - 1) - (1 << MANT_DIG - 1))) >> MANT_DIG - 1 mant = Q & ((1 << MANT_DIG - 1) - 1) if exp == MAX_EXP - MIN_EXP + 2: # nan or infinity result = float('nan') if mant else float('inf') elif exp == 0: # subnormal or zero result = math.ldexp(float(mant), MIN_EXP - MANT_DIG) else: # normal mant += 1 << MANT_DIG - 1 result = math.ldexp(float(mant), exp + MIN_EXP - MANT_DIG - 1) return -result if sign else result
[ "Convert", "a", "32", "-", "bit", "or", "64", "-", "bit", "integer", "created", "by", "float_pack", "into", "a", "Python", "float", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/_struct.py#L162-L197
[ "def", "float_unpack", "(", "Q", ",", "size", ",", "le", ")", ":", "if", "size", "==", "8", ":", "MIN_EXP", "=", "-", "1021", "# = sys.float_info.min_exp", "MAX_EXP", "=", "1024", "# = sys.float_info.max_exp", "MANT_DIG", "=", "53", "# = sys.float_info.mant_dig"...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
float_pack
Convert a Python float x into a 64-bit unsigned integer with the same byte representation.
third_party/pypy/_struct.py
def float_pack(x, size): """Convert a Python float x into a 64-bit unsigned integer with the same byte representation.""" if size == 8: MIN_EXP = -1021 # = sys.float_info.min_exp MAX_EXP = 1024 # = sys.float_info.max_exp MANT_DIG = 53 # = sys.float_info.mant_dig BITS = 64 elif size == 4: MIN_EXP = -125 # C's FLT_MIN_EXP MAX_EXP = 128 # FLT_MAX_EXP MANT_DIG = 24 # FLT_MANT_DIG BITS = 32 else: raise ValueError("invalid size value") sign = math.copysign(1.0, x) < 0.0 if math.isinf(x): mant = 0 exp = MAX_EXP - MIN_EXP + 2 elif math.isnan(x): mant = 1 << (MANT_DIG - 2) # other values possible exp = MAX_EXP - MIN_EXP + 2 elif x == 0.0: mant = 0 exp = 0 else: m, e = math.frexp(abs(x)) # abs(x) == m * 2**e exp = e - (MIN_EXP - 1) if exp > 0: # Normal case. mant = round_to_nearest(m * (1 << MANT_DIG)) mant -= 1 << MANT_DIG - 1 else: # Subnormal case. if exp + MANT_DIG - 1 >= 0: mant = round_to_nearest(m * (1 << exp + MANT_DIG - 1)) else: mant = 0 exp = 0 # Special case: rounding produced a MANT_DIG-bit mantissa. assert 0 <= mant <= 1 << MANT_DIG - 1 if mant == 1 << MANT_DIG - 1: mant = 0 exp += 1 # Raise on overflow (in some circumstances, may want to return # infinity instead). if exp >= MAX_EXP - MIN_EXP + 2: raise OverflowError("float too large to pack in this format") # check constraints assert 0 <= mant < 1 << MANT_DIG - 1 assert 0 <= exp <= MAX_EXP - MIN_EXP + 2 assert 0 <= sign <= 1 return ((sign << BITS - 1) | (exp << MANT_DIG - 1)) | mant
def float_pack(x, size): """Convert a Python float x into a 64-bit unsigned integer with the same byte representation.""" if size == 8: MIN_EXP = -1021 # = sys.float_info.min_exp MAX_EXP = 1024 # = sys.float_info.max_exp MANT_DIG = 53 # = sys.float_info.mant_dig BITS = 64 elif size == 4: MIN_EXP = -125 # C's FLT_MIN_EXP MAX_EXP = 128 # FLT_MAX_EXP MANT_DIG = 24 # FLT_MANT_DIG BITS = 32 else: raise ValueError("invalid size value") sign = math.copysign(1.0, x) < 0.0 if math.isinf(x): mant = 0 exp = MAX_EXP - MIN_EXP + 2 elif math.isnan(x): mant = 1 << (MANT_DIG - 2) # other values possible exp = MAX_EXP - MIN_EXP + 2 elif x == 0.0: mant = 0 exp = 0 else: m, e = math.frexp(abs(x)) # abs(x) == m * 2**e exp = e - (MIN_EXP - 1) if exp > 0: # Normal case. mant = round_to_nearest(m * (1 << MANT_DIG)) mant -= 1 << MANT_DIG - 1 else: # Subnormal case. if exp + MANT_DIG - 1 >= 0: mant = round_to_nearest(m * (1 << exp + MANT_DIG - 1)) else: mant = 0 exp = 0 # Special case: rounding produced a MANT_DIG-bit mantissa. assert 0 <= mant <= 1 << MANT_DIG - 1 if mant == 1 << MANT_DIG - 1: mant = 0 exp += 1 # Raise on overflow (in some circumstances, may want to return # infinity instead). if exp >= MAX_EXP - MIN_EXP + 2: raise OverflowError("float too large to pack in this format") # check constraints assert 0 <= mant < 1 << MANT_DIG - 1 assert 0 <= exp <= MAX_EXP - MIN_EXP + 2 assert 0 <= sign <= 1 return ((sign << BITS - 1) | (exp << MANT_DIG - 1)) | mant
[ "Convert", "a", "Python", "float", "x", "into", "a", "64", "-", "bit", "unsigned", "integer", "with", "the", "same", "byte", "representation", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/_struct.py#L200-L257
[ "def", "float_pack", "(", "x", ",", "size", ")", ":", "if", "size", "==", "8", ":", "MIN_EXP", "=", "-", "1021", "# = sys.float_info.min_exp", "MAX_EXP", "=", "1024", "# = sys.float_info.max_exp", "MANT_DIG", "=", "53", "# = sys.float_info.mant_dig", "BITS", "="...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
calcsize
calcsize(fmt) -> int Return size of C struct described by format string fmt. See struct.__doc__ for more on format strings.
third_party/pypy/_struct.py
def calcsize(fmt): """calcsize(fmt) -> int Return size of C struct described by format string fmt. See struct.__doc__ for more on format strings.""" formatdef, endianness, i = getmode(fmt) num = 0 result = 0 while i < len(fmt): num, i = getNum(fmt, i) cur = fmt[i] try: format = formatdef[cur] except KeyError: raise StructError("%s is not a valid format" % cur) if num != None: result += num * format['size'] else: result += format['size'] num = 0 i += 1 return result
def calcsize(fmt): """calcsize(fmt) -> int Return size of C struct described by format string fmt. See struct.__doc__ for more on format strings.""" formatdef, endianness, i = getmode(fmt) num = 0 result = 0 while i < len(fmt): num, i = getNum(fmt, i) cur = fmt[i] try: format = formatdef[cur] except KeyError: raise StructError("%s is not a valid format" % cur) if num != None: result += num * format['size'] else: result += format['size'] num = 0 i += 1 return result
[ "calcsize", "(", "fmt", ")", "-", ">", "int", "Return", "size", "of", "C", "struct", "described", "by", "format", "string", "fmt", ".", "See", "struct", ".", "__doc__", "for", "more", "on", "format", "strings", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/_struct.py#L310-L331
[ "def", "calcsize", "(", "fmt", ")", ":", "formatdef", ",", "endianness", ",", "i", "=", "getmode", "(", "fmt", ")", "num", "=", "0", "result", "=", "0", "while", "i", "<", "len", "(", "fmt", ")", ":", "num", ",", "i", "=", "getNum", "(", "fmt",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
pack
pack(fmt, v1, v2, ...) -> string Return string containing values v1, v2, ... packed according to fmt. See struct.__doc__ for more on format strings.
third_party/pypy/_struct.py
def pack(fmt, *args): """pack(fmt, v1, v2, ...) -> string Return string containing values v1, v2, ... packed according to fmt. See struct.__doc__ for more on format strings.""" formatdef, endianness, i = getmode(fmt) args = list(args) n_args = len(args) result = [] while i < len(fmt): num, i = getNum(fmt, i) cur = fmt[i] try: format = formatdef[cur] except KeyError: raise StructError("%s is not a valid format" % cur) if num == None: num_s = 0 num = 1 else: num_s = num if cur == 'x': result += [b'\0' * num] elif cur == 's': if isinstance(args[0], bytes): padding = num - len(args[0]) result += [args[0][:num] + b'\0' * padding] args.pop(0) else: raise StructError("arg for string format not a string") elif cur == 'p': if isinstance(args[0], bytes): padding = num - len(args[0]) - 1 if padding > 0: result += [bytes([len(args[0])]) + args[0] [:num - 1] + b'\0' * padding] else: if num < 255: result += [bytes([num - 1]) + args[0][:num - 1]] else: result += [bytes([255]) + args[0][:num - 1]] args.pop(0) else: raise StructError("arg for string format not a string") else: if len(args) < num: raise StructError("insufficient arguments to pack") for var in args[:num]: result += [format['pack'](var, format['size'], endianness)] args = args[num:] num = None i += 1 if len(args) != 0: raise StructError("too many arguments for pack format") return b''.join(result)
def pack(fmt, *args): """pack(fmt, v1, v2, ...) -> string Return string containing values v1, v2, ... packed according to fmt. See struct.__doc__ for more on format strings.""" formatdef, endianness, i = getmode(fmt) args = list(args) n_args = len(args) result = [] while i < len(fmt): num, i = getNum(fmt, i) cur = fmt[i] try: format = formatdef[cur] except KeyError: raise StructError("%s is not a valid format" % cur) if num == None: num_s = 0 num = 1 else: num_s = num if cur == 'x': result += [b'\0' * num] elif cur == 's': if isinstance(args[0], bytes): padding = num - len(args[0]) result += [args[0][:num] + b'\0' * padding] args.pop(0) else: raise StructError("arg for string format not a string") elif cur == 'p': if isinstance(args[0], bytes): padding = num - len(args[0]) - 1 if padding > 0: result += [bytes([len(args[0])]) + args[0] [:num - 1] + b'\0' * padding] else: if num < 255: result += [bytes([num - 1]) + args[0][:num - 1]] else: result += [bytes([255]) + args[0][:num - 1]] args.pop(0) else: raise StructError("arg for string format not a string") else: if len(args) < num: raise StructError("insufficient arguments to pack") for var in args[:num]: result += [format['pack'](var, format['size'], endianness)] args = args[num:] num = None i += 1 if len(args) != 0: raise StructError("too many arguments for pack format") return b''.join(result)
[ "pack", "(", "fmt", "v1", "v2", "...", ")", "-", ">", "string", "Return", "string", "containing", "values", "v1", "v2", "...", "packed", "according", "to", "fmt", ".", "See", "struct", ".", "__doc__", "for", "more", "on", "format", "strings", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/_struct.py#L334-L390
[ "def", "pack", "(", "fmt", ",", "*", "args", ")", ":", "formatdef", ",", "endianness", ",", "i", "=", "getmode", "(", "fmt", ")", "args", "=", "list", "(", "args", ")", "n_args", "=", "len", "(", "args", ")", "result", "=", "[", "]", "while", "...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
unpack
unpack(fmt, string) -> (v1, v2, ...) Unpack the string, containing packed C structure data, according to fmt. Requires len(string)==calcsize(fmt). See struct.__doc__ for more on format strings.
third_party/pypy/_struct.py
def unpack(fmt, data): """unpack(fmt, string) -> (v1, v2, ...) Unpack the string, containing packed C structure data, according to fmt. Requires len(string)==calcsize(fmt). See struct.__doc__ for more on format strings.""" formatdef, endianness, i = getmode(fmt) j = 0 num = 0 result = [] length = calcsize(fmt) if length != len(data): raise StructError("unpack str size does not match format") while i < len(fmt): num, i = getNum(fmt, i) cur = fmt[i] i += 1 try: format = formatdef[cur] except KeyError: raise StructError("%s is not a valid format" % cur) if not num: num = 1 if cur == 'x': j += num elif cur == 's': result.append(data[j:j + num]) j += num elif cur == 'p': n = data[j] if n >= num: n = num - 1 result.append(data[j + 1:j + n + 1]) j += num else: for n in range(num): result += [format['unpack'](data, j, format['size'], endianness)] j += format['size'] return tuple(result)
def unpack(fmt, data): """unpack(fmt, string) -> (v1, v2, ...) Unpack the string, containing packed C structure data, according to fmt. Requires len(string)==calcsize(fmt). See struct.__doc__ for more on format strings.""" formatdef, endianness, i = getmode(fmt) j = 0 num = 0 result = [] length = calcsize(fmt) if length != len(data): raise StructError("unpack str size does not match format") while i < len(fmt): num, i = getNum(fmt, i) cur = fmt[i] i += 1 try: format = formatdef[cur] except KeyError: raise StructError("%s is not a valid format" % cur) if not num: num = 1 if cur == 'x': j += num elif cur == 's': result.append(data[j:j + num]) j += num elif cur == 'p': n = data[j] if n >= num: n = num - 1 result.append(data[j + 1:j + n + 1]) j += num else: for n in range(num): result += [format['unpack'](data, j, format['size'], endianness)] j += format['size'] return tuple(result)
[ "unpack", "(", "fmt", "string", ")", "-", ">", "(", "v1", "v2", "...", ")", "Unpack", "the", "string", "containing", "packed", "C", "structure", "data", "according", "to", "fmt", ".", "Requires", "len", "(", "string", ")", "==", "calcsize", "(", "fmt",...
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/_struct.py#L393-L433
[ "def", "unpack", "(", "fmt", ",", "data", ")", ":", "formatdef", ",", "endianness", ",", "i", "=", "getmode", "(", "fmt", ")", "j", "=", "0", "num", "=", "0", "result", "=", "[", "]", "length", "=", "calcsize", "(", "fmt", ")", "if", "length", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Diagnostic.render
Returns the human-readable location of the diagnostic in the source, the formatted message, the source line corresponding to ``location`` and a line emphasizing the problematic locations in the source line using ASCII art, as a list of lines. Appends the result of calling :meth:`render` on ``notes``, if any. For example: :: <input>:1:8-9: error: cannot add integer and string x + (1 + "a") ~ ^ ~~~ :param only_line: (bool) If true, only print line number, not line and column range
third_party/pythonparser/diagnostic.py
def render(self, only_line=False, colored=False): """ Returns the human-readable location of the diagnostic in the source, the formatted message, the source line corresponding to ``location`` and a line emphasizing the problematic locations in the source line using ASCII art, as a list of lines. Appends the result of calling :meth:`render` on ``notes``, if any. For example: :: <input>:1:8-9: error: cannot add integer and string x + (1 + "a") ~ ^ ~~~ :param only_line: (bool) If true, only print line number, not line and column range """ source_line = self.location.source_line().rstrip("\n") highlight_line = bytearray(re.sub(r"[^\t]", " ", source_line), "utf-8") for hilight in self.highlights: if hilight.line() == self.location.line(): lft, rgt = hilight.column_range() highlight_line[lft:rgt] = bytearray("~", "utf-8") * (rgt - lft) lft, rgt = self.location.column_range() if rgt == lft: # Expand zero-length ranges to one ^ rgt = lft + 1 highlight_line[lft:rgt] = bytearray("^", "utf-8") * (rgt - lft) if only_line: location = "%s:%s" % (self.location.source_buffer.name, self.location.line()) else: location = str(self.location) notes = list(self.notes) if self.level != "note": expanded_location = self.location.expanded_from while expanded_location is not None: notes.insert(0, Diagnostic("note", "expanded from here", {}, self.location.expanded_from)) expanded_location = expanded_location.expanded_from rendered_notes = reduce(list.__add__, [note.render(only_line, colored) for note in notes], []) if colored: if self.level in ("error", "fatal"): level_color = 31 # red elif self.level == "warning": level_color = 35 # magenta else: # level == "note" level_color = 30 # gray return [ "\x1b[1;37m{}: \x1b[{}m{}:\x1b[37m {}\x1b[0m". format(location, level_color, self.level, self.message()), source_line, "\x1b[1;32m{}\x1b[0m".format(highlight_line.decode("utf-8")) ] + rendered_notes else: return [ "{}: {}: {}".format(location, self.level, self.message()), source_line, highlight_line.decode("utf-8") ] + rendered_notes
def render(self, only_line=False, colored=False): """ Returns the human-readable location of the diagnostic in the source, the formatted message, the source line corresponding to ``location`` and a line emphasizing the problematic locations in the source line using ASCII art, as a list of lines. Appends the result of calling :meth:`render` on ``notes``, if any. For example: :: <input>:1:8-9: error: cannot add integer and string x + (1 + "a") ~ ^ ~~~ :param only_line: (bool) If true, only print line number, not line and column range """ source_line = self.location.source_line().rstrip("\n") highlight_line = bytearray(re.sub(r"[^\t]", " ", source_line), "utf-8") for hilight in self.highlights: if hilight.line() == self.location.line(): lft, rgt = hilight.column_range() highlight_line[lft:rgt] = bytearray("~", "utf-8") * (rgt - lft) lft, rgt = self.location.column_range() if rgt == lft: # Expand zero-length ranges to one ^ rgt = lft + 1 highlight_line[lft:rgt] = bytearray("^", "utf-8") * (rgt - lft) if only_line: location = "%s:%s" % (self.location.source_buffer.name, self.location.line()) else: location = str(self.location) notes = list(self.notes) if self.level != "note": expanded_location = self.location.expanded_from while expanded_location is not None: notes.insert(0, Diagnostic("note", "expanded from here", {}, self.location.expanded_from)) expanded_location = expanded_location.expanded_from rendered_notes = reduce(list.__add__, [note.render(only_line, colored) for note in notes], []) if colored: if self.level in ("error", "fatal"): level_color = 31 # red elif self.level == "warning": level_color = 35 # magenta else: # level == "note" level_color = 30 # gray return [ "\x1b[1;37m{}: \x1b[{}m{}:\x1b[37m {}\x1b[0m". format(location, level_color, self.level, self.message()), source_line, "\x1b[1;32m{}\x1b[0m".format(highlight_line.decode("utf-8")) ] + rendered_notes else: return [ "{}: {}: {}".format(location, self.level, self.message()), source_line, highlight_line.decode("utf-8") ] + rendered_notes
[ "Returns", "the", "human", "-", "readable", "location", "of", "the", "diagnostic", "in", "the", "source", "the", "formatted", "message", "the", "source", "line", "corresponding", "to", "location", "and", "a", "line", "emphasizing", "the", "problematic", "locatio...
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pythonparser/diagnostic.py#L66-L129
[ "def", "render", "(", "self", ",", "only_line", "=", "False", ",", "colored", "=", "False", ")", ":", "source_line", "=", "self", ".", "location", ".", "source_line", "(", ")", ".", "rstrip", "(", "\"\\n\"", ")", "highlight_line", "=", "bytearray", "(", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Engine.process
The default implementation of :meth:`process` renders non-fatal diagnostics to ``sys.stderr``, and raises fatal ones as a :class:`Error`.
third_party/pythonparser/diagnostic.py
def process(self, diagnostic): """ The default implementation of :meth:`process` renders non-fatal diagnostics to ``sys.stderr``, and raises fatal ones as a :class:`Error`. """ diagnostic.notes += self._appended_notes self.render_diagnostic(diagnostic) if diagnostic.level == "fatal" or \ (self.all_errors_are_fatal and diagnostic.level == "error"): raise Error(diagnostic)
def process(self, diagnostic): """ The default implementation of :meth:`process` renders non-fatal diagnostics to ``sys.stderr``, and raises fatal ones as a :class:`Error`. """ diagnostic.notes += self._appended_notes self.render_diagnostic(diagnostic) if diagnostic.level == "fatal" or \ (self.all_errors_are_fatal and diagnostic.level == "error"): raise Error(diagnostic)
[ "The", "default", "implementation", "of", ":", "meth", ":", "process", "renders", "non", "-", "fatal", "diagnostics", "to", "sys", ".", "stderr", "and", "raises", "fatal", "ones", "as", "a", ":", "class", ":", "Error", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pythonparser/diagnostic.py#L156-L165
[ "def", "process", "(", "self", ",", "diagnostic", ")", ":", "diagnostic", ".", "notes", "+=", "self", ".", "_appended_notes", "self", ".", "render_diagnostic", "(", "diagnostic", ")", "if", "diagnostic", ".", "level", "==", "\"fatal\"", "or", "(", "self", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Engine.context
A context manager that appends ``note`` to every diagnostic processed by this engine.
third_party/pythonparser/diagnostic.py
def context(self, *notes): """ A context manager that appends ``note`` to every diagnostic processed by this engine. """ self._appended_notes += notes yield del self._appended_notes[-len(notes):]
def context(self, *notes): """ A context manager that appends ``note`` to every diagnostic processed by this engine. """ self._appended_notes += notes yield del self._appended_notes[-len(notes):]
[ "A", "context", "manager", "that", "appends", "note", "to", "every", "diagnostic", "processed", "by", "this", "engine", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pythonparser/diagnostic.py#L168-L175
[ "def", "context", "(", "self", ",", "*", "notes", ")", ":", "self", ".", "_appended_notes", "+=", "notes", "yield", "del", "self", ".", "_appended_notes", "[", "-", "len", "(", "notes", ")", ":", "]" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
decode
Decode common content-transfer-encodings (base64, quopri, uuencode).
third_party/stdlib/mimetools.py
def decode(input, output, encoding): """Decode common content-transfer-encodings (base64, quopri, uuencode).""" if encoding == 'base64': import base64 return base64.decode(input, output) if encoding == 'quoted-printable': import quopri return quopri.decode(input, output) if encoding in ('uuencode', 'x-uuencode', 'uue', 'x-uue'): import uu return uu.decode(input, output) if encoding in ('7bit', '8bit'): return output.write(input.read()) if encoding in decodetab: pipethrough(input, decodetab[encoding], output) else: raise ValueError, \ 'unknown Content-Transfer-Encoding: %s' % encoding
def decode(input, output, encoding): """Decode common content-transfer-encodings (base64, quopri, uuencode).""" if encoding == 'base64': import base64 return base64.decode(input, output) if encoding == 'quoted-printable': import quopri return quopri.decode(input, output) if encoding in ('uuencode', 'x-uuencode', 'uue', 'x-uue'): import uu return uu.decode(input, output) if encoding in ('7bit', '8bit'): return output.write(input.read()) if encoding in decodetab: pipethrough(input, decodetab[encoding], output) else: raise ValueError, \ 'unknown Content-Transfer-Encoding: %s' % encoding
[ "Decode", "common", "content", "-", "transfer", "-", "encodings", "(", "base64", "quopri", "uuencode", ")", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/mimetools.py#L157-L174
[ "def", "decode", "(", "input", ",", "output", ",", "encoding", ")", ":", "if", "encoding", "==", "'base64'", ":", "import", "base64", "return", "base64", ".", "decode", "(", "input", ",", "output", ")", "if", "encoding", "==", "'quoted-printable'", ":", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
encode
Encode common content-transfer-encodings (base64, quopri, uuencode).
third_party/stdlib/mimetools.py
def encode(input, output, encoding): """Encode common content-transfer-encodings (base64, quopri, uuencode).""" if encoding == 'base64': import base64 return base64.encode(input, output) if encoding == 'quoted-printable': import quopri return quopri.encode(input, output, 0) if encoding in ('uuencode', 'x-uuencode', 'uue', 'x-uue'): import uu return uu.encode(input, output) if encoding in ('7bit', '8bit'): return output.write(input.read()) if encoding in encodetab: pipethrough(input, encodetab[encoding], output) else: raise ValueError, \ 'unknown Content-Transfer-Encoding: %s' % encoding
def encode(input, output, encoding): """Encode common content-transfer-encodings (base64, quopri, uuencode).""" if encoding == 'base64': import base64 return base64.encode(input, output) if encoding == 'quoted-printable': import quopri return quopri.encode(input, output, 0) if encoding in ('uuencode', 'x-uuencode', 'uue', 'x-uue'): import uu return uu.encode(input, output) if encoding in ('7bit', '8bit'): return output.write(input.read()) if encoding in encodetab: pipethrough(input, encodetab[encoding], output) else: raise ValueError, \ 'unknown Content-Transfer-Encoding: %s' % encoding
[ "Encode", "common", "content", "-", "transfer", "-", "encodings", "(", "base64", "quopri", "uuencode", ")", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/mimetools.py#L176-L193
[ "def", "encode", "(", "input", ",", "output", ",", "encoding", ")", ":", "if", "encoding", "==", "'base64'", ":", "import", "base64", "return", "base64", ".", "encode", "(", "input", ",", "output", ")", "if", "encoding", "==", "'quoted-printable'", ":", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
print_list
Print the list of tuples as returned by extract_tb() or extract_stack() as a formatted stack trace to the given file.
third_party/stdlib/traceback.py
def print_list(extracted_list, file=None): """Print the list of tuples as returned by extract_tb() or extract_stack() as a formatted stack trace to the given file.""" if file is None: file = sys.stderr for filename, lineno, name, line in extracted_list: _print(file, ' File "%s", line %d, in %s' % (filename,lineno,name)) if line: _print(file, ' %s' % line.strip())
def print_list(extracted_list, file=None): """Print the list of tuples as returned by extract_tb() or extract_stack() as a formatted stack trace to the given file.""" if file is None: file = sys.stderr for filename, lineno, name, line in extracted_list: _print(file, ' File "%s", line %d, in %s' % (filename,lineno,name)) if line: _print(file, ' %s' % line.strip())
[ "Print", "the", "list", "of", "tuples", "as", "returned", "by", "extract_tb", "()", "or", "extract_stack", "()", "as", "a", "formatted", "stack", "trace", "to", "the", "given", "file", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L16-L25
[ "def", "print_list", "(", "extracted_list", ",", "file", "=", "None", ")", ":", "if", "file", "is", "None", ":", "file", "=", "sys", ".", "stderr", "for", "filename", ",", "lineno", ",", "name", ",", "line", "in", "extracted_list", ":", "_print", "(", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
format_list
Format a list of traceback entry tuples for printing. Given a list of tuples as returned by extract_tb() or extract_stack(), return a list of strings ready for printing. Each string in the resulting list corresponds to the item with the same index in the argument list. Each string ends in a newline; the strings may contain internal newlines as well, for those items whose source text line is not None.
third_party/stdlib/traceback.py
def format_list(extracted_list): """Format a list of traceback entry tuples for printing. Given a list of tuples as returned by extract_tb() or extract_stack(), return a list of strings ready for printing. Each string in the resulting list corresponds to the item with the same index in the argument list. Each string ends in a newline; the strings may contain internal newlines as well, for those items whose source text line is not None. """ list = [] for filename, lineno, name, line in extracted_list: item = ' File "%s", line %d, in %s\n' % (filename,lineno,name) if line: item = item + ' %s\n' % line.strip() list.append(item) return list
def format_list(extracted_list): """Format a list of traceback entry tuples for printing. Given a list of tuples as returned by extract_tb() or extract_stack(), return a list of strings ready for printing. Each string in the resulting list corresponds to the item with the same index in the argument list. Each string ends in a newline; the strings may contain internal newlines as well, for those items whose source text line is not None. """ list = [] for filename, lineno, name, line in extracted_list: item = ' File "%s", line %d, in %s\n' % (filename,lineno,name) if line: item = item + ' %s\n' % line.strip() list.append(item) return list
[ "Format", "a", "list", "of", "traceback", "entry", "tuples", "for", "printing", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L27-L43
[ "def", "format_list", "(", "extracted_list", ")", ":", "list", "=", "[", "]", "for", "filename", ",", "lineno", ",", "name", ",", "line", "in", "extracted_list", ":", "item", "=", "' File \"%s\", line %d, in %s\\n'", "%", "(", "filename", ",", "lineno", ","...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
print_tb
Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method.
third_party/stdlib/traceback.py
def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. """ if file is None: file = sys.stderr if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name _print(file, ' File "%s", line %d, in %s' % (filename, lineno, name)) linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: _print(file, ' ' + line.strip()) tb = tb.tb_next n = n+1
def print_tb(tb, limit=None, file=None): """Print up to 'limit' stack trace entries from the traceback 'tb'. If 'limit' is omitted or None, all entries are printed. If 'file' is omitted or None, the output goes to sys.stderr; otherwise 'file' should be an open file or file-like object with a write() method. """ if file is None: file = sys.stderr if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit n = 0 while tb is not None and (limit is None or n < limit): f = tb.tb_frame lineno = tb.tb_lineno co = f.f_code filename = co.co_filename name = co.co_name _print(file, ' File "%s", line %d, in %s' % (filename, lineno, name)) linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: _print(file, ' ' + line.strip()) tb = tb.tb_next n = n+1
[ "Print", "up", "to", "limit", "stack", "trace", "entries", "from", "the", "traceback", "tb", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L46-L72
[ "def", "print_tb", "(", "tb", ",", "limit", "=", "None", ",", "file", "=", "None", ")", ":", "if", "file", "is", "None", ":", "file", "=", "sys", ".", "stderr", "if", "limit", "is", "None", ":", "if", "hasattr", "(", "sys", ",", "'tracebacklimit'",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
print_exception
Print exception up to 'limit' stack trace entries from 'tb' to 'file'. This differs from print_tb() in the following ways: (1) if traceback is not None, it prints a header "Traceback (most recent call last):"; (2) it prints the exception type and value after the stack trace; (3) if type is SyntaxError and value has the appropriate format, it prints the line where the syntax error occurred with a caret on the next line indicating the approximate position of the error.
third_party/stdlib/traceback.py
def print_exception(etype, value, tb, limit=None, file=None): """Print exception up to 'limit' stack trace entries from 'tb' to 'file'. This differs from print_tb() in the following ways: (1) if traceback is not None, it prints a header "Traceback (most recent call last):"; (2) it prints the exception type and value after the stack trace; (3) if type is SyntaxError and value has the appropriate format, it prints the line where the syntax error occurred with a caret on the next line indicating the approximate position of the error. """ if file is None: # TODO: Use sys.stderr when that's implemented. file = open('/dev/stderr', 'w') #file = sys.stderr if tb: _print(file, 'Traceback (most recent call last):') print_tb(tb, limit, file) lines = format_exception_only(etype, value) for line in lines: _print(file, line, '')
def print_exception(etype, value, tb, limit=None, file=None): """Print exception up to 'limit' stack trace entries from 'tb' to 'file'. This differs from print_tb() in the following ways: (1) if traceback is not None, it prints a header "Traceback (most recent call last):"; (2) it prints the exception type and value after the stack trace; (3) if type is SyntaxError and value has the appropriate format, it prints the line where the syntax error occurred with a caret on the next line indicating the approximate position of the error. """ if file is None: # TODO: Use sys.stderr when that's implemented. file = open('/dev/stderr', 'w') #file = sys.stderr if tb: _print(file, 'Traceback (most recent call last):') print_tb(tb, limit, file) lines = format_exception_only(etype, value) for line in lines: _print(file, line, '')
[ "Print", "exception", "up", "to", "limit", "stack", "trace", "entries", "from", "tb", "to", "file", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L110-L130
[ "def", "print_exception", "(", "etype", ",", "value", ",", "tb", ",", "limit", "=", "None", ",", "file", "=", "None", ")", ":", "if", "file", "is", "None", ":", "# TODO: Use sys.stderr when that's implemented.", "file", "=", "open", "(", "'/dev/stderr'", ","...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
format_exception
Format a stack trace and the exception information. The arguments have the same meaning as the corresponding arguments to print_exception(). The return value is a list of strings, each ending in a newline and some containing internal newlines. When these lines are concatenated and printed, exactly the same text is printed as does print_exception().
third_party/stdlib/traceback.py
def format_exception(etype, value, tb, limit = None): """Format a stack trace and the exception information. The arguments have the same meaning as the corresponding arguments to print_exception(). The return value is a list of strings, each ending in a newline and some containing internal newlines. When these lines are concatenated and printed, exactly the same text is printed as does print_exception(). """ if tb: list = ['Traceback (most recent call last):\n'] list = list + format_tb(tb, limit) else: list = [] list = list + format_exception_only(etype, value) return list
def format_exception(etype, value, tb, limit = None): """Format a stack trace and the exception information. The arguments have the same meaning as the corresponding arguments to print_exception(). The return value is a list of strings, each ending in a newline and some containing internal newlines. When these lines are concatenated and printed, exactly the same text is printed as does print_exception(). """ if tb: list = ['Traceback (most recent call last):\n'] list = list + format_tb(tb, limit) else: list = [] list = list + format_exception_only(etype, value) return list
[ "Format", "a", "stack", "trace", "and", "the", "exception", "information", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L132-L147
[ "def", "format_exception", "(", "etype", ",", "value", ",", "tb", ",", "limit", "=", "None", ")", ":", "if", "tb", ":", "list", "=", "[", "'Traceback (most recent call last):\\n'", "]", "list", "=", "list", "+", "format_tb", "(", "tb", ",", "limit", ")",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
format_exception_only
Format the exception part of a traceback. The arguments are the exception type and value such as given by sys.last_type and sys.last_value. The return value is a list of strings, each ending in a newline. Normally, the list contains a single string; however, for SyntaxError exceptions, it contains several lines that (when printed) display detailed information about where the syntax error occurred. The message indicating which exception occurred is always the last string in the list.
third_party/stdlib/traceback.py
def format_exception_only(etype, value): """Format the exception part of a traceback. The arguments are the exception type and value such as given by sys.last_type and sys.last_value. The return value is a list of strings, each ending in a newline. Normally, the list contains a single string; however, for SyntaxError exceptions, it contains several lines that (when printed) display detailed information about where the syntax error occurred. The message indicating which exception occurred is always the last string in the list. """ # An instance should not have a meaningful value parameter, but # sometimes does, particularly for string exceptions, such as # >>> raise string1, string2 # deprecated # # Clear these out first because issubtype(string1, SyntaxError) # would raise another exception and mask the original problem. if (isinstance(etype, BaseException) or # isinstance(etype, types.InstanceType) or etype is None or type(etype) is str): return [_format_final_exc_line(etype, value)] stype = etype.__name__ if not issubclass(etype, SyntaxError): return [_format_final_exc_line(stype, value)] # It was a syntax error; show exactly where the problem was found. lines = [] try: msg, (filename, lineno, offset, badline) = value.args except Exception: pass else: filename = filename or "<string>" lines.append(' File "%s", line %d\n' % (filename, lineno)) if badline is not None: lines.append(' %s\n' % badline.strip()) if offset is not None: caretspace = badline.rstrip('\n') offset = min(len(caretspace), offset) - 1 caretspace = caretspace[:offset].lstrip() # non-space whitespace (likes tabs) must be kept for alignment caretspace = ((c.isspace() and c or ' ') for c in caretspace) lines.append(' %s^\n' % ''.join(caretspace)) value = msg lines.append(_format_final_exc_line(stype, value)) return lines
def format_exception_only(etype, value): """Format the exception part of a traceback. The arguments are the exception type and value such as given by sys.last_type and sys.last_value. The return value is a list of strings, each ending in a newline. Normally, the list contains a single string; however, for SyntaxError exceptions, it contains several lines that (when printed) display detailed information about where the syntax error occurred. The message indicating which exception occurred is always the last string in the list. """ # An instance should not have a meaningful value parameter, but # sometimes does, particularly for string exceptions, such as # >>> raise string1, string2 # deprecated # # Clear these out first because issubtype(string1, SyntaxError) # would raise another exception and mask the original problem. if (isinstance(etype, BaseException) or # isinstance(etype, types.InstanceType) or etype is None or type(etype) is str): return [_format_final_exc_line(etype, value)] stype = etype.__name__ if not issubclass(etype, SyntaxError): return [_format_final_exc_line(stype, value)] # It was a syntax error; show exactly where the problem was found. lines = [] try: msg, (filename, lineno, offset, badline) = value.args except Exception: pass else: filename = filename or "<string>" lines.append(' File "%s", line %d\n' % (filename, lineno)) if badline is not None: lines.append(' %s\n' % badline.strip()) if offset is not None: caretspace = badline.rstrip('\n') offset = min(len(caretspace), offset) - 1 caretspace = caretspace[:offset].lstrip() # non-space whitespace (likes tabs) must be kept for alignment caretspace = ((c.isspace() and c or ' ') for c in caretspace) lines.append(' %s^\n' % ''.join(caretspace)) value = msg lines.append(_format_final_exc_line(stype, value)) return lines
[ "Format", "the", "exception", "part", "of", "a", "traceback", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L149-L203
[ "def", "format_exception_only", "(", "etype", ",", "value", ")", ":", "# An instance should not have a meaningful value parameter, but", "# sometimes does, particularly for string exceptions, such as", "# >>> raise string1, string2 # deprecated", "#", "# Clear these out first because issubt...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
_format_final_exc_line
Return a list of a single line -- normal case for format_exception_only
third_party/stdlib/traceback.py
def _format_final_exc_line(etype, value): """Return a list of a single line -- normal case for format_exception_only""" valuestr = _some_str(value) if value is None or not valuestr: line = "%s\n" % etype else: line = "%s: %s\n" % (etype, valuestr) return line
def _format_final_exc_line(etype, value): """Return a list of a single line -- normal case for format_exception_only""" valuestr = _some_str(value) if value is None or not valuestr: line = "%s\n" % etype else: line = "%s: %s\n" % (etype, valuestr) return line
[ "Return", "a", "list", "of", "a", "single", "line", "--", "normal", "case", "for", "format_exception_only" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L205-L212
[ "def", "_format_final_exc_line", "(", "etype", ",", "value", ")", ":", "valuestr", "=", "_some_str", "(", "value", ")", "if", "value", "is", "None", "or", "not", "valuestr", ":", "line", "=", "\"%s\\n\"", "%", "etype", "else", ":", "line", "=", "\"%s: %s...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
print_exc
Shorthand for 'print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)'. (In fact, it uses sys.exc_info() to retrieve the same information in a thread-safe way.)
third_party/stdlib/traceback.py
def print_exc(limit=None, file=None): """Shorthand for 'print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)'. (In fact, it uses sys.exc_info() to retrieve the same information in a thread-safe way.)""" if file is None: # TODO: Use sys.stderr when that's implemented. file = open('/dev/stderr', 'w') #file = sys.stderr try: etype, value, tb = sys.exc_info() print_exception(etype, value, tb, limit, file) finally: etype = value = tb = None
def print_exc(limit=None, file=None): """Shorthand for 'print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)'. (In fact, it uses sys.exc_info() to retrieve the same information in a thread-safe way.)""" if file is None: # TODO: Use sys.stderr when that's implemented. file = open('/dev/stderr', 'w') #file = sys.stderr try: etype, value, tb = sys.exc_info() print_exception(etype, value, tb, limit, file) finally: etype = value = tb = None
[ "Shorthand", "for", "print_exception", "(", "sys", ".", "exc_type", "sys", ".", "exc_value", "sys", ".", "exc_traceback", "limit", "file", ")", ".", "(", "In", "fact", "it", "uses", "sys", ".", "exc_info", "()", "to", "retrieve", "the", "same", "informatio...
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L227-L239
[ "def", "print_exc", "(", "limit", "=", "None", ",", "file", "=", "None", ")", ":", "if", "file", "is", "None", ":", "# TODO: Use sys.stderr when that's implemented.", "file", "=", "open", "(", "'/dev/stderr'", ",", "'w'", ")", "#file = sys.stderr", "try", ":",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
print_last
This is a shorthand for 'print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)'.
third_party/stdlib/traceback.py
def print_last(limit=None, file=None): """This is a shorthand for 'print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)'.""" if not hasattr(sys, "last_type"): raise ValueError("no last exception") if file is None: file = sys.stderr print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)
def print_last(limit=None, file=None): """This is a shorthand for 'print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)'.""" if not hasattr(sys, "last_type"): raise ValueError("no last exception") if file is None: file = sys.stderr print_exception(sys.last_type, sys.last_value, sys.last_traceback, limit, file)
[ "This", "is", "a", "shorthand", "for", "print_exception", "(", "sys", ".", "last_type", "sys", ".", "last_value", "sys", ".", "last_traceback", "limit", "file", ")", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L251-L259
[ "def", "print_last", "(", "limit", "=", "None", ",", "file", "=", "None", ")", ":", "if", "not", "hasattr", "(", "sys", ",", "\"last_type\"", ")", ":", "raise", "ValueError", "(", "\"no last exception\"", ")", "if", "file", "is", "None", ":", "file", "...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
print_stack
Print a stack trace from its invocation point. The optional 'f' argument can be used to specify an alternate stack frame at which to start. The optional 'limit' and 'file' arguments have the same meaning as for print_exception().
third_party/stdlib/traceback.py
def print_stack(f=None, limit=None, file=None): """Print a stack trace from its invocation point. The optional 'f' argument can be used to specify an alternate stack frame at which to start. The optional 'limit' and 'file' arguments have the same meaning as for print_exception(). """ if f is None: try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame.f_back print_list(extract_stack(f, limit), file)
def print_stack(f=None, limit=None, file=None): """Print a stack trace from its invocation point. The optional 'f' argument can be used to specify an alternate stack frame at which to start. The optional 'limit' and 'file' arguments have the same meaning as for print_exception(). """ if f is None: try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame.f_back print_list(extract_stack(f, limit), file)
[ "Print", "a", "stack", "trace", "from", "its", "invocation", "point", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L262-L274
[ "def", "print_stack", "(", "f", "=", "None", ",", "limit", "=", "None", ",", "file", "=", "None", ")", ":", "if", "f", "is", "None", ":", "try", ":", "raise", "ZeroDivisionError", "except", "ZeroDivisionError", ":", "f", "=", "sys", ".", "exc_info", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
format_stack
Shorthand for 'format_list(extract_stack(f, limit))'.
third_party/stdlib/traceback.py
def format_stack(f=None, limit=None): """Shorthand for 'format_list(extract_stack(f, limit))'.""" if f is None: try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame.f_back return format_list(extract_stack(f, limit))
def format_stack(f=None, limit=None): """Shorthand for 'format_list(extract_stack(f, limit))'.""" if f is None: try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame.f_back return format_list(extract_stack(f, limit))
[ "Shorthand", "for", "format_list", "(", "extract_stack", "(", "f", "limit", "))", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L276-L283
[ "def", "format_stack", "(", "f", "=", "None", ",", "limit", "=", "None", ")", ":", "if", "f", "is", "None", ":", "try", ":", "raise", "ZeroDivisionError", "except", "ZeroDivisionError", ":", "f", "=", "sys", ".", "exc_info", "(", ")", "[", "2", "]", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
extract_stack
Extract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional 'f' and 'limit' arguments have the same meaning as for print_stack(). Each item in the list is a quadruple (filename, line number, function name, text), and the entries are in order from oldest to newest stack frame.
third_party/stdlib/traceback.py
def extract_stack(f=None, limit = None): """Extract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional 'f' and 'limit' arguments have the same meaning as for print_stack(). Each item in the list is a quadruple (filename, line number, function name, text), and the entries are in order from oldest to newest stack frame. """ if f is None: try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame.f_back if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while f is not None and (limit is None or n < limit): lineno = f.f_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) f = f.f_back n = n+1 list.reverse() return list
def extract_stack(f=None, limit = None): """Extract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional 'f' and 'limit' arguments have the same meaning as for print_stack(). Each item in the list is a quadruple (filename, line number, function name, text), and the entries are in order from oldest to newest stack frame. """ if f is None: try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame.f_back if limit is None: if hasattr(sys, 'tracebacklimit'): limit = sys.tracebacklimit list = [] n = 0 while f is not None and (limit is None or n < limit): lineno = f.f_lineno co = f.f_code filename = co.co_filename name = co.co_name linecache.checkcache(filename) line = linecache.getline(filename, lineno, f.f_globals) if line: line = line.strip() else: line = None list.append((filename, lineno, name, line)) f = f.f_back n = n+1 list.reverse() return list
[ "Extract", "the", "raw", "traceback", "from", "the", "current", "stack", "frame", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/traceback.py#L285-L317
[ "def", "extract_stack", "(", "f", "=", "None", ",", "limit", "=", "None", ")", ":", "if", "f", "is", "None", ":", "try", ":", "raise", "ZeroDivisionError", "except", "ZeroDivisionError", ":", "f", "=", "sys", ".", "exc_info", "(", ")", "[", "2", "]",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Random.seed
Initialize internal state of the random number generator. None or no argument seeds from current time or from an operating system specific randomness source if available. If a is not None or is an int or long, hash(a) is used instead. Hash values for some types are nondeterministic when the PYTHONHASHSEED environment variable is enabled.
third_party/stdlib/random.py
def seed(self, a=None): """Initialize internal state of the random number generator. None or no argument seeds from current time or from an operating system specific randomness source if available. If a is not None or is an int or long, hash(a) is used instead. Hash values for some types are nondeterministic when the PYTHONHASHSEED environment variable is enabled. """ super(Random, self).seed(a) self.gauss_next = None
def seed(self, a=None): """Initialize internal state of the random number generator. None or no argument seeds from current time or from an operating system specific randomness source if available. If a is not None or is an int or long, hash(a) is used instead. Hash values for some types are nondeterministic when the PYTHONHASHSEED environment variable is enabled. """ super(Random, self).seed(a) self.gauss_next = None
[ "Initialize", "internal", "state", "of", "the", "random", "number", "generator", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/random.py#L98-L110
[ "def", "seed", "(", "self", ",", "a", "=", "None", ")", ":", "super", "(", "Random", ",", "self", ")", ".", "seed", "(", "a", ")", "self", ".", "gauss_next", "=", "None" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Random.randrange
Choose a random item from range(start, stop[, step]). This fixes the problem with randint() which includes the endpoint; in Python this is usually not what you want.
third_party/stdlib/random.py
def randrange(self, start, stop=None, step=1, _int=int, _maxwidth=1L<<BPF): """Choose a random item from range(start, stop[, step]). This fixes the problem with randint() which includes the endpoint; in Python this is usually not what you want. """ # This code is a bit messy to make it fast for the # common case while still doing adequate error checking. istart = _int(start) if istart != start: raise ValueError, "non-integer arg 1 for randrange()" if stop is None: if istart > 0: if istart >= _maxwidth: return self._randbelow(istart) return _int(self.random() * istart) raise ValueError, "empty range for randrange()" # stop argument supplied. istop = _int(stop) if istop != stop: raise ValueError, "non-integer stop for randrange()" width = istop - istart if step == 1 and width > 0: # Note that # int(istart + self.random()*width) # instead would be incorrect. For example, consider istart # = -2 and istop = 0. Then the guts would be in # -2.0 to 0.0 exclusive on both ends (ignoring that random() # might return 0.0), and because int() truncates toward 0, the # final result would be -1 or 0 (instead of -2 or -1). # istart + int(self.random()*width) # would also be incorrect, for a subtler reason: the RHS # can return a long, and then randrange() would also return # a long, but we're supposed to return an int (for backward # compatibility). if width >= _maxwidth: return _int(istart + self._randbelow(width)) return _int(istart + _int(self.random()*width)) if step == 1: raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width) # Non-unit step argument supplied. istep = _int(step) if istep != step: raise ValueError, "non-integer step for randrange()" if istep > 0: n = (width + istep - 1) // istep elif istep < 0: n = (width + istep + 1) // istep else: raise ValueError, "zero step for randrange()" if n <= 0: raise ValueError, "empty range for randrange()" if n >= _maxwidth: return istart + istep*self._randbelow(n) return istart + istep*_int(self.random() * n)
def randrange(self, start, stop=None, step=1, _int=int, _maxwidth=1L<<BPF): """Choose a random item from range(start, stop[, step]). This fixes the problem with randint() which includes the endpoint; in Python this is usually not what you want. """ # This code is a bit messy to make it fast for the # common case while still doing adequate error checking. istart = _int(start) if istart != start: raise ValueError, "non-integer arg 1 for randrange()" if stop is None: if istart > 0: if istart >= _maxwidth: return self._randbelow(istart) return _int(self.random() * istart) raise ValueError, "empty range for randrange()" # stop argument supplied. istop = _int(stop) if istop != stop: raise ValueError, "non-integer stop for randrange()" width = istop - istart if step == 1 and width > 0: # Note that # int(istart + self.random()*width) # instead would be incorrect. For example, consider istart # = -2 and istop = 0. Then the guts would be in # -2.0 to 0.0 exclusive on both ends (ignoring that random() # might return 0.0), and because int() truncates toward 0, the # final result would be -1 or 0 (instead of -2 or -1). # istart + int(self.random()*width) # would also be incorrect, for a subtler reason: the RHS # can return a long, and then randrange() would also return # a long, but we're supposed to return an int (for backward # compatibility). if width >= _maxwidth: return _int(istart + self._randbelow(width)) return _int(istart + _int(self.random()*width)) if step == 1: raise ValueError, "empty range for randrange() (%d,%d, %d)" % (istart, istop, width) # Non-unit step argument supplied. istep = _int(step) if istep != step: raise ValueError, "non-integer step for randrange()" if istep > 0: n = (width + istep - 1) // istep elif istep < 0: n = (width + istep + 1) // istep else: raise ValueError, "zero step for randrange()" if n <= 0: raise ValueError, "empty range for randrange()" if n >= _maxwidth: return istart + istep*self._randbelow(n) return istart + istep*_int(self.random() * n)
[ "Choose", "a", "random", "item", "from", "range", "(", "start", "stop", "[", "step", "]", ")", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/random.py#L117-L178
[ "def", "randrange", "(", "self", ",", "start", ",", "stop", "=", "None", ",", "step", "=", "1", ",", "_int", "=", "int", ",", "_maxwidth", "=", "1L", "<<", "BPF", ")", ":", "# This code is a bit messy to make it fast for the", "# common case while still doing ad...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Random.shuffle
x, random=random.random -> shuffle list x in place; return None. Optional arg random is a 0-argument function returning a random float in [0.0, 1.0); by default, the standard random.random.
third_party/stdlib/random.py
def shuffle(self, x, random=None): """x, random=random.random -> shuffle list x in place; return None. Optional arg random is a 0-argument function returning a random float in [0.0, 1.0); by default, the standard random.random. """ if random is None: random = self.random _int = int for i in reversed(xrange(1, len(x))): # pick an element in x[:i+1] with which to exchange x[i] j = _int(random() * (i+1)) x[i], x[j] = x[j], x[i]
def shuffle(self, x, random=None): """x, random=random.random -> shuffle list x in place; return None. Optional arg random is a 0-argument function returning a random float in [0.0, 1.0); by default, the standard random.random. """ if random is None: random = self.random _int = int for i in reversed(xrange(1, len(x))): # pick an element in x[:i+1] with which to exchange x[i] j = _int(random() * (i+1)) x[i], x[j] = x[j], x[i]
[ "x", "random", "=", "random", ".", "random", "-", ">", "shuffle", "list", "x", "in", "place", ";", "return", "None", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/random.py#L192-L206
[ "def", "shuffle", "(", "self", ",", "x", ",", "random", "=", "None", ")", ":", "if", "random", "is", "None", ":", "random", "=", "self", ".", "random", "_int", "=", "int", "for", "i", "in", "reversed", "(", "xrange", "(", "1", ",", "len", "(", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
_slotnames
Return a list of slot names for a given class. This needs to find slots defined by the class and its bases, so we can't simply return the __slots__ attribute. We must walk down the Method Resolution Order and concatenate the __slots__ of each class found there. (This assumes classes don't modify their __slots__ attribute to misrepresent their slots after the class is defined.)
third_party/stdlib/copy_reg.py
def _slotnames(cls): """Return a list of slot names for a given class. This needs to find slots defined by the class and its bases, so we can't simply return the __slots__ attribute. We must walk down the Method Resolution Order and concatenate the __slots__ of each class found there. (This assumes classes don't modify their __slots__ attribute to misrepresent their slots after the class is defined.) """ # Get the value from a cache in the class if possible names = cls.__dict__.get("__slotnames__") if names is not None: return names # Not cached -- calculate the value names = [] if not hasattr(cls, "__slots__"): # This class has no slots pass else: # Slots found -- gather slot names from all base classes for c in cls.__mro__: if "__slots__" in c.__dict__: slots = c.__dict__['__slots__'] # if class has a single slot, it can be given as a string if isinstance(slots, basestring): slots = (slots,) for name in slots: # special descriptors if name in ("__dict__", "__weakref__"): continue # mangled names elif name.startswith('__') and not name.endswith('__'): names.append('_%s%s' % (c.__name__, name)) else: names.append(name) # Cache the outcome in the class if at all possible try: cls.__slotnames__ = names except: pass # But don't die if we can't return names
def _slotnames(cls): """Return a list of slot names for a given class. This needs to find slots defined by the class and its bases, so we can't simply return the __slots__ attribute. We must walk down the Method Resolution Order and concatenate the __slots__ of each class found there. (This assumes classes don't modify their __slots__ attribute to misrepresent their slots after the class is defined.) """ # Get the value from a cache in the class if possible names = cls.__dict__.get("__slotnames__") if names is not None: return names # Not cached -- calculate the value names = [] if not hasattr(cls, "__slots__"): # This class has no slots pass else: # Slots found -- gather slot names from all base classes for c in cls.__mro__: if "__slots__" in c.__dict__: slots = c.__dict__['__slots__'] # if class has a single slot, it can be given as a string if isinstance(slots, basestring): slots = (slots,) for name in slots: # special descriptors if name in ("__dict__", "__weakref__"): continue # mangled names elif name.startswith('__') and not name.endswith('__'): names.append('_%s%s' % (c.__name__, name)) else: names.append(name) # Cache the outcome in the class if at all possible try: cls.__slotnames__ = names except: pass # But don't die if we can't return names
[ "Return", "a", "list", "of", "slot", "names", "for", "a", "given", "class", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/copy_reg.py#L95-L140
[ "def", "_slotnames", "(", "cls", ")", ":", "# Get the value from a cache in the class if possible", "names", "=", "cls", ".", "__dict__", ".", "get", "(", "\"__slotnames__\"", ")", "if", "names", "is", "not", "None", ":", "return", "names", "# Not cached -- calculat...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
add_extension
Register an extension code.
third_party/stdlib/copy_reg.py
def add_extension(module, name, code): """Register an extension code.""" code = int(code) if not 1 <= code <= 0x7fffffff: raise ValueError, "code out of range" key = (module, name) if (_extension_registry.get(key) == code and _inverted_registry.get(code) == key): return # Redundant registrations are benign if key in _extension_registry: raise ValueError("key %s is already registered with code %s" % (key, _extension_registry[key])) if code in _inverted_registry: raise ValueError("code %s is already in use for key %s" % (code, _inverted_registry[code])) _extension_registry[key] = code _inverted_registry[code] = key
def add_extension(module, name, code): """Register an extension code.""" code = int(code) if not 1 <= code <= 0x7fffffff: raise ValueError, "code out of range" key = (module, name) if (_extension_registry.get(key) == code and _inverted_registry.get(code) == key): return # Redundant registrations are benign if key in _extension_registry: raise ValueError("key %s is already registered with code %s" % (key, _extension_registry[key])) if code in _inverted_registry: raise ValueError("code %s is already in use for key %s" % (code, _inverted_registry[code])) _extension_registry[key] = code _inverted_registry[code] = key
[ "Register", "an", "extension", "code", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/copy_reg.py#L157-L173
[ "def", "add_extension", "(", "module", ",", "name", ",", "code", ")", ":", "code", "=", "int", "(", "code", ")", "if", "not", "1", "<=", "code", "<=", "0x7fffffff", ":", "raise", "ValueError", ",", "\"code out of range\"", "key", "=", "(", "module", ",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
remove_extension
Unregister an extension code. For testing only.
third_party/stdlib/copy_reg.py
def remove_extension(module, name, code): """Unregister an extension code. For testing only.""" key = (module, name) if (_extension_registry.get(key) != code or _inverted_registry.get(code) != key): raise ValueError("key %s is not registered with code %s" % (key, code)) del _extension_registry[key] del _inverted_registry[code] if code in _extension_cache: del _extension_cache[code]
def remove_extension(module, name, code): """Unregister an extension code. For testing only.""" key = (module, name) if (_extension_registry.get(key) != code or _inverted_registry.get(code) != key): raise ValueError("key %s is not registered with code %s" % (key, code)) del _extension_registry[key] del _inverted_registry[code] if code in _extension_cache: del _extension_cache[code]
[ "Unregister", "an", "extension", "code", ".", "For", "testing", "only", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/copy_reg.py#L175-L185
[ "def", "remove_extension", "(", "module", ",", "name", ",", "code", ")", ":", "key", "=", "(", "module", ",", "name", ")", "if", "(", "_extension_registry", ".", "get", "(", "key", ")", "!=", "code", "or", "_inverted_registry", ".", "get", "(", "code",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
update_wrapper
Update a wrapper function to look like the wrapped function wrapper is the function to be updated wrapped is the original function assigned is a tuple naming the attributes assigned directly from the wrapped function to the wrapper function (defaults to functools.WRAPPER_ASSIGNMENTS) updated is a tuple naming the attributes of the wrapper that are updated with the corresponding attribute from the wrapped function (defaults to functools.WRAPPER_UPDATES)
third_party/stdlib/functools.py
def update_wrapper(wrapper, wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES): """Update a wrapper function to look like the wrapped function wrapper is the function to be updated wrapped is the original function assigned is a tuple naming the attributes assigned directly from the wrapped function to the wrapper function (defaults to functools.WRAPPER_ASSIGNMENTS) updated is a tuple naming the attributes of the wrapper that are updated with the corresponding attribute from the wrapped function (defaults to functools.WRAPPER_UPDATES) """ for attr in assigned: setattr(wrapper, attr, getattr(wrapped, attr)) for attr in updated: getattr(wrapper, attr).update(getattr(wrapped, attr, {})) # Return the wrapper so this can be used as a decorator via partial() return wrapper
def update_wrapper(wrapper, wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES): """Update a wrapper function to look like the wrapped function wrapper is the function to be updated wrapped is the original function assigned is a tuple naming the attributes assigned directly from the wrapped function to the wrapper function (defaults to functools.WRAPPER_ASSIGNMENTS) updated is a tuple naming the attributes of the wrapper that are updated with the corresponding attribute from the wrapped function (defaults to functools.WRAPPER_UPDATES) """ for attr in assigned: setattr(wrapper, attr, getattr(wrapped, attr)) for attr in updated: getattr(wrapper, attr).update(getattr(wrapped, attr, {})) # Return the wrapper so this can be used as a decorator via partial() return wrapper
[ "Update", "a", "wrapper", "function", "to", "look", "like", "the", "wrapped", "function" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/functools.py#L23-L43
[ "def", "update_wrapper", "(", "wrapper", ",", "wrapped", ",", "assigned", "=", "WRAPPER_ASSIGNMENTS", ",", "updated", "=", "WRAPPER_UPDATES", ")", ":", "for", "attr", "in", "assigned", ":", "setattr", "(", "wrapper", ",", "attr", ",", "getattr", "(", "wrappe...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
wraps
Decorator factory to apply update_wrapper() to a wrapper function Returns a decorator that invokes update_wrapper() with the decorated function as the wrapper argument and the arguments to wraps() as the remaining arguments. Default arguments are as for update_wrapper(). This is a convenience function to simplify applying partial() to update_wrapper().
third_party/stdlib/functools.py
def wraps(wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES): """Decorator factory to apply update_wrapper() to a wrapper function Returns a decorator that invokes update_wrapper() with the decorated function as the wrapper argument and the arguments to wraps() as the remaining arguments. Default arguments are as for update_wrapper(). This is a convenience function to simplify applying partial() to update_wrapper(). """ return partial(update_wrapper, wrapped=wrapped, assigned=assigned, updated=updated)
def wraps(wrapped, assigned = WRAPPER_ASSIGNMENTS, updated = WRAPPER_UPDATES): """Decorator factory to apply update_wrapper() to a wrapper function Returns a decorator that invokes update_wrapper() with the decorated function as the wrapper argument and the arguments to wraps() as the remaining arguments. Default arguments are as for update_wrapper(). This is a convenience function to simplify applying partial() to update_wrapper(). """ return partial(update_wrapper, wrapped=wrapped, assigned=assigned, updated=updated)
[ "Decorator", "factory", "to", "apply", "update_wrapper", "()", "to", "a", "wrapper", "function" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/functools.py#L45-L57
[ "def", "wraps", "(", "wrapped", ",", "assigned", "=", "WRAPPER_ASSIGNMENTS", ",", "updated", "=", "WRAPPER_UPDATES", ")", ":", "return", "partial", "(", "update_wrapper", ",", "wrapped", "=", "wrapped", ",", "assigned", "=", "assigned", ",", "updated", "=", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
cmp_to_key
Convert a cmp= function into a key= function
third_party/stdlib/functools.py
def cmp_to_key(mycmp): """Convert a cmp= function into a key= function""" class K(object): __slots__ = ['obj'] def __init__(self, obj, *args): self.obj = obj def __lt__(self, other): return mycmp(self.obj, other.obj) < 0 def __gt__(self, other): return mycmp(self.obj, other.obj) > 0 def __eq__(self, other): return mycmp(self.obj, other.obj) == 0 def __le__(self, other): return mycmp(self.obj, other.obj) <= 0 def __ge__(self, other): return mycmp(self.obj, other.obj) >= 0 def __ne__(self, other): return mycmp(self.obj, other.obj) != 0 def __hash__(self): raise TypeError('hash not implemented') return K
def cmp_to_key(mycmp): """Convert a cmp= function into a key= function""" class K(object): __slots__ = ['obj'] def __init__(self, obj, *args): self.obj = obj def __lt__(self, other): return mycmp(self.obj, other.obj) < 0 def __gt__(self, other): return mycmp(self.obj, other.obj) > 0 def __eq__(self, other): return mycmp(self.obj, other.obj) == 0 def __le__(self, other): return mycmp(self.obj, other.obj) <= 0 def __ge__(self, other): return mycmp(self.obj, other.obj) >= 0 def __ne__(self, other): return mycmp(self.obj, other.obj) != 0 def __hash__(self): raise TypeError('hash not implemented') return K
[ "Convert", "a", "cmp", "=", "function", "into", "a", "key", "=", "function" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/functools.py#L86-L106
[ "def", "cmp_to_key", "(", "mycmp", ")", ":", "class", "K", "(", "object", ")", ":", "__slots__", "=", "[", "'obj'", "]", "def", "__init__", "(", "self", ",", "obj", ",", "*", "args", ")", ":", "self", ".", "obj", "=", "obj", "def", "__lt__", "(",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
unquote
Remove quotes from a string.
third_party/stdlib/rfc822.py
def unquote(s): """Remove quotes from a string.""" if len(s) > 1: if s.startswith('"') and s.endswith('"'): return s[1:-1].replace('\\\\', '\\').replace('\\"', '"') if s.startswith('<') and s.endswith('>'): return s[1:-1] return s
def unquote(s): """Remove quotes from a string.""" if len(s) > 1: if s.startswith('"') and s.endswith('"'): return s[1:-1].replace('\\\\', '\\').replace('\\"', '"') if s.startswith('<') and s.endswith('>'): return s[1:-1] return s
[ "Remove", "quotes", "from", "a", "string", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L477-L484
[ "def", "unquote", "(", "s", ")", ":", "if", "len", "(", "s", ")", ">", "1", ":", "if", "s", ".", "startswith", "(", "'\"'", ")", "and", "s", ".", "endswith", "(", "'\"'", ")", ":", "return", "s", "[", "1", ":", "-", "1", "]", ".", "replace"...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
parseaddr
Parse an address into a (realname, mailaddr) tuple.
third_party/stdlib/rfc822.py
def parseaddr(address): """Parse an address into a (realname, mailaddr) tuple.""" a = AddressList(address) lst = a.addresslist if not lst: return (None, None) return lst[0]
def parseaddr(address): """Parse an address into a (realname, mailaddr) tuple.""" a = AddressList(address) lst = a.addresslist if not lst: return (None, None) return lst[0]
[ "Parse", "an", "address", "into", "a", "(", "realname", "mailaddr", ")", "tuple", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L492-L498
[ "def", "parseaddr", "(", "address", ")", ":", "a", "=", "AddressList", "(", "address", ")", "lst", "=", "a", ".", "addresslist", "if", "not", "lst", ":", "return", "(", "None", ",", "None", ")", "return", "lst", "[", "0", "]" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
mktime_tz
Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.
third_party/stdlib/rfc822.py
def mktime_tz(data): """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" if data[9] is None: # No zone info, so localtime is better assumption than GMT return time.mktime(data[:8] + (-1,)) else: t = time.mktime(data[:8] + (0,)) return t - data[9] - time.timezone
def mktime_tz(data): """Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp.""" if data[9] is None: # No zone info, so localtime is better assumption than GMT return time.mktime(data[:8] + (-1,)) else: t = time.mktime(data[:8] + (0,)) return t - data[9] - time.timezone
[ "Turn", "a", "10", "-", "tuple", "as", "returned", "by", "parsedate_tz", "()", "into", "a", "UTC", "timestamp", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L948-L955
[ "def", "mktime_tz", "(", "data", ")", ":", "if", "data", "[", "9", "]", "is", "None", ":", "# No zone info, so localtime is better assumption than GMT", "return", "time", ".", "mktime", "(", "data", "[", ":", "8", "]", "+", "(", "-", "1", ",", ")", ")", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
formatdate
Returns time format preferred for Internet standards. Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 According to RFC 1123, day and month names must always be in English. If not for that, this code could use strftime(). It can't because strftime() honors the locale and could generate non-English names.
third_party/stdlib/rfc822.py
def formatdate(timeval=None): """Returns time format preferred for Internet standards. Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 According to RFC 1123, day and month names must always be in English. If not for that, this code could use strftime(). It can't because strftime() honors the locale and could generate non-English names. """ if timeval is None: timeval = time.time() timeval = time.gmtime(timeval) return "%s, %02d %s %04d %02d:%02d:%02d GMT" % ( ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")[timeval[6]], timeval[2], ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")[timeval[1]-1], timeval[0], timeval[3], timeval[4], timeval[5])
def formatdate(timeval=None): """Returns time format preferred for Internet standards. Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 According to RFC 1123, day and month names must always be in English. If not for that, this code could use strftime(). It can't because strftime() honors the locale and could generate non-English names. """ if timeval is None: timeval = time.time() timeval = time.gmtime(timeval) return "%s, %02d %s %04d %02d:%02d:%02d GMT" % ( ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")[timeval[6]], timeval[2], ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")[timeval[1]-1], timeval[0], timeval[3], timeval[4], timeval[5])
[ "Returns", "time", "format", "preferred", "for", "Internet", "standards", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L957-L975
[ "def", "formatdate", "(", "timeval", "=", "None", ")", ":", "if", "timeval", "is", "None", ":", "timeval", "=", "time", ".", "time", "(", ")", "timeval", "=", "time", ".", "gmtime", "(", "timeval", ")", "return", "\"%s, %02d %s %04d %02d:%02d:%02d GMT\"", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Message.rewindbody
Rewind the file to the start of the body (if seekable).
third_party/stdlib/rfc822.py
def rewindbody(self): """Rewind the file to the start of the body (if seekable).""" if not self.seekable: raise IOError, "unseekable file" self.fp.seek(self.startofbody)
def rewindbody(self): """Rewind the file to the start of the body (if seekable).""" if not self.seekable: raise IOError, "unseekable file" self.fp.seek(self.startofbody)
[ "Rewind", "the", "file", "to", "the", "start", "of", "the", "body", "(", "if", "seekable", ")", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L116-L120
[ "def", "rewindbody", "(", "self", ")", ":", "if", "not", "self", ".", "seekable", ":", "raise", "IOError", ",", "\"unseekable file\"", "self", ".", "fp", ".", "seek", "(", "self", ".", "startofbody", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Message.readheaders
Read header lines. Read header lines up to the entirely blank line that terminates them. The (normally blank) line that ends the headers is skipped, but not included in the returned list. If a non-header line ends the headers, (which is an error), an attempt is made to backspace over it; it is never included in the returned list. The variable self.status is set to the empty string if all went well, otherwise it is an error message. The variable self.headers is a completely uninterpreted list of lines contained in the header (so printing them will reproduce the header exactly as it appears in the file).
third_party/stdlib/rfc822.py
def readheaders(self): """Read header lines. Read header lines up to the entirely blank line that terminates them. The (normally blank) line that ends the headers is skipped, but not included in the returned list. If a non-header line ends the headers, (which is an error), an attempt is made to backspace over it; it is never included in the returned list. The variable self.status is set to the empty string if all went well, otherwise it is an error message. The variable self.headers is a completely uninterpreted list of lines contained in the header (so printing them will reproduce the header exactly as it appears in the file). """ self.dict = {} self.unixfrom = '' self.headers = lst = [] self.status = '' headerseen = "" firstline = 1 startofline = unread = tell = None if hasattr(self.fp, 'unread'): unread = self.fp.unread elif self.seekable: tell = self.fp.tell while 1: if tell: try: startofline = tell() except IOError: startofline = tell = None self.seekable = 0 line = self.fp.readline() if not line: self.status = 'EOF in headers' break # Skip unix From name time lines if firstline and line.startswith('From '): self.unixfrom = self.unixfrom + line continue firstline = 0 if headerseen and line[0] in ' \t': # It's a continuation line. lst.append(line) x = (self.dict[headerseen] + "\n " + line.strip()) self.dict[headerseen] = x.strip() continue elif self.iscomment(line): # It's a comment. Ignore it. continue elif self.islast(line): # Note! No pushback here! The delimiter line gets eaten. break headerseen = self.isheader(line) if headerseen: # It's a legal header line, save it. lst.append(line) self.dict[headerseen] = line[len(headerseen)+1:].strip() continue elif headerseen is not None: # An empty header name. These aren't allowed in HTTP, but it's # probably a benign mistake. Don't add the header, just keep # going. continue else: # It's not a header line; throw it back and stop here. if not self.dict: self.status = 'No headers' else: self.status = 'Non-header line where header expected' # Try to undo the read. if unread: unread(line) elif tell: self.fp.seek(startofline) else: self.status = self.status + '; bad seek' break
def readheaders(self): """Read header lines. Read header lines up to the entirely blank line that terminates them. The (normally blank) line that ends the headers is skipped, but not included in the returned list. If a non-header line ends the headers, (which is an error), an attempt is made to backspace over it; it is never included in the returned list. The variable self.status is set to the empty string if all went well, otherwise it is an error message. The variable self.headers is a completely uninterpreted list of lines contained in the header (so printing them will reproduce the header exactly as it appears in the file). """ self.dict = {} self.unixfrom = '' self.headers = lst = [] self.status = '' headerseen = "" firstline = 1 startofline = unread = tell = None if hasattr(self.fp, 'unread'): unread = self.fp.unread elif self.seekable: tell = self.fp.tell while 1: if tell: try: startofline = tell() except IOError: startofline = tell = None self.seekable = 0 line = self.fp.readline() if not line: self.status = 'EOF in headers' break # Skip unix From name time lines if firstline and line.startswith('From '): self.unixfrom = self.unixfrom + line continue firstline = 0 if headerseen and line[0] in ' \t': # It's a continuation line. lst.append(line) x = (self.dict[headerseen] + "\n " + line.strip()) self.dict[headerseen] = x.strip() continue elif self.iscomment(line): # It's a comment. Ignore it. continue elif self.islast(line): # Note! No pushback here! The delimiter line gets eaten. break headerseen = self.isheader(line) if headerseen: # It's a legal header line, save it. lst.append(line) self.dict[headerseen] = line[len(headerseen)+1:].strip() continue elif headerseen is not None: # An empty header name. These aren't allowed in HTTP, but it's # probably a benign mistake. Don't add the header, just keep # going. continue else: # It's not a header line; throw it back and stop here. if not self.dict: self.status = 'No headers' else: self.status = 'Non-header line where header expected' # Try to undo the read. if unread: unread(line) elif tell: self.fp.seek(startofline) else: self.status = self.status + '; bad seek' break
[ "Read", "header", "lines", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L122-L200
[ "def", "readheaders", "(", "self", ")", ":", "self", ".", "dict", "=", "{", "}", "self", ".", "unixfrom", "=", "''", "self", ".", "headers", "=", "lst", "=", "[", "]", "self", ".", "status", "=", "''", "headerseen", "=", "\"\"", "firstline", "=", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Message.isheader
Determine whether a given line is a legal header. This method should return the header name, suitably canonicalized. You may override this method in order to use Message parsing on tagged data in RFC 2822-like formats with special header formats.
third_party/stdlib/rfc822.py
def isheader(self, line): """Determine whether a given line is a legal header. This method should return the header name, suitably canonicalized. You may override this method in order to use Message parsing on tagged data in RFC 2822-like formats with special header formats. """ i = line.find(':') if i > -1: return line[:i].lower() return None
def isheader(self, line): """Determine whether a given line is a legal header. This method should return the header name, suitably canonicalized. You may override this method in order to use Message parsing on tagged data in RFC 2822-like formats with special header formats. """ i = line.find(':') if i > -1: return line[:i].lower() return None
[ "Determine", "whether", "a", "given", "line", "is", "a", "legal", "header", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L202-L212
[ "def", "isheader", "(", "self", ",", "line", ")", ":", "i", "=", "line", ".", "find", "(", "':'", ")", "if", "i", ">", "-", "1", ":", "return", "line", "[", ":", "i", "]", ".", "lower", "(", ")", "return", "None" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Message.getfirstmatchingheader
Get the first header line matching name. This is similar to getallmatchingheaders, but it returns only the first matching header (and its continuation lines).
third_party/stdlib/rfc822.py
def getfirstmatchingheader(self, name): """Get the first header line matching name. This is similar to getallmatchingheaders, but it returns only the first matching header (and its continuation lines). """ name = name.lower() + ':' n = len(name) lst = [] hit = 0 for line in self.headers: if hit: if not line[:1].isspace(): break elif line[:n].lower() == name: hit = 1 if hit: lst.append(line) return lst
def getfirstmatchingheader(self, name): """Get the first header line matching name. This is similar to getallmatchingheaders, but it returns only the first matching header (and its continuation lines). """ name = name.lower() + ':' n = len(name) lst = [] hit = 0 for line in self.headers: if hit: if not line[:1].isspace(): break elif line[:n].lower() == name: hit = 1 if hit: lst.append(line) return lst
[ "Get", "the", "first", "header", "line", "matching", "name", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L255-L273
[ "def", "getfirstmatchingheader", "(", "self", ",", "name", ")", ":", "name", "=", "name", ".", "lower", "(", ")", "+", "':'", "n", "=", "len", "(", "name", ")", "lst", "=", "[", "]", "hit", "=", "0", "for", "line", "in", "self", ".", "headers", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Message.getrawheader
A higher-level interface to getfirstmatchingheader(). Return a string containing the literal text of the header but with the keyword stripped. All leading, trailing and embedded whitespace is kept in the string, however. Return None if the header does not occur.
third_party/stdlib/rfc822.py
def getrawheader(self, name): """A higher-level interface to getfirstmatchingheader(). Return a string containing the literal text of the header but with the keyword stripped. All leading, trailing and embedded whitespace is kept in the string, however. Return None if the header does not occur. """ lst = self.getfirstmatchingheader(name) if not lst: return None lst[0] = lst[0][len(name) + 1:] return ''.join(lst)
def getrawheader(self, name): """A higher-level interface to getfirstmatchingheader(). Return a string containing the literal text of the header but with the keyword stripped. All leading, trailing and embedded whitespace is kept in the string, however. Return None if the header does not occur. """ lst = self.getfirstmatchingheader(name) if not lst: return None lst[0] = lst[0][len(name) + 1:] return ''.join(lst)
[ "A", "higher", "-", "level", "interface", "to", "getfirstmatchingheader", "()", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L275-L288
[ "def", "getrawheader", "(", "self", ",", "name", ")", ":", "lst", "=", "self", ".", "getfirstmatchingheader", "(", "name", ")", "if", "not", "lst", ":", "return", "None", "lst", "[", "0", "]", "=", "lst", "[", "0", "]", "[", "len", "(", "name", "...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Message.getheader
Get the header value for a name. This is the normal interface: it returns a stripped version of the header value for a given header name, or None if it doesn't exist. This uses the dictionary version which finds the *last* such header.
third_party/stdlib/rfc822.py
def getheader(self, name, default=None): """Get the header value for a name. This is the normal interface: it returns a stripped version of the header value for a given header name, or None if it doesn't exist. This uses the dictionary version which finds the *last* such header. """ return self.dict.get(name.lower(), default)
def getheader(self, name, default=None): """Get the header value for a name. This is the normal interface: it returns a stripped version of the header value for a given header name, or None if it doesn't exist. This uses the dictionary version which finds the *last* such header. """ return self.dict.get(name.lower(), default)
[ "Get", "the", "header", "value", "for", "a", "name", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L290-L297
[ "def", "getheader", "(", "self", ",", "name", ",", "default", "=", "None", ")", ":", "return", "self", ".", "dict", ".", "get", "(", "name", ".", "lower", "(", ")", ",", "default", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Message.getheaders
Get all values for a header. This returns a list of values for headers given more than once; each value in the result list is stripped in the same way as the result of getheader(). If the header is not given, return an empty list.
third_party/stdlib/rfc822.py
def getheaders(self, name): """Get all values for a header. This returns a list of values for headers given more than once; each value in the result list is stripped in the same way as the result of getheader(). If the header is not given, return an empty list. """ result = [] current = '' have_header = 0 for s in self.getallmatchingheaders(name): if s[0].isspace(): if current: current = "%s\n %s" % (current, s.strip()) else: current = s.strip() else: if have_header: result.append(current) current = s[s.find(":") + 1:].strip() have_header = 1 if have_header: result.append(current) return result
def getheaders(self, name): """Get all values for a header. This returns a list of values for headers given more than once; each value in the result list is stripped in the same way as the result of getheader(). If the header is not given, return an empty list. """ result = [] current = '' have_header = 0 for s in self.getallmatchingheaders(name): if s[0].isspace(): if current: current = "%s\n %s" % (current, s.strip()) else: current = s.strip() else: if have_header: result.append(current) current = s[s.find(":") + 1:].strip() have_header = 1 if have_header: result.append(current) return result
[ "Get", "all", "values", "for", "a", "header", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L300-L323
[ "def", "getheaders", "(", "self", ",", "name", ")", ":", "result", "=", "[", "]", "current", "=", "''", "have_header", "=", "0", "for", "s", "in", "self", ".", "getallmatchingheaders", "(", "name", ")", ":", "if", "s", "[", "0", "]", ".", "isspace"...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Message.getaddrlist
Get a list of addresses from a header. Retrieves a list of addresses from a header, where each address is a tuple as returned by getaddr(). Scans all named headers, so it works properly with multiple To: or Cc: headers for example.
third_party/stdlib/rfc822.py
def getaddrlist(self, name): """Get a list of addresses from a header. Retrieves a list of addresses from a header, where each address is a tuple as returned by getaddr(). Scans all named headers, so it works properly with multiple To: or Cc: headers for example. """ raw = [] for h in self.getallmatchingheaders(name): if h[0] in ' \t': raw.append(h) else: if raw: raw.append(', ') i = h.find(':') if i > 0: addr = h[i+1:] raw.append(addr) alladdrs = ''.join(raw) a = AddressList(alladdrs) return a.addresslist
def getaddrlist(self, name): """Get a list of addresses from a header. Retrieves a list of addresses from a header, where each address is a tuple as returned by getaddr(). Scans all named headers, so it works properly with multiple To: or Cc: headers for example. """ raw = [] for h in self.getallmatchingheaders(name): if h[0] in ' \t': raw.append(h) else: if raw: raw.append(', ') i = h.find(':') if i > 0: addr = h[i+1:] raw.append(addr) alladdrs = ''.join(raw) a = AddressList(alladdrs) return a.addresslist
[ "Get", "a", "list", "of", "addresses", "from", "a", "header", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L338-L358
[ "def", "getaddrlist", "(", "self", ",", "name", ")", ":", "raw", "=", "[", "]", "for", "h", "in", "self", ".", "getallmatchingheaders", "(", "name", ")", ":", "if", "h", "[", "0", "]", "in", "' \\t'", ":", "raw", ".", "append", "(", "h", ")", "...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
AddrlistClass.gotonext
Parse up to the start of the next address.
third_party/stdlib/rfc822.py
def gotonext(self): """Parse up to the start of the next address.""" while self.pos < len(self.field): if self.field[self.pos] in self.LWS + '\n\r': self.pos = self.pos + 1 elif self.field[self.pos] == '(': self.commentlist.append(self.getcomment()) else: break
def gotonext(self): """Parse up to the start of the next address.""" while self.pos < len(self.field): if self.field[self.pos] in self.LWS + '\n\r': self.pos = self.pos + 1 elif self.field[self.pos] == '(': self.commentlist.append(self.getcomment()) else: break
[ "Parse", "up", "to", "the", "start", "of", "the", "next", "address", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L531-L538
[ "def", "gotonext", "(", "self", ")", ":", "while", "self", ".", "pos", "<", "len", "(", "self", ".", "field", ")", ":", "if", "self", ".", "field", "[", "self", ".", "pos", "]", "in", "self", ".", "LWS", "+", "'\\n\\r'", ":", "self", ".", "pos"...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
AddrlistClass.getaddrlist
Parse all addresses. Returns a list containing all of the addresses.
third_party/stdlib/rfc822.py
def getaddrlist(self): """Parse all addresses. Returns a list containing all of the addresses. """ result = [] ad = self.getaddress() while ad: result += ad ad = self.getaddress() return result
def getaddrlist(self): """Parse all addresses. Returns a list containing all of the addresses. """ result = [] ad = self.getaddress() while ad: result += ad ad = self.getaddress() return result
[ "Parse", "all", "addresses", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L540-L550
[ "def", "getaddrlist", "(", "self", ")", ":", "result", "=", "[", "]", "ad", "=", "self", ".", "getaddress", "(", ")", "while", "ad", ":", "result", "+=", "ad", "ad", "=", "self", ".", "getaddress", "(", ")", "return", "result" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
AddrlistClass.getrouteaddr
Parse a route address (Return-path value). This method just skips all the route stuff and returns the addrspec.
third_party/stdlib/rfc822.py
def getrouteaddr(self): """Parse a route address (Return-path value). This method just skips all the route stuff and returns the addrspec. """ if self.field[self.pos] != '<': return expectroute = 0 self.pos += 1 self.gotonext() adlist = "" while self.pos < len(self.field): if expectroute: self.getdomain() expectroute = 0 elif self.field[self.pos] == '>': self.pos += 1 break elif self.field[self.pos] == '@': self.pos += 1 expectroute = 1 elif self.field[self.pos] == ':': self.pos += 1 else: adlist = self.getaddrspec() self.pos += 1 break self.gotonext() return adlist
def getrouteaddr(self): """Parse a route address (Return-path value). This method just skips all the route stuff and returns the addrspec. """ if self.field[self.pos] != '<': return expectroute = 0 self.pos += 1 self.gotonext() adlist = "" while self.pos < len(self.field): if expectroute: self.getdomain() expectroute = 0 elif self.field[self.pos] == '>': self.pos += 1 break elif self.field[self.pos] == '@': self.pos += 1 expectroute = 1 elif self.field[self.pos] == ':': self.pos += 1 else: adlist = self.getaddrspec() self.pos += 1 break self.gotonext() return adlist
[ "Parse", "a", "route", "address", "(", "Return", "-", "path", "value", ")", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L610-L640
[ "def", "getrouteaddr", "(", "self", ")", ":", "if", "self", ".", "field", "[", "self", ".", "pos", "]", "!=", "'<'", ":", "return", "expectroute", "=", "0", "self", ".", "pos", "+=", "1", "self", ".", "gotonext", "(", ")", "adlist", "=", "\"\"", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
AddrlistClass.getaddrspec
Parse an RFC 2822 addr-spec.
third_party/stdlib/rfc822.py
def getaddrspec(self): """Parse an RFC 2822 addr-spec.""" aslist = [] self.gotonext() while self.pos < len(self.field): if self.field[self.pos] == '.': aslist.append('.') self.pos += 1 elif self.field[self.pos] == '"': aslist.append('"%s"' % self.getquote()) elif self.field[self.pos] in self.atomends: break else: aslist.append(self.getatom()) self.gotonext() if self.pos >= len(self.field) or self.field[self.pos] != '@': return ''.join(aslist) aslist.append('@') self.pos += 1 self.gotonext() return ''.join(aslist) + self.getdomain()
def getaddrspec(self): """Parse an RFC 2822 addr-spec.""" aslist = [] self.gotonext() while self.pos < len(self.field): if self.field[self.pos] == '.': aslist.append('.') self.pos += 1 elif self.field[self.pos] == '"': aslist.append('"%s"' % self.getquote()) elif self.field[self.pos] in self.atomends: break else: aslist.append(self.getatom()) self.gotonext() if self.pos >= len(self.field) or self.field[self.pos] != '@': return ''.join(aslist) aslist.append('@') self.pos += 1 self.gotonext() return ''.join(aslist) + self.getdomain()
[ "Parse", "an", "RFC", "2822", "addr", "-", "spec", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L642-L664
[ "def", "getaddrspec", "(", "self", ")", ":", "aslist", "=", "[", "]", "self", ".", "gotonext", "(", ")", "while", "self", ".", "pos", "<", "len", "(", "self", ".", "field", ")", ":", "if", "self", ".", "field", "[", "self", ".", "pos", "]", "==...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
AddrlistClass.getdomain
Get the complete domain name from an address.
third_party/stdlib/rfc822.py
def getdomain(self): """Get the complete domain name from an address.""" sdlist = [] while self.pos < len(self.field): if self.field[self.pos] in self.LWS: self.pos += 1 elif self.field[self.pos] == '(': self.commentlist.append(self.getcomment()) elif self.field[self.pos] == '[': sdlist.append(self.getdomainliteral()) elif self.field[self.pos] == '.': self.pos += 1 sdlist.append('.') elif self.field[self.pos] in self.atomends: break else: sdlist.append(self.getatom()) return ''.join(sdlist)
def getdomain(self): """Get the complete domain name from an address.""" sdlist = [] while self.pos < len(self.field): if self.field[self.pos] in self.LWS: self.pos += 1 elif self.field[self.pos] == '(': self.commentlist.append(self.getcomment()) elif self.field[self.pos] == '[': sdlist.append(self.getdomainliteral()) elif self.field[self.pos] == '.': self.pos += 1 sdlist.append('.') elif self.field[self.pos] in self.atomends: break else: sdlist.append(self.getatom()) return ''.join(sdlist)
[ "Get", "the", "complete", "domain", "name", "from", "an", "address", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L666-L682
[ "def", "getdomain", "(", "self", ")", ":", "sdlist", "=", "[", "]", "while", "self", ".", "pos", "<", "len", "(", "self", ".", "field", ")", ":", "if", "self", ".", "field", "[", "self", ".", "pos", "]", "in", "self", ".", "LWS", ":", "self", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
AddrlistClass.getdelimited
Parse a header fragment delimited by special characters. `beginchar' is the start character for the fragment. If self is not looking at an instance of `beginchar' then getdelimited returns the empty string. `endchars' is a sequence of allowable end-delimiting characters. Parsing stops when one of these is encountered. If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed within the parsed fragment.
third_party/stdlib/rfc822.py
def getdelimited(self, beginchar, endchars, allowcomments = 1): """Parse a header fragment delimited by special characters. `beginchar' is the start character for the fragment. If self is not looking at an instance of `beginchar' then getdelimited returns the empty string. `endchars' is a sequence of allowable end-delimiting characters. Parsing stops when one of these is encountered. If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed within the parsed fragment. """ if self.field[self.pos] != beginchar: return '' slist = [''] quote = 0 self.pos += 1 while self.pos < len(self.field): if quote == 1: slist.append(self.field[self.pos]) quote = 0 elif self.field[self.pos] in endchars: self.pos += 1 break elif allowcomments and self.field[self.pos] == '(': slist.append(self.getcomment()) continue # have already advanced pos from getcomment elif self.field[self.pos] == '\\': quote = 1 else: slist.append(self.field[self.pos]) self.pos += 1 return ''.join(slist)
def getdelimited(self, beginchar, endchars, allowcomments = 1): """Parse a header fragment delimited by special characters. `beginchar' is the start character for the fragment. If self is not looking at an instance of `beginchar' then getdelimited returns the empty string. `endchars' is a sequence of allowable end-delimiting characters. Parsing stops when one of these is encountered. If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed within the parsed fragment. """ if self.field[self.pos] != beginchar: return '' slist = [''] quote = 0 self.pos += 1 while self.pos < len(self.field): if quote == 1: slist.append(self.field[self.pos]) quote = 0 elif self.field[self.pos] in endchars: self.pos += 1 break elif allowcomments and self.field[self.pos] == '(': slist.append(self.getcomment()) continue # have already advanced pos from getcomment elif self.field[self.pos] == '\\': quote = 1 else: slist.append(self.field[self.pos]) self.pos += 1 return ''.join(slist)
[ "Parse", "a", "header", "fragment", "delimited", "by", "special", "characters", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L684-L719
[ "def", "getdelimited", "(", "self", ",", "beginchar", ",", "endchars", ",", "allowcomments", "=", "1", ")", ":", "if", "self", ".", "field", "[", "self", ".", "pos", "]", "!=", "beginchar", ":", "return", "''", "slist", "=", "[", "''", "]", "quote", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
AddrlistClass.getphraselist
Parse a sequence of RFC 2822 phrases. A phrase is a sequence of words, which are in turn either RFC 2822 atoms or quoted-strings. Phrases are canonicalized by squeezing all runs of continuous whitespace into one space.
third_party/stdlib/rfc822.py
def getphraselist(self): """Parse a sequence of RFC 2822 phrases. A phrase is a sequence of words, which are in turn either RFC 2822 atoms or quoted-strings. Phrases are canonicalized by squeezing all runs of continuous whitespace into one space. """ plist = [] while self.pos < len(self.field): if self.field[self.pos] in self.LWS: self.pos += 1 elif self.field[self.pos] == '"': plist.append(self.getquote()) elif self.field[self.pos] == '(': self.commentlist.append(self.getcomment()) elif self.field[self.pos] in self.phraseends: break else: plist.append(self.getatom(self.phraseends)) return plist
def getphraselist(self): """Parse a sequence of RFC 2822 phrases. A phrase is a sequence of words, which are in turn either RFC 2822 atoms or quoted-strings. Phrases are canonicalized by squeezing all runs of continuous whitespace into one space. """ plist = [] while self.pos < len(self.field): if self.field[self.pos] in self.LWS: self.pos += 1 elif self.field[self.pos] == '"': plist.append(self.getquote()) elif self.field[self.pos] == '(': self.commentlist.append(self.getcomment()) elif self.field[self.pos] in self.phraseends: break else: plist.append(self.getatom(self.phraseends)) return plist
[ "Parse", "a", "sequence", "of", "RFC", "2822", "phrases", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/rfc822.py#L752-L773
[ "def", "getphraselist", "(", "self", ")", ":", "plist", "=", "[", "]", "while", "self", ".", "pos", "<", "len", "(", "self", ".", "field", ")", ":", "if", "self", ".", "field", "[", "self", ".", "pos", "]", "in", "self", ".", "LWS", ":", "self"...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
_days_in_month
year, month -> number of days in that month in that year.
third_party/pypy/datetime.py
def _days_in_month(year, month): "year, month -> number of days in that month in that year." assert 1 <= month <= 12, month if month == 2 and _is_leap(year): return 29 return _DAYS_IN_MONTH[month]
def _days_in_month(year, month): "year, month -> number of days in that month in that year." assert 1 <= month <= 12, month if month == 2 and _is_leap(year): return 29 return _DAYS_IN_MONTH[month]
[ "year", "month", "-", ">", "number", "of", "days", "in", "that", "month", "in", "that", "year", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L70-L75
[ "def", "_days_in_month", "(", "year", ",", "month", ")", ":", "assert", "1", "<=", "month", "<=", "12", ",", "month", "if", "month", "==", "2", "and", "_is_leap", "(", "year", ")", ":", "return", "29", "return", "_DAYS_IN_MONTH", "[", "month", "]" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
_ymd2ord
year, month, day -> ordinal, considering 01-Jan-0001 as day 1.
third_party/pypy/datetime.py
def _ymd2ord(year, month, day): "year, month, day -> ordinal, considering 01-Jan-0001 as day 1." assert 1 <= month <= 12, 'month must be in 1..12' dim = _days_in_month(year, month) assert 1 <= day <= dim, ('day must be in 1..%d' % dim) return (_days_before_year(year) + _days_before_month(year, month) + day)
def _ymd2ord(year, month, day): "year, month, day -> ordinal, considering 01-Jan-0001 as day 1." assert 1 <= month <= 12, 'month must be in 1..12' dim = _days_in_month(year, month) assert 1 <= day <= dim, ('day must be in 1..%d' % dim) return (_days_before_year(year) + _days_before_month(year, month) + day)
[ "year", "month", "day", "-", ">", "ordinal", "considering", "01", "-", "Jan", "-", "0001", "as", "day", "1", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L82-L89
[ "def", "_ymd2ord", "(", "year", ",", "month", ",", "day", ")", ":", "assert", "1", "<=", "month", "<=", "12", ",", "'month must be in 1..12'", "dim", "=", "_days_in_month", "(", "year", ",", "month", ")", "assert", "1", "<=", "day", "<=", "dim", ",", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
_ord2ymd
ordinal -> (year, month, day), considering 01-Jan-0001 as day 1.
third_party/pypy/datetime.py
def _ord2ymd(n): "ordinal -> (year, month, day), considering 01-Jan-0001 as day 1." # n is a 1-based index, starting at 1-Jan-1. The pattern of leap years # repeats exactly every 400 years. The basic strategy is to find the # closest 400-year boundary at or before n, then work with the offset # from that boundary to n. Life is much clearer if we subtract 1 from # n first -- then the values of n at 400-year boundaries are exactly # those divisible by _DI400Y: # # D M Y n n-1 # -- --- ---- ---------- ---------------- # 31 Dec -400 -_DI400Y -_DI400Y -1 # 1 Jan -399 -_DI400Y +1 -_DI400Y 400-year boundary # ... # 30 Dec 000 -1 -2 # 31 Dec 000 0 -1 # 1 Jan 001 1 0 400-year boundary # 2 Jan 001 2 1 # 3 Jan 001 3 2 # ... # 31 Dec 400 _DI400Y _DI400Y -1 # 1 Jan 401 _DI400Y +1 _DI400Y 400-year boundary n -= 1 n400, n = divmod(n, _DI400Y) year = n400 * 400 + 1 # ..., -399, 1, 401, ... # Now n is the (non-negative) offset, in days, from January 1 of year, to # the desired date. Now compute how many 100-year cycles precede n. # Note that it's possible for n100 to equal 4! In that case 4 full # 100-year cycles precede the desired day, which implies the desired # day is December 31 at the end of a 400-year cycle. n100, n = divmod(n, _DI100Y) # Now compute how many 4-year cycles precede it. n4, n = divmod(n, _DI4Y) # And now how many single years. Again n1 can be 4, and again meaning # that the desired day is December 31 at the end of the 4-year cycle. n1, n = divmod(n, 365) year += n100 * 100 + n4 * 4 + n1 if n1 == 4 or n100 == 4: assert n == 0 return year-1, 12, 31 # Now the year is correct, and n is the offset from January 1. We find # the month via an estimate that's either exact or one too large. leapyear = n1 == 3 and (n4 != 24 or n100 == 3) assert leapyear == _is_leap(year) month = (n + 50) >> 5 preceding = _DAYS_BEFORE_MONTH[month] + (month > 2 and leapyear) if preceding > n: # estimate is too large month -= 1 preceding -= _DAYS_IN_MONTH[month] + (month == 2 and leapyear) n -= preceding assert 0 <= n < _days_in_month(year, month) # Now the year and month are correct, and n is the offset from the # start of that month: we're done! return year, month, n+1
def _ord2ymd(n): "ordinal -> (year, month, day), considering 01-Jan-0001 as day 1." # n is a 1-based index, starting at 1-Jan-1. The pattern of leap years # repeats exactly every 400 years. The basic strategy is to find the # closest 400-year boundary at or before n, then work with the offset # from that boundary to n. Life is much clearer if we subtract 1 from # n first -- then the values of n at 400-year boundaries are exactly # those divisible by _DI400Y: # # D M Y n n-1 # -- --- ---- ---------- ---------------- # 31 Dec -400 -_DI400Y -_DI400Y -1 # 1 Jan -399 -_DI400Y +1 -_DI400Y 400-year boundary # ... # 30 Dec 000 -1 -2 # 31 Dec 000 0 -1 # 1 Jan 001 1 0 400-year boundary # 2 Jan 001 2 1 # 3 Jan 001 3 2 # ... # 31 Dec 400 _DI400Y _DI400Y -1 # 1 Jan 401 _DI400Y +1 _DI400Y 400-year boundary n -= 1 n400, n = divmod(n, _DI400Y) year = n400 * 400 + 1 # ..., -399, 1, 401, ... # Now n is the (non-negative) offset, in days, from January 1 of year, to # the desired date. Now compute how many 100-year cycles precede n. # Note that it's possible for n100 to equal 4! In that case 4 full # 100-year cycles precede the desired day, which implies the desired # day is December 31 at the end of a 400-year cycle. n100, n = divmod(n, _DI100Y) # Now compute how many 4-year cycles precede it. n4, n = divmod(n, _DI4Y) # And now how many single years. Again n1 can be 4, and again meaning # that the desired day is December 31 at the end of the 4-year cycle. n1, n = divmod(n, 365) year += n100 * 100 + n4 * 4 + n1 if n1 == 4 or n100 == 4: assert n == 0 return year-1, 12, 31 # Now the year is correct, and n is the offset from January 1. We find # the month via an estimate that's either exact or one too large. leapyear = n1 == 3 and (n4 != 24 or n100 == 3) assert leapyear == _is_leap(year) month = (n + 50) >> 5 preceding = _DAYS_BEFORE_MONTH[month] + (month > 2 and leapyear) if preceding > n: # estimate is too large month -= 1 preceding -= _DAYS_IN_MONTH[month] + (month == 2 and leapyear) n -= preceding assert 0 <= n < _days_in_month(year, month) # Now the year and month are correct, and n is the offset from the # start of that month: we're done! return year, month, n+1
[ "ordinal", "-", ">", "(", "year", "month", "day", ")", "considering", "01", "-", "Jan", "-", "0001", "as", "day", "1", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L116-L176
[ "def", "_ord2ymd", "(", "n", ")", ":", "# n is a 1-based index, starting at 1-Jan-1. The pattern of leap years", "# repeats exactly every 400 years. The basic strategy is to find the", "# closest 400-year boundary at or before n, then work with the offset", "# from that boundary to n. Life is m...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
date.fromtimestamp
Construct a date from a POSIX timestamp (like time.time()).
third_party/pypy/datetime.py
def fromtimestamp(cls, t): "Construct a date from a POSIX timestamp (like time.time())." y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(t) return cls(y, m, d)
def fromtimestamp(cls, t): "Construct a date from a POSIX timestamp (like time.time())." y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(t) return cls(y, m, d)
[ "Construct", "a", "date", "from", "a", "POSIX", "timestamp", "(", "like", "time", ".", "time", "()", ")", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L732-L735
[ "def", "fromtimestamp", "(", "cls", ",", "t", ")", ":", "y", ",", "m", ",", "d", ",", "hh", ",", "mm", ",", "ss", ",", "weekday", ",", "jday", ",", "dst", "=", "_time", ".", "localtime", "(", "t", ")", "return", "cls", "(", "y", ",", "m", "...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
date.fromordinal
Contruct a date from a proleptic Gregorian ordinal. January 1 of year 1 is day 1. Only the year, month and day are non-zero in the result.
third_party/pypy/datetime.py
def fromordinal(cls, n): """Contruct a date from a proleptic Gregorian ordinal. January 1 of year 1 is day 1. Only the year, month and day are non-zero in the result. """ y, m, d = _ord2ymd(n) return cls(y, m, d)
def fromordinal(cls, n): """Contruct a date from a proleptic Gregorian ordinal. January 1 of year 1 is day 1. Only the year, month and day are non-zero in the result. """ y, m, d = _ord2ymd(n) return cls(y, m, d)
[ "Contruct", "a", "date", "from", "a", "proleptic", "Gregorian", "ordinal", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L744-L751
[ "def", "fromordinal", "(", "cls", ",", "n", ")", ":", "y", ",", "m", ",", "d", "=", "_ord2ymd", "(", "n", ")", "return", "cls", "(", "y", ",", "m", ",", "d", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
date.ctime
Return ctime() style string.
third_party/pypy/datetime.py
def ctime(self): "Return ctime() style string." weekday = self.toordinal() % 7 or 7 return "%s %s %2d 00:00:00 %04d" % ( _DAYNAMES[weekday], _MONTHNAMES[self._month], self._day, self._year)
def ctime(self): "Return ctime() style string." weekday = self.toordinal() % 7 or 7 return "%s %s %2d 00:00:00 %04d" % ( _DAYNAMES[weekday], _MONTHNAMES[self._month], self._day, self._year)
[ "Return", "ctime", "()", "style", "string", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L777-L783
[ "def", "ctime", "(", "self", ")", ":", "weekday", "=", "self", ".", "toordinal", "(", ")", "%", "7", "or", "7", "return", "\"%s %s %2d 00:00:00 %04d\"", "%", "(", "_DAYNAMES", "[", "weekday", "]", ",", "_MONTHNAMES", "[", "self", ".", "_month", "]", ",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
date.isoformat
Return the date formatted according to ISO. This is 'YYYY-MM-DD'. References: - http://www.w3.org/TR/NOTE-datetime - http://www.cl.cam.ac.uk/~mgk25/iso-time.html
third_party/pypy/datetime.py
def isoformat(self): """Return the date formatted according to ISO. This is 'YYYY-MM-DD'. References: - http://www.w3.org/TR/NOTE-datetime - http://www.cl.cam.ac.uk/~mgk25/iso-time.html """ # return "%04d-%02d-%02d" % (self._year, self._month, self._day) return "%s-%s-%s" % (str(self._year).zfill(4), str(self._month).zfill(2), str(self._day).zfill(2))
def isoformat(self): """Return the date formatted according to ISO. This is 'YYYY-MM-DD'. References: - http://www.w3.org/TR/NOTE-datetime - http://www.cl.cam.ac.uk/~mgk25/iso-time.html """ # return "%04d-%02d-%02d" % (self._year, self._month, self._day) return "%s-%s-%s" % (str(self._year).zfill(4), str(self._month).zfill(2), str(self._day).zfill(2))
[ "Return", "the", "date", "formatted", "according", "to", "ISO", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L797-L807
[ "def", "isoformat", "(", "self", ")", ":", "# return \"%04d-%02d-%02d\" % (self._year, self._month, self._day)", "return", "\"%s-%s-%s\"", "%", "(", "str", "(", "self", ".", "_year", ")", ".", "zfill", "(", "4", ")", ",", "str", "(", "self", ".", "_month", ")"...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
date.replace
Return a new date with new values for the specified fields.
third_party/pypy/datetime.py
def replace(self, year=None, month=None, day=None): """Return a new date with new values for the specified fields.""" if year is None: year = self._year if month is None: month = self._month if day is None: day = self._day return date.__new__(type(self), year, month, day)
def replace(self, year=None, month=None, day=None): """Return a new date with new values for the specified fields.""" if year is None: year = self._year if month is None: month = self._month if day is None: day = self._day return date.__new__(type(self), year, month, day)
[ "Return", "a", "new", "date", "with", "new", "values", "for", "the", "specified", "fields", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L842-L850
[ "def", "replace", "(", "self", ",", "year", "=", "None", ",", "month", "=", "None", ",", "day", "=", "None", ")", ":", "if", "year", "is", "None", ":", "year", "=", "self", ".", "_year", "if", "month", "is", "None", ":", "month", "=", "self", "...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
date.isocalendar
Return a 3-tuple containing ISO year, week number, and weekday. The first ISO week of the year is the (Mon-Sun) week containing the year's first Thursday; everything else derives from that. The first week is 1; Monday is 1 ... Sunday is 7. ISO calendar algorithm taken from http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm
third_party/pypy/datetime.py
def isocalendar(self): """Return a 3-tuple containing ISO year, week number, and weekday. The first ISO week of the year is the (Mon-Sun) week containing the year's first Thursday; everything else derives from that. The first week is 1; Monday is 1 ... Sunday is 7. ISO calendar algorithm taken from http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm """ year = self._year week1monday = _isoweek1monday(year) today = _ymd2ord(self._year, self._month, self._day) # Internally, week and day have origin 0 week, day = divmod(today - week1monday, 7) if week < 0: year -= 1 week1monday = _isoweek1monday(year) week, day = divmod(today - week1monday, 7) elif week >= 52: if today >= _isoweek1monday(year+1): year += 1 week = 0 return year, week+1, day+1
def isocalendar(self): """Return a 3-tuple containing ISO year, week number, and weekday. The first ISO week of the year is the (Mon-Sun) week containing the year's first Thursday; everything else derives from that. The first week is 1; Monday is 1 ... Sunday is 7. ISO calendar algorithm taken from http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm """ year = self._year week1monday = _isoweek1monday(year) today = _ymd2ord(self._year, self._month, self._day) # Internally, week and day have origin 0 week, day = divmod(today - week1monday, 7) if week < 0: year -= 1 week1monday = _isoweek1monday(year) week, day = divmod(today - week1monday, 7) elif week >= 52: if today >= _isoweek1monday(year+1): year += 1 week = 0 return year, week+1, day+1
[ "Return", "a", "3", "-", "tuple", "containing", "ISO", "year", "week", "number", "and", "weekday", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L952-L977
[ "def", "isocalendar", "(", "self", ")", ":", "year", "=", "self", ".", "_year", "week1monday", "=", "_isoweek1monday", "(", "year", ")", "today", "=", "_ymd2ord", "(", "self", ".", "_year", ",", "self", ".", "_month", ",", "self", ".", "_day", ")", "...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
time._tzstr
Return formatted timezone offset (+xx:xx) or None.
third_party/pypy/datetime.py
def _tzstr(self, sep=":"): """Return formatted timezone offset (+xx:xx) or None.""" off = self._utcoffset() if off is not None: if off < 0: sign = "-" off = -off else: sign = "+" hh, mm = divmod(off, 60) assert 0 <= hh < 24 off = "%s%02d%s%02d" % (sign, hh, sep, mm) return off
def _tzstr(self, sep=":"): """Return formatted timezone offset (+xx:xx) or None.""" off = self._utcoffset() if off is not None: if off < 0: sign = "-" off = -off else: sign = "+" hh, mm = divmod(off, 60) assert 0 <= hh < 24 off = "%s%02d%s%02d" % (sign, hh, sep, mm) return off
[ "Return", "formatted", "timezone", "offset", "(", "+", "xx", ":", "xx", ")", "or", "None", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1231-L1243
[ "def", "_tzstr", "(", "self", ",", "sep", "=", "\":\"", ")", ":", "off", "=", "self", ".", "_utcoffset", "(", ")", "if", "off", "is", "not", "None", ":", "if", "off", "<", "0", ":", "sign", "=", "\"-\"", "off", "=", "-", "off", "else", ":", "...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
time.isoformat
Return the time formatted according to ISO. This is 'HH:MM:SS.mmmmmm+zz:zz', or 'HH:MM:SS+zz:zz' if self.microsecond == 0.
third_party/pypy/datetime.py
def isoformat(self): """Return the time formatted according to ISO. This is 'HH:MM:SS.mmmmmm+zz:zz', or 'HH:MM:SS+zz:zz' if self.microsecond == 0. """ s = _format_time(self._hour, self._minute, self._second, self._microsecond) tz = self._tzstr() if tz: s += tz return s
def isoformat(self): """Return the time formatted according to ISO. This is 'HH:MM:SS.mmmmmm+zz:zz', or 'HH:MM:SS+zz:zz' if self.microsecond == 0. """ s = _format_time(self._hour, self._minute, self._second, self._microsecond) tz = self._tzstr() if tz: s += tz return s
[ "Return", "the", "time", "formatted", "according", "to", "ISO", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1261-L1272
[ "def", "isoformat", "(", "self", ")", ":", "s", "=", "_format_time", "(", "self", ".", "_hour", ",", "self", ".", "_minute", ",", "self", ".", "_second", ",", "self", ".", "_microsecond", ")", "tz", "=", "self", ".", "_tzstr", "(", ")", "if", "tz",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
time.tzname
Return the timezone name. Note that the name is 100% informational -- there's no requirement that it mean anything in particular. For example, "GMT", "UTC", "-500", "-5:00", "EDT", "US/Eastern", "America/New York" are all valid replies.
third_party/pypy/datetime.py
def tzname(self): """Return the timezone name. Note that the name is 100% informational -- there's no requirement that it mean anything in particular. For example, "GMT", "UTC", "-500", "-5:00", "EDT", "US/Eastern", "America/New York" are all valid replies. """ if self._tzinfo is None: return None name = self._tzinfo.tzname(None) _check_tzname(name) return name
def tzname(self): """Return the timezone name. Note that the name is 100% informational -- there's no requirement that it mean anything in particular. For example, "GMT", "UTC", "-500", "-5:00", "EDT", "US/Eastern", "America/New York" are all valid replies. """ if self._tzinfo is None: return None name = self._tzinfo.tzname(None) _check_tzname(name) return name
[ "Return", "the", "timezone", "name", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1316-L1327
[ "def", "tzname", "(", "self", ")", ":", "if", "self", ".", "_tzinfo", "is", "None", ":", "return", "None", "name", "=", "self", ".", "_tzinfo", ".", "tzname", "(", "None", ")", "_check_tzname", "(", "name", ")", "return", "name" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
time.dst
Return 0 if DST is not in effect, or the DST offset (in minutes eastward) if DST is in effect. This is purely informational; the DST offset has already been added to the UTC offset returned by utcoffset() if applicable, so there's no need to consult dst() unless you're interested in displaying the DST info.
third_party/pypy/datetime.py
def dst(self): """Return 0 if DST is not in effect, or the DST offset (in minutes eastward) if DST is in effect. This is purely informational; the DST offset has already been added to the UTC offset returned by utcoffset() if applicable, so there's no need to consult dst() unless you're interested in displaying the DST info. """ if self._tzinfo is None: return None offset = self._tzinfo.dst(None) offset = _check_utc_offset("dst", offset) if offset is not None: offset = timedelta._create(0, offset * 60, 0, True) return offset
def dst(self): """Return 0 if DST is not in effect, or the DST offset (in minutes eastward) if DST is in effect. This is purely informational; the DST offset has already been added to the UTC offset returned by utcoffset() if applicable, so there's no need to consult dst() unless you're interested in displaying the DST info. """ if self._tzinfo is None: return None offset = self._tzinfo.dst(None) offset = _check_utc_offset("dst", offset) if offset is not None: offset = timedelta._create(0, offset * 60, 0, True) return offset
[ "Return", "0", "if", "DST", "is", "not", "in", "effect", "or", "the", "DST", "offset", "(", "in", "minutes", "eastward", ")", "if", "DST", "is", "in", "effect", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1329-L1344
[ "def", "dst", "(", "self", ")", ":", "if", "self", ".", "_tzinfo", "is", "None", ":", "return", "None", "offset", "=", "self", ".", "_tzinfo", ".", "dst", "(", "None", ")", "offset", "=", "_check_utc_offset", "(", "\"dst\"", ",", "offset", ")", "if",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
time.replace
Return a new time with new values for the specified fields.
third_party/pypy/datetime.py
def replace(self, hour=None, minute=None, second=None, microsecond=None, tzinfo=True): """Return a new time with new values for the specified fields.""" if hour is None: hour = self.hour if minute is None: minute = self.minute if second is None: second = self.second if microsecond is None: microsecond = self.microsecond if tzinfo is True: tzinfo = self.tzinfo return time.__new__(type(self), hour, minute, second, microsecond, tzinfo)
def replace(self, hour=None, minute=None, second=None, microsecond=None, tzinfo=True): """Return a new time with new values for the specified fields.""" if hour is None: hour = self.hour if minute is None: minute = self.minute if second is None: second = self.second if microsecond is None: microsecond = self.microsecond if tzinfo is True: tzinfo = self.tzinfo return time.__new__(type(self), hour, minute, second, microsecond, tzinfo)
[ "Return", "a", "new", "time", "with", "new", "values", "for", "the", "specified", "fields", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1354-L1368
[ "def", "replace", "(", "self", ",", "hour", "=", "None", ",", "minute", "=", "None", ",", "second", "=", "None", ",", "microsecond", "=", "None", ",", "tzinfo", "=", "True", ")", ":", "if", "hour", "is", "None", ":", "hour", "=", "self", ".", "ho...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
datetime.fromtimestamp
Construct a datetime from a POSIX timestamp (like time.time()). A timezone info object may be passed in as well.
third_party/pypy/datetime.py
def fromtimestamp(cls, timestamp, tz=None): """Construct a datetime from a POSIX timestamp (like time.time()). A timezone info object may be passed in as well. """ _check_tzinfo_arg(tz) converter = _time.localtime if tz is None else _time.gmtime self = cls._from_timestamp(converter, timestamp, tz) if tz is not None: self = tz.fromutc(self) return self
def fromtimestamp(cls, timestamp, tz=None): """Construct a datetime from a POSIX timestamp (like time.time()). A timezone info object may be passed in as well. """ _check_tzinfo_arg(tz) converter = _time.localtime if tz is None else _time.gmtime self = cls._from_timestamp(converter, timestamp, tz) if tz is not None: self = tz.fromutc(self) return self
[ "Construct", "a", "datetime", "from", "a", "POSIX", "timestamp", "(", "like", "time", ".", "time", "()", ")", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1466-L1476
[ "def", "fromtimestamp", "(", "cls", ",", "timestamp", ",", "tz", "=", "None", ")", ":", "_check_tzinfo_arg", "(", "tz", ")", "converter", "=", "_time", ".", "localtime", "if", "tz", "is", "None", "else", "_time", ".", "gmtime", "self", "=", "cls", ".",...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
datetime.now
Construct a datetime from time.time() and optional time zone info.
third_party/pypy/datetime.py
def now(cls, tz=None): "Construct a datetime from time.time() and optional time zone info." t = _time.time() return cls.fromtimestamp(t, tz)
def now(cls, tz=None): "Construct a datetime from time.time() and optional time zone info." t = _time.time() return cls.fromtimestamp(t, tz)
[ "Construct", "a", "datetime", "from", "time", ".", "time", "()", "and", "optional", "time", "zone", "info", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1502-L1505
[ "def", "now", "(", "cls", ",", "tz", "=", "None", ")", ":", "t", "=", "_time", ".", "time", "(", ")", "return", "cls", ".", "fromtimestamp", "(", "t", ",", "tz", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
datetime.combine
Construct a datetime from a given date and a given time.
third_party/pypy/datetime.py
def combine(cls, date, time): "Construct a datetime from a given date and a given time." if not isinstance(date, _date_class): raise TypeError("date argument must be a date instance") if not isinstance(time, _time_class): raise TypeError("time argument must be a time instance") return cls(date.year, date.month, date.day, time.hour, time.minute, time.second, time.microsecond, time.tzinfo)
def combine(cls, date, time): "Construct a datetime from a given date and a given time." if not isinstance(date, _date_class): raise TypeError("date argument must be a date instance") if not isinstance(time, _time_class): raise TypeError("time argument must be a time instance") return cls(date.year, date.month, date.day, time.hour, time.minute, time.second, time.microsecond, time.tzinfo)
[ "Construct", "a", "datetime", "from", "a", "given", "date", "and", "a", "given", "time", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1514-L1522
[ "def", "combine", "(", "cls", ",", "date", ",", "time", ")", ":", "if", "not", "isinstance", "(", "date", ",", "_date_class", ")", ":", "raise", "TypeError", "(", "\"date argument must be a date instance\"", ")", "if", "not", "isinstance", "(", "time", ",", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
datetime.utctimetuple
Return UTC time tuple compatible with time.gmtime().
third_party/pypy/datetime.py
def utctimetuple(self): "Return UTC time tuple compatible with time.gmtime()." y, m, d = self.year, self.month, self.day hh, mm, ss = self.hour, self.minute, self.second offset = self._utcoffset() if offset: # neither None nor 0 mm -= offset y, m, d, hh, mm, ss, _ = _normalize_datetime( y, m, d, hh, mm, ss, 0, ignore_overflow=True) return _build_struct_time(y, m, d, hh, mm, ss, 0)
def utctimetuple(self): "Return UTC time tuple compatible with time.gmtime()." y, m, d = self.year, self.month, self.day hh, mm, ss = self.hour, self.minute, self.second offset = self._utcoffset() if offset: # neither None nor 0 mm -= offset y, m, d, hh, mm, ss, _ = _normalize_datetime( y, m, d, hh, mm, ss, 0, ignore_overflow=True) return _build_struct_time(y, m, d, hh, mm, ss, 0)
[ "Return", "UTC", "time", "tuple", "compatible", "with", "time", ".", "gmtime", "()", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1535-L1544
[ "def", "utctimetuple", "(", "self", ")", ":", "y", ",", "m", ",", "d", "=", "self", ".", "year", ",", "self", ".", "month", ",", "self", ".", "day", "hh", ",", "mm", ",", "ss", "=", "self", ".", "hour", ",", "self", ".", "minute", ",", "self"...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
datetime.time
Return the time part, with tzinfo None.
third_party/pypy/datetime.py
def time(self): "Return the time part, with tzinfo None." return time(self.hour, self.minute, self.second, self.microsecond)
def time(self): "Return the time part, with tzinfo None." return time(self.hour, self.minute, self.second, self.microsecond)
[ "Return", "the", "time", "part", "with", "tzinfo", "None", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1550-L1552
[ "def", "time", "(", "self", ")", ":", "return", "time", "(", "self", ".", "hour", ",", "self", ".", "minute", ",", "self", ".", "second", ",", "self", ".", "microsecond", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
datetime.timetz
Return the time part, with same tzinfo.
third_party/pypy/datetime.py
def timetz(self): "Return the time part, with same tzinfo." return time(self.hour, self.minute, self.second, self.microsecond, self._tzinfo)
def timetz(self): "Return the time part, with same tzinfo." return time(self.hour, self.minute, self.second, self.microsecond, self._tzinfo)
[ "Return", "the", "time", "part", "with", "same", "tzinfo", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1554-L1557
[ "def", "timetz", "(", "self", ")", ":", "return", "time", "(", "self", ".", "hour", ",", "self", ".", "minute", ",", "self", ".", "second", ",", "self", ".", "microsecond", ",", "self", ".", "_tzinfo", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
datetime.replace
Return a new datetime with new values for the specified fields.
third_party/pypy/datetime.py
def replace(self, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, tzinfo=True): """Return a new datetime with new values for the specified fields.""" if year is None: year = self.year if month is None: month = self.month if day is None: day = self.day if hour is None: hour = self.hour if minute is None: minute = self.minute if second is None: second = self.second if microsecond is None: microsecond = self.microsecond if tzinfo is True: tzinfo = self.tzinfo return datetime.__new__(type(self), year, month, day, hour, minute, second, microsecond, tzinfo)
def replace(self, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, tzinfo=True): """Return a new datetime with new values for the specified fields.""" if year is None: year = self.year if month is None: month = self.month if day is None: day = self.day if hour is None: hour = self.hour if minute is None: minute = self.minute if second is None: second = self.second if microsecond is None: microsecond = self.microsecond if tzinfo is True: tzinfo = self.tzinfo return datetime.__new__(type(self), year, month, day, hour, minute, second, microsecond, tzinfo)
[ "Return", "a", "new", "datetime", "with", "new", "values", "for", "the", "specified", "fields", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1559-L1580
[ "def", "replace", "(", "self", ",", "year", "=", "None", ",", "month", "=", "None", ",", "day", "=", "None", ",", "hour", "=", "None", ",", "minute", "=", "None", ",", "second", "=", "None", ",", "microsecond", "=", "None", ",", "tzinfo", "=", "T...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
datetime.ctime
Return ctime() style string.
third_party/pypy/datetime.py
def ctime(self): "Return ctime() style string." weekday = self.toordinal() % 7 or 7 return "%s %s %2d %02d:%02d:%02d %04d" % ( _DAYNAMES[weekday], _MONTHNAMES[self._month], self._day, self._hour, self._minute, self._second, self._year)
def ctime(self): "Return ctime() style string." weekday = self.toordinal() % 7 or 7 return "%s %s %2d %02d:%02d:%02d %04d" % ( _DAYNAMES[weekday], _MONTHNAMES[self._month], self._day, self._hour, self._minute, self._second, self._year)
[ "Return", "ctime", "()", "style", "string", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1604-L1612
[ "def", "ctime", "(", "self", ")", ":", "weekday", "=", "self", ".", "toordinal", "(", ")", "%", "7", "or", "7", "return", "\"%s %s %2d %02d:%02d:%02d %04d\"", "%", "(", "_DAYNAMES", "[", "weekday", "]", ",", "_MONTHNAMES", "[", "self", ".", "_month", "]"...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
datetime.isoformat
Return the time formatted according to ISO. This is 'YYYY-MM-DD HH:MM:SS.mmmmmm', or 'YYYY-MM-DD HH:MM:SS' if self.microsecond == 0. If self.tzinfo is not None, the UTC offset is also attached, giving 'YYYY-MM-DD HH:MM:SS.mmmmmm+HH:MM' or 'YYYY-MM-DD HH:MM:SS+HH:MM'. Optional argument sep specifies the separator between date and time, default 'T'.
third_party/pypy/datetime.py
def isoformat(self, sep='T'): """Return the time formatted according to ISO. This is 'YYYY-MM-DD HH:MM:SS.mmmmmm', or 'YYYY-MM-DD HH:MM:SS' if self.microsecond == 0. If self.tzinfo is not None, the UTC offset is also attached, giving 'YYYY-MM-DD HH:MM:SS.mmmmmm+HH:MM' or 'YYYY-MM-DD HH:MM:SS+HH:MM'. Optional argument sep specifies the separator between date and time, default 'T'. """ s = ("%04d-%02d-%02d%c" % (self._year, self._month, self._day, sep) + _format_time(self._hour, self._minute, self._second, self._microsecond)) off = self._utcoffset() if off is not None: if off < 0: sign = "-" off = -off else: sign = "+" hh, mm = divmod(off, 60) s += "%s%02d:%02d" % (sign, hh, mm) return s
def isoformat(self, sep='T'): """Return the time formatted according to ISO. This is 'YYYY-MM-DD HH:MM:SS.mmmmmm', or 'YYYY-MM-DD HH:MM:SS' if self.microsecond == 0. If self.tzinfo is not None, the UTC offset is also attached, giving 'YYYY-MM-DD HH:MM:SS.mmmmmm+HH:MM' or 'YYYY-MM-DD HH:MM:SS+HH:MM'. Optional argument sep specifies the separator between date and time, default 'T'. """ s = ("%04d-%02d-%02d%c" % (self._year, self._month, self._day, sep) + _format_time(self._hour, self._minute, self._second, self._microsecond)) off = self._utcoffset() if off is not None: if off < 0: sign = "-" off = -off else: sign = "+" hh, mm = divmod(off, 60) s += "%s%02d:%02d" % (sign, hh, mm) return s
[ "Return", "the", "time", "formatted", "according", "to", "ISO", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1614-L1638
[ "def", "isoformat", "(", "self", ",", "sep", "=", "'T'", ")", ":", "s", "=", "(", "\"%04d-%02d-%02d%c\"", "%", "(", "self", ".", "_year", ",", "self", ".", "_month", ",", "self", ".", "_day", ",", "sep", ")", "+", "_format_time", "(", "self", ".", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
datetime.utcoffset
Return the timezone offset in minutes east of UTC (negative west of UTC).
third_party/pypy/datetime.py
def utcoffset(self): """Return the timezone offset in minutes east of UTC (negative west of UTC).""" if self._tzinfo is None: return None offset = self._tzinfo.utcoffset(self) offset = _check_utc_offset("utcoffset", offset) if offset is not None: offset = timedelta._create(0, offset * 60, 0, True) return offset
def utcoffset(self): """Return the timezone offset in minutes east of UTC (negative west of UTC).""" if self._tzinfo is None: return None offset = self._tzinfo.utcoffset(self) offset = _check_utc_offset("utcoffset", offset) if offset is not None: offset = timedelta._create(0, offset * 60, 0, True) return offset
[ "Return", "the", "timezone", "offset", "in", "minutes", "east", "of", "UTC", "(", "negative", "west", "of", "UTC", ")", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pypy/datetime.py#L1670-L1679
[ "def", "utcoffset", "(", "self", ")", ":", "if", "self", ".", "_tzinfo", "is", "None", ":", "return", "None", "offset", "=", "self", ".", "_tzinfo", ".", "utcoffset", "(", "self", ")", "offset", "=", "_check_utc_offset", "(", "\"utcoffset\"", ",", "offse...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
truediv
Same as a / b.
third_party/ouroboros/operator.py
def truediv(a, b): "Same as a / b." if type(a) == int or type(a) == long: a = float(a) return a / b
def truediv(a, b): "Same as a / b." if type(a) == int or type(a) == long: a = float(a) return a / b
[ "Same", "as", "a", "/", "b", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/ouroboros/operator.py#L130-L134
[ "def", "truediv", "(", "a", ",", "b", ")", ":", "if", "type", "(", "a", ")", "==", "int", "or", "type", "(", "a", ")", "==", "long", ":", "a", "=", "float", "(", "a", ")", "return", "a", "/", "b" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
concat
Same as a + b, for a and b sequences.
third_party/ouroboros/operator.py
def concat(a, b): "Same as a + b, for a and b sequences." if not hasattr(a, '__getitem__'): msg = "'%s' object can't be concatenated" % type(a).__name__ raise TypeError(msg) return a + b
def concat(a, b): "Same as a + b, for a and b sequences." if not hasattr(a, '__getitem__'): msg = "'%s' object can't be concatenated" % type(a).__name__ raise TypeError(msg) return a + b
[ "Same", "as", "a", "+", "b", "for", "a", "and", "b", "sequences", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/ouroboros/operator.py#L142-L147
[ "def", "concat", "(", "a", ",", "b", ")", ":", "if", "not", "hasattr", "(", "a", ",", "'__getitem__'", ")", ":", "msg", "=", "\"'%s' object can't be concatenated\"", "%", "type", "(", "a", ")", ".", "__name__", "raise", "TypeError", "(", "msg", ")", "r...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
countOf
Return the number of times b occurs in a.
third_party/ouroboros/operator.py
def countOf(a, b): "Return the number of times b occurs in a." count = 0 for i in a: if i == b: count += 1 return count
def countOf(a, b): "Return the number of times b occurs in a." count = 0 for i in a: if i == b: count += 1 return count
[ "Return", "the", "number", "of", "times", "b", "occurs", "in", "a", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/ouroboros/operator.py#L153-L159
[ "def", "countOf", "(", "a", ",", "b", ")", ":", "count", "=", "0", "for", "i", "in", "a", ":", "if", "i", "==", "b", ":", "count", "+=", "1", "return", "count" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
indexOf
Return the first index of b in a.
third_party/ouroboros/operator.py
def indexOf(a, b): "Return the first index of b in a." for i, j in enumerate(a): if j == b: return i else: raise ValueError('sequence.index(x): x not in sequence')
def indexOf(a, b): "Return the first index of b in a." for i, j in enumerate(a): if j == b: return i else: raise ValueError('sequence.index(x): x not in sequence')
[ "Return", "the", "first", "index", "of", "b", "in", "a", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/ouroboros/operator.py#L169-L175
[ "def", "indexOf", "(", "a", ",", "b", ")", ":", "for", "i", ",", "j", "in", "enumerate", "(", "a", ")", ":", "if", "j", "==", "b", ":", "return", "i", "else", ":", "raise", "ValueError", "(", "'sequence.index(x): x not in sequence'", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
length_hint
Return an estimate of the number of items in obj. This is useful for presizing containers when building from an iterable. If the object supports len(), the result will be exact. Otherwise, it may over- or under-estimate by an arbitrary amount. The result will be an integer >= 0.
third_party/ouroboros/operator.py
def length_hint(obj, default=0): """ Return an estimate of the number of items in obj. This is useful for presizing containers when building from an iterable. If the object supports len(), the result will be exact. Otherwise, it may over- or under-estimate by an arbitrary amount. The result will be an integer >= 0. """ if not isinstance(default, int): msg = ("'%s' object cannot be interpreted as an integer" % type(default).__name__) raise TypeError(msg) try: return len(obj) except TypeError: pass try: hint = type(obj).__length_hint__ except AttributeError: return default try: val = hint(obj) except TypeError: return default if val is NotImplemented: return default if not isinstance(val, int): msg = ('__length_hint__ must be integer, not %s' % type(val).__name__) raise TypeError(msg) if val < 0: msg = '__length_hint__() should return >= 0' raise ValueError(msg) return val
def length_hint(obj, default=0): """ Return an estimate of the number of items in obj. This is useful for presizing containers when building from an iterable. If the object supports len(), the result will be exact. Otherwise, it may over- or under-estimate by an arbitrary amount. The result will be an integer >= 0. """ if not isinstance(default, int): msg = ("'%s' object cannot be interpreted as an integer" % type(default).__name__) raise TypeError(msg) try: return len(obj) except TypeError: pass try: hint = type(obj).__length_hint__ except AttributeError: return default try: val = hint(obj) except TypeError: return default if val is NotImplemented: return default if not isinstance(val, int): msg = ('__length_hint__ must be integer, not %s' % type(val).__name__) raise TypeError(msg) if val < 0: msg = '__length_hint__() should return >= 0' raise ValueError(msg) return val
[ "Return", "an", "estimate", "of", "the", "number", "of", "items", "in", "obj", ".", "This", "is", "useful", "for", "presizing", "containers", "when", "building", "from", "an", "iterable", ".", "If", "the", "object", "supports", "len", "()", "the", "result"...
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/ouroboros/operator.py#L181-L217
[ "def", "length_hint", "(", "obj", ",", "default", "=", "0", ")", ":", "if", "not", "isinstance", "(", "default", ",", "int", ")", ":", "msg", "=", "(", "\"'%s' object cannot be interpreted as an integer\"", "%", "type", "(", "default", ")", ".", "__name__", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
iconcat
Same as a += b, for a and b sequences.
third_party/ouroboros/operator.py
def iconcat(a, b): "Same as a += b, for a and b sequences." if not hasattr(a, '__getitem__'): msg = "'%s' object can't be concatenated" % type(a).__name__ raise TypeError(msg) a += b return a
def iconcat(a, b): "Same as a += b, for a and b sequences." if not hasattr(a, '__getitem__'): msg = "'%s' object can't be concatenated" % type(a).__name__ raise TypeError(msg) a += b return a
[ "Same", "as", "a", "+", "=", "b", "for", "a", "and", "b", "sequences", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/ouroboros/operator.py#L303-L309
[ "def", "iconcat", "(", "a", ",", "b", ")", ":", "if", "not", "hasattr", "(", "a", ",", "'__getitem__'", ")", ":", "msg", "=", "\"'%s' object can't be concatenated\"", "%", "type", "(", "a", ")", ".", "__name__", "raise", "TypeError", "(", "msg", ")", "...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
itruediv
Same as a /= b.
third_party/ouroboros/operator.py
def itruediv(a, b): "Same as a /= b." if type(a) == int or type(a) == long: a = float(a) a /= b return a
def itruediv(a, b): "Same as a /= b." if type(a) == int or type(a) == long: a = float(a) a /= b return a
[ "Same", "as", "a", "/", "=", "b", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/ouroboros/operator.py#L351-L356
[ "def", "itruediv", "(", "a", ",", "b", ")", ":", "if", "type", "(", "a", ")", "==", "int", "or", "type", "(", "a", ")", "==", "long", ":", "a", "=", "float", "(", "a", ")", "a", "/=", "b", "return", "a" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Sniffer.sniff
Returns a dialect (or None) corresponding to the sample
third_party/stdlib/csv.py
def sniff(self, sample, delimiters=None): """ Returns a dialect (or None) corresponding to the sample """ quotechar, doublequote, delimiter, skipinitialspace = \ self._guess_quote_and_delimiter(sample, delimiters) if not delimiter: delimiter, skipinitialspace = self._guess_delimiter(sample, delimiters) if not delimiter: raise Error, "Could not determine delimiter" class dialect(Dialect): _name = "sniffed" lineterminator = '\r\n' quoting = QUOTE_MINIMAL # escapechar = '' dialect.doublequote = doublequote dialect.delimiter = delimiter # _csv.reader won't accept a quotechar of '' dialect.quotechar = quotechar or '"' dialect.skipinitialspace = skipinitialspace return dialect
def sniff(self, sample, delimiters=None): """ Returns a dialect (or None) corresponding to the sample """ quotechar, doublequote, delimiter, skipinitialspace = \ self._guess_quote_and_delimiter(sample, delimiters) if not delimiter: delimiter, skipinitialspace = self._guess_delimiter(sample, delimiters) if not delimiter: raise Error, "Could not determine delimiter" class dialect(Dialect): _name = "sniffed" lineterminator = '\r\n' quoting = QUOTE_MINIMAL # escapechar = '' dialect.doublequote = doublequote dialect.delimiter = delimiter # _csv.reader won't accept a quotechar of '' dialect.quotechar = quotechar or '"' dialect.skipinitialspace = skipinitialspace return dialect
[ "Returns", "a", "dialect", "(", "or", "None", ")", "corresponding", "to", "the", "sample" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/csv.py#L189-L215
[ "def", "sniff", "(", "self", ",", "sample", ",", "delimiters", "=", "None", ")", ":", "quotechar", ",", "doublequote", ",", "delimiter", ",", "skipinitialspace", "=", "self", ".", "_guess_quote_and_delimiter", "(", "sample", ",", "delimiters", ")", "if", "no...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Sniffer._guess_quote_and_delimiter
Looks for text enclosed between two identical quotes (the probable quotechar) which are preceded and followed by the same character (the probable delimiter). For example: ,'some text', The quote with the most wins, same with the delimiter. If there is no quotechar the delimiter can't be determined this way.
third_party/stdlib/csv.py
def _guess_quote_and_delimiter(self, data, delimiters): """ Looks for text enclosed between two identical quotes (the probable quotechar) which are preceded and followed by the same character (the probable delimiter). For example: ,'some text', The quote with the most wins, same with the delimiter. If there is no quotechar the delimiter can't be determined this way. """ matches = [] for restr in ('(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?", '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?", '(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?" '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space) regexp = re.compile(restr, re.DOTALL | re.MULTILINE) matches = regexp.findall(data) if matches: break if not matches: # (quotechar, doublequote, delimiter, skipinitialspace) return ('', False, None, 0) quotes = {} delims = {} spaces = 0 for m in matches: n = regexp.groupindex['quote'] - 1 key = m[n] if key: quotes[key] = quotes.get(key, 0) + 1 try: n = regexp.groupindex['delim'] - 1 key = m[n] except KeyError: continue if key and (delimiters is None or key in delimiters): delims[key] = delims.get(key, 0) + 1 try: n = regexp.groupindex['space'] - 1 except KeyError: continue if m[n]: spaces += 1 quotechar = reduce(lambda a, b, quotes = quotes: (quotes[a] > quotes[b]) and a or b, quotes.keys()) if delims: delim = reduce(lambda a, b, delims = delims: (delims[a] > delims[b]) and a or b, delims.keys()) skipinitialspace = delims[delim] == spaces if delim == '\n': # most likely a file with a single column delim = '' else: # there is *no* delimiter, it's a single column of quoted data delim = '' skipinitialspace = 0 # if we see an extra quote between delimiters, we've got a # double quoted format dq_regexp = re.compile( r"((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \ {'delim':re.escape(delim), 'quote':quotechar}, re.MULTILINE) if dq_regexp.search(data): doublequote = True else: doublequote = False return (quotechar, doublequote, delim, skipinitialspace)
def _guess_quote_and_delimiter(self, data, delimiters): """ Looks for text enclosed between two identical quotes (the probable quotechar) which are preceded and followed by the same character (the probable delimiter). For example: ,'some text', The quote with the most wins, same with the delimiter. If there is no quotechar the delimiter can't be determined this way. """ matches = [] for restr in ('(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?", '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?", '(?P<delim>>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?" '(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space) regexp = re.compile(restr, re.DOTALL | re.MULTILINE) matches = regexp.findall(data) if matches: break if not matches: # (quotechar, doublequote, delimiter, skipinitialspace) return ('', False, None, 0) quotes = {} delims = {} spaces = 0 for m in matches: n = regexp.groupindex['quote'] - 1 key = m[n] if key: quotes[key] = quotes.get(key, 0) + 1 try: n = regexp.groupindex['delim'] - 1 key = m[n] except KeyError: continue if key and (delimiters is None or key in delimiters): delims[key] = delims.get(key, 0) + 1 try: n = regexp.groupindex['space'] - 1 except KeyError: continue if m[n]: spaces += 1 quotechar = reduce(lambda a, b, quotes = quotes: (quotes[a] > quotes[b]) and a or b, quotes.keys()) if delims: delim = reduce(lambda a, b, delims = delims: (delims[a] > delims[b]) and a or b, delims.keys()) skipinitialspace = delims[delim] == spaces if delim == '\n': # most likely a file with a single column delim = '' else: # there is *no* delimiter, it's a single column of quoted data delim = '' skipinitialspace = 0 # if we see an extra quote between delimiters, we've got a # double quoted format dq_regexp = re.compile( r"((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \ {'delim':re.escape(delim), 'quote':quotechar}, re.MULTILINE) if dq_regexp.search(data): doublequote = True else: doublequote = False return (quotechar, doublequote, delim, skipinitialspace)
[ "Looks", "for", "text", "enclosed", "between", "two", "identical", "quotes", "(", "the", "probable", "quotechar", ")", "which", "are", "preceded", "and", "followed", "by", "the", "same", "character", "(", "the", "probable", "delimiter", ")", ".", "For", "exa...
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/csv.py#L218-L292
[ "def", "_guess_quote_and_delimiter", "(", "self", ",", "data", ",", "delimiters", ")", ":", "matches", "=", "[", "]", "for", "restr", "in", "(", "'(?P<delim>[^\\w\\n\"\\'])(?P<space> ?)(?P<quote>[\"\\']).*?(?P=quote)(?P=delim)'", ",", "# ,\".*?\",", "'(?:^|\\n)(?P<quote>[\"...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Sniffer._guess_delimiter
The delimiter /should/ occur the same number of times on each row. However, due to malformed data, it may not. We don't want an all or nothing approach, so we allow for small variations in this number. 1) build a table of the frequency of each character on every line. 2) build a table of frequencies of this frequency (meta-frequency?), e.g. 'x occurred 5 times in 10 rows, 6 times in 1000 rows, 7 times in 2 rows' 3) use the mode of the meta-frequency to determine the /expected/ frequency for that character 4) find out how often the character actually meets that goal 5) the character that best meets its goal is the delimiter For performance reasons, the data is evaluated in chunks, so it can try and evaluate the smallest portion of the data possible, evaluating additional chunks as necessary.
third_party/stdlib/csv.py
def _guess_delimiter(self, data, delimiters): """ The delimiter /should/ occur the same number of times on each row. However, due to malformed data, it may not. We don't want an all or nothing approach, so we allow for small variations in this number. 1) build a table of the frequency of each character on every line. 2) build a table of frequencies of this frequency (meta-frequency?), e.g. 'x occurred 5 times in 10 rows, 6 times in 1000 rows, 7 times in 2 rows' 3) use the mode of the meta-frequency to determine the /expected/ frequency for that character 4) find out how often the character actually meets that goal 5) the character that best meets its goal is the delimiter For performance reasons, the data is evaluated in chunks, so it can try and evaluate the smallest portion of the data possible, evaluating additional chunks as necessary. """ data = filter(None, data.split('\n')) ascii = [chr(c) for c in range(127)] # 7-bit ASCII # build frequency tables chunkLength = min(10, len(data)) iteration = 0 charFrequency = {} modes = {} delims = {} start, end = 0, min(chunkLength, len(data)) while start < len(data): iteration += 1 for line in data[start:end]: for char in ascii: metaFrequency = charFrequency.get(char, {}) # must count even if frequency is 0 freq = line.count(char) # value is the mode metaFrequency[freq] = metaFrequency.get(freq, 0) + 1 charFrequency[char] = metaFrequency for char in charFrequency.keys(): items = charFrequency[char].items() if len(items) == 1 and items[0][0] == 0: continue # get the mode of the frequencies if len(items) > 1: modes[char] = reduce(lambda a, b: a[1] > b[1] and a or b, items) # adjust the mode - subtract the sum of all # other frequencies items.remove(modes[char]) modes[char] = (modes[char][0], modes[char][1] - reduce(lambda a, b: (0, a[1] + b[1]), items)[1]) else: modes[char] = items[0] # build a list of possible delimiters modeList = modes.items() total = float(chunkLength * iteration) # (rows of consistent data) / (number of rows) = 100% consistency = 1.0 # minimum consistency threshold threshold = 0.9 while len(delims) == 0 and consistency >= threshold: for k, v in modeList: if v[0] > 0 and v[1] > 0: if ((v[1]/total) >= consistency and (delimiters is None or k in delimiters)): delims[k] = v consistency -= 0.01 if len(delims) == 1: delim = delims.keys()[0] skipinitialspace = (data[0].count(delim) == data[0].count("%c " % delim)) return (delim, skipinitialspace) # analyze another chunkLength lines start = end end += chunkLength if not delims: return ('', 0) # if there's more than one, fall back to a 'preferred' list if len(delims) > 1: for d in self.preferred: if d in delims.keys(): skipinitialspace = (data[0].count(d) == data[0].count("%c " % d)) return (d, skipinitialspace) # nothing else indicates a preference, pick the character that # dominates(?) items = [(v,k) for (k,v) in delims.items()] items.sort() delim = items[-1][1] skipinitialspace = (data[0].count(delim) == data[0].count("%c " % delim)) return (delim, skipinitialspace)
def _guess_delimiter(self, data, delimiters): """ The delimiter /should/ occur the same number of times on each row. However, due to malformed data, it may not. We don't want an all or nothing approach, so we allow for small variations in this number. 1) build a table of the frequency of each character on every line. 2) build a table of frequencies of this frequency (meta-frequency?), e.g. 'x occurred 5 times in 10 rows, 6 times in 1000 rows, 7 times in 2 rows' 3) use the mode of the meta-frequency to determine the /expected/ frequency for that character 4) find out how often the character actually meets that goal 5) the character that best meets its goal is the delimiter For performance reasons, the data is evaluated in chunks, so it can try and evaluate the smallest portion of the data possible, evaluating additional chunks as necessary. """ data = filter(None, data.split('\n')) ascii = [chr(c) for c in range(127)] # 7-bit ASCII # build frequency tables chunkLength = min(10, len(data)) iteration = 0 charFrequency = {} modes = {} delims = {} start, end = 0, min(chunkLength, len(data)) while start < len(data): iteration += 1 for line in data[start:end]: for char in ascii: metaFrequency = charFrequency.get(char, {}) # must count even if frequency is 0 freq = line.count(char) # value is the mode metaFrequency[freq] = metaFrequency.get(freq, 0) + 1 charFrequency[char] = metaFrequency for char in charFrequency.keys(): items = charFrequency[char].items() if len(items) == 1 and items[0][0] == 0: continue # get the mode of the frequencies if len(items) > 1: modes[char] = reduce(lambda a, b: a[1] > b[1] and a or b, items) # adjust the mode - subtract the sum of all # other frequencies items.remove(modes[char]) modes[char] = (modes[char][0], modes[char][1] - reduce(lambda a, b: (0, a[1] + b[1]), items)[1]) else: modes[char] = items[0] # build a list of possible delimiters modeList = modes.items() total = float(chunkLength * iteration) # (rows of consistent data) / (number of rows) = 100% consistency = 1.0 # minimum consistency threshold threshold = 0.9 while len(delims) == 0 and consistency >= threshold: for k, v in modeList: if v[0] > 0 and v[1] > 0: if ((v[1]/total) >= consistency and (delimiters is None or k in delimiters)): delims[k] = v consistency -= 0.01 if len(delims) == 1: delim = delims.keys()[0] skipinitialspace = (data[0].count(delim) == data[0].count("%c " % delim)) return (delim, skipinitialspace) # analyze another chunkLength lines start = end end += chunkLength if not delims: return ('', 0) # if there's more than one, fall back to a 'preferred' list if len(delims) > 1: for d in self.preferred: if d in delims.keys(): skipinitialspace = (data[0].count(d) == data[0].count("%c " % d)) return (d, skipinitialspace) # nothing else indicates a preference, pick the character that # dominates(?) items = [(v,k) for (k,v) in delims.items()] items.sort() delim = items[-1][1] skipinitialspace = (data[0].count(delim) == data[0].count("%c " % delim)) return (delim, skipinitialspace)
[ "The", "delimiter", "/", "should", "/", "occur", "the", "same", "number", "of", "times", "on", "each", "row", ".", "However", "due", "to", "malformed", "data", "it", "may", "not", ".", "We", "don", "t", "want", "an", "all", "or", "nothing", "approach",...
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/csv.py#L295-L397
[ "def", "_guess_delimiter", "(", "self", ",", "data", ",", "delimiters", ")", ":", "data", "=", "filter", "(", "None", ",", "data", ".", "split", "(", "'\\n'", ")", ")", "ascii", "=", "[", "chr", "(", "c", ")", "for", "c", "in", "range", "(", "127...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
encode_basestring
Return a JSON representation of a Python string
third_party/stdlib/json/encoder.py
def encode_basestring(s): """Return a JSON representation of a Python string """ def replace(match): return ESCAPE_DCT[match.group(0)] return '"' + ESCAPE.sub(replace, s) + '"'
def encode_basestring(s): """Return a JSON representation of a Python string """ def replace(match): return ESCAPE_DCT[match.group(0)] return '"' + ESCAPE.sub(replace, s) + '"'
[ "Return", "a", "JSON", "representation", "of", "a", "Python", "string" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/json/encoder.py#L41-L47
[ "def", "encode_basestring", "(", "s", ")", ":", "def", "replace", "(", "match", ")", ":", "return", "ESCAPE_DCT", "[", "match", ".", "group", "(", "0", ")", "]", "return", "'\"'", "+", "ESCAPE", ".", "sub", "(", "replace", ",", "s", ")", "+", "'\"'...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
sub
Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it's passed the match object and must return a replacement string to be used.
third_party/stdlib/re.py
def sub(pattern, repl, string, count=0, flags=0): """Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, flags).sub(repl, string, count)
def sub(pattern, repl, string, count=0, flags=0): """Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, flags).sub(repl, string, count)
[ "Return", "the", "string", "obtained", "by", "replacing", "the", "leftmost", "non", "-", "overlapping", "occurrences", "of", "the", "pattern", "in", "string", "by", "the", "replacement", "repl", ".", "repl", "can", "be", "either", "a", "string", "or", "a", ...
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/re.py#L151-L158
[ "def", "sub", "(", "pattern", ",", "repl", ",", "string", ",", "count", "=", "0", ",", "flags", "=", "0", ")", ":", "return", "_compile", "(", "pattern", ",", "flags", ")", ".", "sub", "(", "repl", ",", "string", ",", "count", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
subn
Return a 2-tuple containing (new_string, number). new_string is the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it's passed the match object and must return a replacement string to be used.
third_party/stdlib/re.py
def subn(pattern, repl, string, count=0, flags=0): """Return a 2-tuple containing (new_string, number). new_string is the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, flags).subn(repl, string, count)
def subn(pattern, repl, string, count=0, flags=0): """Return a 2-tuple containing (new_string, number). new_string is the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in the source string by the replacement repl. number is the number of substitutions that were made. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it's passed the match object and must return a replacement string to be used.""" return _compile(pattern, flags).subn(repl, string, count)
[ "Return", "a", "2", "-", "tuple", "containing", "(", "new_string", "number", ")", ".", "new_string", "is", "the", "string", "obtained", "by", "replacing", "the", "leftmost", "non", "-", "overlapping", "occurrences", "of", "the", "pattern", "in", "the", "sour...
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/re.py#L160-L169
[ "def", "subn", "(", "pattern", ",", "repl", ",", "string", ",", "count", "=", "0", ",", "flags", "=", "0", ")", ":", "return", "_compile", "(", "pattern", ",", "flags", ")", ".", "subn", "(", "repl", ",", "string", ",", "count", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
split
Split the source string by the occurrences of the pattern, returning a list containing the resulting substrings.
third_party/stdlib/re.py
def split(pattern, string, maxsplit=0, flags=0): """Split the source string by the occurrences of the pattern, returning a list containing the resulting substrings.""" return _compile(pattern, flags).split(string, maxsplit)
def split(pattern, string, maxsplit=0, flags=0): """Split the source string by the occurrences of the pattern, returning a list containing the resulting substrings.""" return _compile(pattern, flags).split(string, maxsplit)
[ "Split", "the", "source", "string", "by", "the", "occurrences", "of", "the", "pattern", "returning", "a", "list", "containing", "the", "resulting", "substrings", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/re.py#L171-L174
[ "def", "split", "(", "pattern", ",", "string", ",", "maxsplit", "=", "0", ",", "flags", "=", "0", ")", ":", "return", "_compile", "(", "pattern", ",", "flags", ")", ".", "split", "(", "string", ",", "maxsplit", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
findall
Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result.
third_party/stdlib/re.py
def findall(pattern, string, flags=0): """Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result.""" return _compile(pattern, flags).findall(string) # if sys.hexversion >= 0x02020000: # __all__.append("finditer") def finditer(pattern, string, flags=0): """Return an iterator over all non-overlapping matches in the string. For each match, the iterator returns a match object. Empty matches are included in the result.""" return _compile(pattern, flags).finditer(string)
def findall(pattern, string, flags=0): """Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result.""" return _compile(pattern, flags).findall(string) # if sys.hexversion >= 0x02020000: # __all__.append("finditer") def finditer(pattern, string, flags=0): """Return an iterator over all non-overlapping matches in the string. For each match, the iterator returns a match object. Empty matches are included in the result.""" return _compile(pattern, flags).finditer(string)
[ "Return", "a", "list", "of", "all", "non", "-", "overlapping", "matches", "in", "the", "string", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/re.py#L176-L193
[ "def", "findall", "(", "pattern", ",", "string", ",", "flags", "=", "0", ")", ":", "return", "_compile", "(", "pattern", ",", "flags", ")", ".", "findall", "(", "string", ")", "# if sys.hexversion >= 0x02020000:", "# __all__.append(\"finditer\")", "def", "fi...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
escape
Escape all non-alphanumeric characters in pattern.
third_party/stdlib/re.py
def escape(pattern): "Escape all non-alphanumeric characters in pattern." s = list(pattern) alphanum = _alphanum for i, c in enumerate(pattern): if c not in alphanum: if c == "\000": s[i] = "\\000" else: s[i] = "\\" + c return pattern[:0].join(s)
def escape(pattern): "Escape all non-alphanumeric characters in pattern." s = list(pattern) alphanum = _alphanum for i, c in enumerate(pattern): if c not in alphanum: if c == "\000": s[i] = "\\000" else: s[i] = "\\" + c return pattern[:0].join(s)
[ "Escape", "all", "non", "-", "alphanumeric", "characters", "in", "pattern", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/re.py#L211-L221
[ "def", "escape", "(", "pattern", ")", ":", "s", "=", "list", "(", "pattern", ")", "alphanum", "=", "_alphanum", "for", "i", ",", "c", "in", "enumerate", "(", "pattern", ")", ":", "if", "c", "not", "in", "alphanum", ":", "if", "c", "==", "\"\\000\""...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Block.alloc_temp
Create a new temporary Go variable having type type_ for this block.
compiler/block.py
def alloc_temp(self, type_='*πg.Object'): """Create a new temporary Go variable having type type_ for this block.""" for v in sorted(self.free_temps, key=lambda k: k.name): if v.type_ == type_: self.free_temps.remove(v) self.used_temps.add(v) return v self.temp_index += 1 name = 'πTemp{:03d}'.format(self.temp_index) v = expr.GeneratedTempVar(self, name, type_) self.used_temps.add(v) return v
def alloc_temp(self, type_='*πg.Object'): """Create a new temporary Go variable having type type_ for this block.""" for v in sorted(self.free_temps, key=lambda k: k.name): if v.type_ == type_: self.free_temps.remove(v) self.used_temps.add(v) return v self.temp_index += 1 name = 'πTemp{:03d}'.format(self.temp_index) v = expr.GeneratedTempVar(self, name, type_) self.used_temps.add(v) return v
[ "Create", "a", "new", "temporary", "Go", "variable", "having", "type", "type_", "for", "this", "block", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/compiler/block.py#L108-L119
[ "def", "alloc_temp", "(", "self", ",", "type_", "=", "'*πg.Object')", ":", "", "for", "v", "in", "sorted", "(", "self", ".", "free_temps", ",", "key", "=", "lambda", "k", ":", "k", ".", "name", ")", ":", "if", "v", ".", "type_", "==", "type_", ":...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
Block.free_temp
Release the GeneratedTempVar v so it can be reused.
compiler/block.py
def free_temp(self, v): """Release the GeneratedTempVar v so it can be reused.""" self.used_temps.remove(v) self.free_temps.add(v)
def free_temp(self, v): """Release the GeneratedTempVar v so it can be reused.""" self.used_temps.remove(v) self.free_temps.add(v)
[ "Release", "the", "GeneratedTempVar", "v", "so", "it", "can", "be", "reused", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/compiler/block.py#L121-L124
[ "def", "free_temp", "(", "self", ",", "v", ")", ":", "self", ".", "used_temps", ".", "remove", "(", "v", ")", "self", ".", "free_temps", ".", "add", "(", "v", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
parse_buffer
Like :meth:`parse`, but accepts a :class:`source.Buffer` instead of source and filename, and returns comments as well. :see: :meth:`parse` :return: (:class:`ast.AST`, list of :class:`source.Comment`) Abstract syntax tree and comments
third_party/pythonparser/__init__.py
def parse_buffer(buffer, mode="exec", flags=[], version=None, engine=None): """ Like :meth:`parse`, but accepts a :class:`source.Buffer` instead of source and filename, and returns comments as well. :see: :meth:`parse` :return: (:class:`ast.AST`, list of :class:`source.Comment`) Abstract syntax tree and comments """ if version is None: version = sys.version_info[0:2] if engine is None: engine = pythonparser_diagnostic.Engine() lexer = pythonparser_lexer.Lexer(buffer, version, engine) if mode in ("single", "eval"): lexer.interactive = True parser = pythonparser_parser.Parser(lexer, version, engine) parser.add_flags(flags) if mode == "exec": return parser.file_input(), lexer.comments elif mode == "single": return parser.single_input(), lexer.comments elif mode == "eval": return parser.eval_input(), lexer.comments
def parse_buffer(buffer, mode="exec", flags=[], version=None, engine=None): """ Like :meth:`parse`, but accepts a :class:`source.Buffer` instead of source and filename, and returns comments as well. :see: :meth:`parse` :return: (:class:`ast.AST`, list of :class:`source.Comment`) Abstract syntax tree and comments """ if version is None: version = sys.version_info[0:2] if engine is None: engine = pythonparser_diagnostic.Engine() lexer = pythonparser_lexer.Lexer(buffer, version, engine) if mode in ("single", "eval"): lexer.interactive = True parser = pythonparser_parser.Parser(lexer, version, engine) parser.add_flags(flags) if mode == "exec": return parser.file_input(), lexer.comments elif mode == "single": return parser.single_input(), lexer.comments elif mode == "eval": return parser.eval_input(), lexer.comments
[ "Like", ":", "meth", ":", "parse", "but", "accepts", "a", ":", "class", ":", "source", ".", "Buffer", "instead", "of", "source", "and", "filename", "and", "returns", "comments", "as", "well", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pythonparser/__init__.py#L5-L33
[ "def", "parse_buffer", "(", "buffer", ",", "mode", "=", "\"exec\"", ",", "flags", "=", "[", "]", ",", "version", "=", "None", ",", "engine", "=", "None", ")", ":", "if", "version", "is", "None", ":", "version", "=", "sys", ".", "version_info", "[", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
parse
Parse a string into an abstract syntax tree. This is the replacement for the built-in :meth:`..ast.parse`. :param source: (string) Source code in the correct encoding :param filename: (string) Filename of the source (used in diagnostics) :param mode: (string) Execution mode. Pass ``"exec"`` to parse a module, ``"single"`` to parse a single (interactive) statement, and ``"eval"`` to parse an expression. In the last two cases, ``source`` must be terminated with an empty line (i.e. end with ``"\\n\\n"``). :param flags: (list of string) Future flags. Equivalent to ``from __future__ import <flags>``. :param version: (2-tuple of int) Major and minor version of Python syntax to recognize, ``sys.version_info[0:2]`` by default. :param engine: (:class:`diagnostic.Engine`) Diagnostic engine, a fresh one is created by default :return: (:class:`ast.AST`) Abstract syntax tree :raise: :class:`diagnostic.Error` if the source code is not well-formed
third_party/pythonparser/__init__.py
def parse(source, filename="<unknown>", mode="exec", flags=[], version=None, engine=None): """ Parse a string into an abstract syntax tree. This is the replacement for the built-in :meth:`..ast.parse`. :param source: (string) Source code in the correct encoding :param filename: (string) Filename of the source (used in diagnostics) :param mode: (string) Execution mode. Pass ``"exec"`` to parse a module, ``"single"`` to parse a single (interactive) statement, and ``"eval"`` to parse an expression. In the last two cases, ``source`` must be terminated with an empty line (i.e. end with ``"\\n\\n"``). :param flags: (list of string) Future flags. Equivalent to ``from __future__ import <flags>``. :param version: (2-tuple of int) Major and minor version of Python syntax to recognize, ``sys.version_info[0:2]`` by default. :param engine: (:class:`diagnostic.Engine`) Diagnostic engine, a fresh one is created by default :return: (:class:`ast.AST`) Abstract syntax tree :raise: :class:`diagnostic.Error` if the source code is not well-formed """ ast, comments = parse_buffer(pythonparser_source.Buffer(source, filename), mode, flags, version, engine) return ast
def parse(source, filename="<unknown>", mode="exec", flags=[], version=None, engine=None): """ Parse a string into an abstract syntax tree. This is the replacement for the built-in :meth:`..ast.parse`. :param source: (string) Source code in the correct encoding :param filename: (string) Filename of the source (used in diagnostics) :param mode: (string) Execution mode. Pass ``"exec"`` to parse a module, ``"single"`` to parse a single (interactive) statement, and ``"eval"`` to parse an expression. In the last two cases, ``source`` must be terminated with an empty line (i.e. end with ``"\\n\\n"``). :param flags: (list of string) Future flags. Equivalent to ``from __future__ import <flags>``. :param version: (2-tuple of int) Major and minor version of Python syntax to recognize, ``sys.version_info[0:2]`` by default. :param engine: (:class:`diagnostic.Engine`) Diagnostic engine, a fresh one is created by default :return: (:class:`ast.AST`) Abstract syntax tree :raise: :class:`diagnostic.Error` if the source code is not well-formed """ ast, comments = parse_buffer(pythonparser_source.Buffer(source, filename), mode, flags, version, engine) return ast
[ "Parse", "a", "string", "into", "an", "abstract", "syntax", "tree", ".", "This", "is", "the", "replacement", "for", "the", "built", "-", "in", ":", "meth", ":", "..", "ast", ".", "parse", "." ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/pythonparser/__init__.py#L35-L60
[ "def", "parse", "(", "source", ",", "filename", "=", "\"<unknown>\"", ",", "mode", "=", "\"exec\"", ",", "flags", "=", "[", "]", ",", "version", "=", "None", ",", "engine", "=", "None", ")", ":", "ast", ",", "comments", "=", "parse_buffer", "(", "pyt...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
encode
Uuencode file
third_party/stdlib/uu.py
def encode(in_file, out_file, name=None, mode=None): """Uuencode file""" # # If in_file is a pathname open it and change defaults # opened_files = [] try: if in_file == '-': in_file = sys.stdin elif isinstance(in_file, basestring): if name is None: name = os.path.basename(in_file) if mode is None: try: mode = os.stat(in_file).st_mode except AttributeError: pass in_file = open(in_file, 'rb') opened_files.append(in_file) # # Open out_file if it is a pathname # if out_file == '-': out_file = sys.stdout elif isinstance(out_file, basestring): out_file = open(out_file, 'wb') opened_files.append(out_file) # # Set defaults for name and mode # if name is None: name = '-' if mode is None: mode = 0666 # # Write the data # out_file.write('begin %o %s\n' % ((mode&0777),name)) data = in_file.read(45) while len(data) > 0: out_file.write(binascii.b2a_uu(data)) data = in_file.read(45) out_file.write(' \nend\n') finally: for f in opened_files: f.close()
def encode(in_file, out_file, name=None, mode=None): """Uuencode file""" # # If in_file is a pathname open it and change defaults # opened_files = [] try: if in_file == '-': in_file = sys.stdin elif isinstance(in_file, basestring): if name is None: name = os.path.basename(in_file) if mode is None: try: mode = os.stat(in_file).st_mode except AttributeError: pass in_file = open(in_file, 'rb') opened_files.append(in_file) # # Open out_file if it is a pathname # if out_file == '-': out_file = sys.stdout elif isinstance(out_file, basestring): out_file = open(out_file, 'wb') opened_files.append(out_file) # # Set defaults for name and mode # if name is None: name = '-' if mode is None: mode = 0666 # # Write the data # out_file.write('begin %o %s\n' % ((mode&0777),name)) data = in_file.read(45) while len(data) > 0: out_file.write(binascii.b2a_uu(data)) data = in_file.read(45) out_file.write(' \nend\n') finally: for f in opened_files: f.close()
[ "Uuencode", "file" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/uu.py#L42-L87
[ "def", "encode", "(", "in_file", ",", "out_file", ",", "name", "=", "None", ",", "mode", "=", "None", ")", ":", "#", "# If in_file is a pathname open it and change defaults", "#", "opened_files", "=", "[", "]", "try", ":", "if", "in_file", "==", "'-'", ":", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
decode
Decode uuencoded file
third_party/stdlib/uu.py
def decode(in_file, out_file=None, mode=None, quiet=0): """Decode uuencoded file""" # # Open the input file, if needed. # opened_files = [] if in_file == '-': in_file = sys.stdin elif isinstance(in_file, basestring): in_file = open(in_file) opened_files.append(in_file) try: # # Read until a begin is encountered or we've exhausted the file # while True: hdr = in_file.readline() if not hdr: raise Error('No valid begin line found in input file') if not hdr.startswith('begin'): continue hdrfields = hdr.split(' ', 2) if len(hdrfields) == 3 and hdrfields[0] == 'begin': try: int(hdrfields[1], 8) break except ValueError: pass if out_file is None: out_file = hdrfields[2].rstrip() if os.path.exists(out_file): raise Error('Cannot overwrite existing file: %s' % out_file) if mode is None: mode = int(hdrfields[1], 8) # # Open the output file # if out_file == '-': out_file = sys.stdout elif isinstance(out_file, basestring): fp = open(out_file, 'wb') try: os.path.chmod(out_file, mode) except AttributeError: pass out_file = fp opened_files.append(out_file) # # Main decoding loop # s = in_file.readline() while s and s.strip() != 'end': try: data = binascii.a2b_uu(s) except binascii.Error, v: # Workaround for broken uuencoders by /Fredrik Lundh nbytes = (((ord(s[0])-32) & 63) * 4 + 5) // 3 data = binascii.a2b_uu(s[:nbytes]) if not quiet: sys.stderr.write("Warning: %s\n" % v) out_file.write(data) s = in_file.readline() if not s: raise Error('Truncated input file') finally: for f in opened_files: f.close()
def decode(in_file, out_file=None, mode=None, quiet=0): """Decode uuencoded file""" # # Open the input file, if needed. # opened_files = [] if in_file == '-': in_file = sys.stdin elif isinstance(in_file, basestring): in_file = open(in_file) opened_files.append(in_file) try: # # Read until a begin is encountered or we've exhausted the file # while True: hdr = in_file.readline() if not hdr: raise Error('No valid begin line found in input file') if not hdr.startswith('begin'): continue hdrfields = hdr.split(' ', 2) if len(hdrfields) == 3 and hdrfields[0] == 'begin': try: int(hdrfields[1], 8) break except ValueError: pass if out_file is None: out_file = hdrfields[2].rstrip() if os.path.exists(out_file): raise Error('Cannot overwrite existing file: %s' % out_file) if mode is None: mode = int(hdrfields[1], 8) # # Open the output file # if out_file == '-': out_file = sys.stdout elif isinstance(out_file, basestring): fp = open(out_file, 'wb') try: os.path.chmod(out_file, mode) except AttributeError: pass out_file = fp opened_files.append(out_file) # # Main decoding loop # s = in_file.readline() while s and s.strip() != 'end': try: data = binascii.a2b_uu(s) except binascii.Error, v: # Workaround for broken uuencoders by /Fredrik Lundh nbytes = (((ord(s[0])-32) & 63) * 4 + 5) // 3 data = binascii.a2b_uu(s[:nbytes]) if not quiet: sys.stderr.write("Warning: %s\n" % v) out_file.write(data) s = in_file.readline() if not s: raise Error('Truncated input file') finally: for f in opened_files: f.close()
[ "Decode", "uuencoded", "file" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/uu.py#L90-L156
[ "def", "decode", "(", "in_file", ",", "out_file", "=", "None", ",", "mode", "=", "None", ",", "quiet", "=", "0", ")", ":", "#", "# Open the input file, if needed.", "#", "opened_files", "=", "[", "]", "if", "in_file", "==", "'-'", ":", "in_file", "=", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
capwords
capwords(s [,sep]) -> string Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join. If the optional second argument sep is absent or None, runs of whitespace characters are replaced by a single space and leading and trailing whitespace are removed, otherwise sep is used to split and join the words.
third_party/stdlib/string.py
def capwords(s, sep=None): """capwords(s [,sep]) -> string Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join. If the optional second argument sep is absent or None, runs of whitespace characters are replaced by a single space and leading and trailing whitespace are removed, otherwise sep is used to split and join the words. """ return (sep or ' ').join(x.capitalize() for x in s.split(sep))
def capwords(s, sep=None): """capwords(s [,sep]) -> string Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join. If the optional second argument sep is absent or None, runs of whitespace characters are replaced by a single space and leading and trailing whitespace are removed, otherwise sep is used to split and join the words. """ return (sep or ' ').join(x.capitalize() for x in s.split(sep))
[ "capwords", "(", "s", "[", "sep", "]", ")", "-", ">", "string" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/string.py#L47-L58
[ "def", "capwords", "(", "s", ",", "sep", "=", "None", ")", ":", "return", "(", "sep", "or", "' '", ")", ".", "join", "(", "x", ".", "capitalize", "(", ")", "for", "x", "in", "s", ".", "split", "(", "sep", ")", ")" ]
3ec87959189cfcdeae82eb68a47648ac25ceb10b
valid
maketrans
maketrans(frm, to) -> string Return a translation table (a string of 256 bytes long) suitable for use in string.translate. The strings frm and to must be of the same length.
third_party/stdlib/string.py
def maketrans(fromstr, tostr): """maketrans(frm, to) -> string Return a translation table (a string of 256 bytes long) suitable for use in string.translate. The strings frm and to must be of the same length. """ if len(fromstr) != len(tostr): raise ValueError, "maketrans arguments must have same length" global _idmapL if not _idmapL: _idmapL = list(_idmap) L = _idmapL[:] fromstr = map(ord, fromstr) for i in range(len(fromstr)): L[fromstr[i]] = tostr[i] return ''.join(L)
def maketrans(fromstr, tostr): """maketrans(frm, to) -> string Return a translation table (a string of 256 bytes long) suitable for use in string.translate. The strings frm and to must be of the same length. """ if len(fromstr) != len(tostr): raise ValueError, "maketrans arguments must have same length" global _idmapL if not _idmapL: _idmapL = list(_idmap) L = _idmapL[:] fromstr = map(ord, fromstr) for i in range(len(fromstr)): L[fromstr[i]] = tostr[i] return ''.join(L)
[ "maketrans", "(", "frm", "to", ")", "-", ">", "string" ]
google/grumpy
python
https://github.com/google/grumpy/blob/3ec87959189cfcdeae82eb68a47648ac25ceb10b/third_party/stdlib/string.py#L63-L80
[ "def", "maketrans", "(", "fromstr", ",", "tostr", ")", ":", "if", "len", "(", "fromstr", ")", "!=", "len", "(", "tostr", ")", ":", "raise", "ValueError", ",", "\"maketrans arguments must have same length\"", "global", "_idmapL", "if", "not", "_idmapL", ":", ...
3ec87959189cfcdeae82eb68a47648ac25ceb10b