nwo
stringlengths
10
28
sha
stringlengths
40
40
path
stringlengths
11
97
identifier
stringlengths
1
64
parameters
stringlengths
2
2.24k
return_statement
stringlengths
0
2.17k
docstring
stringlengths
0
5.45k
docstring_summary
stringlengths
0
3.83k
func_begin
int64
1
13.4k
func_end
int64
2
13.4k
function
stringlengths
28
56.4k
url
stringlengths
106
209
project
int64
1
48
executed_lines
list
executed_lines_pc
float64
0
153
missing_lines
list
missing_lines_pc
float64
0
100
covered
bool
2 classes
filecoverage
float64
2.53
100
function_lines
int64
2
1.46k
mccabe
int64
1
253
coverage
float64
0
100
docstring_lines
int64
0
112
function_nodoc
stringlengths
9
56.4k
id
int64
0
29.8k
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.position
(self)
return p
The current position (as a position_marker object). Returns a copy.
The current position (as a position_marker object). Returns a copy.
1,727
1,735
def position(self): """The current position (as a position_marker object). Returns a copy. """ p = self.__pos.copy() p.text_after = self.text_context p.at_end = self.at_end return p
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1727-L1735
25
[ 0, 1, 2, 3, 4 ]
55.555556
[ 5, 6, 7, 8 ]
44.444444
false
14.825334
9
1
55.555556
2
def position(self): p = self.__pos.copy() p.text_after = self.text_context p.at_end = self.at_end return p
18,439
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.at_start
(self)
return self.__pos.at_start
Returns True if the position is currently at the start of the document, or False otherwise.
Returns True if the position is currently at the start of the document, or False otherwise.
1,738
1,743
def at_start(self): """Returns True if the position is currently at the start of the document, or False otherwise. """ return self.__pos.at_start
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1738-L1743
25
[ 0, 1, 2, 3, 4 ]
83.333333
[ 5 ]
16.666667
false
14.825334
6
1
83.333333
2
def at_start(self): return self.__pos.at_start
18,440
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.at_end
(self)
return (not c)
Returns True if the position is currently at the end of the document, of False otherwise.
Returns True if the position is currently at the end of the document, of False otherwise.
1,746
1,752
def at_end(self): """Returns True if the position is currently at the end of the document, of False otherwise. """ c = self.peek() return (not c)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1746-L1752
25
[ 0, 1, 2, 3, 4 ]
71.428571
[ 5, 6 ]
28.571429
false
14.825334
7
1
71.428571
2
def at_end(self): c = self.peek() return (not c)
18,441
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.at_ws
(self, allow_unicode_whitespace=True)
Returns True if the current position contains a white-space character.
Returns True if the current position contains a white-space character.
1,754
1,765
def at_ws(self, allow_unicode_whitespace=True): """Returns True if the current position contains a white-space character. """ c = self.peek() if not c: return False elif allow_unicode_whitespace: return helpers.char_is_unicode_ws(c) else: return helpers.char_is_json_ws(c)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1754-L1765
25
[ 0, 1, 2, 3, 4 ]
41.666667
[ 5, 6, 7, 8, 9, 11 ]
50
false
14.825334
12
3
50
2
def at_ws(self, allow_unicode_whitespace=True): c = self.peek() if not c: return False elif allow_unicode_whitespace: return helpers.char_is_unicode_ws(c) else: return helpers.char_is_json_ws(c)
18,442
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.at_eol
(self, allow_unicode_eol=True)
Returns True if the current position contains an end-of-line control character.
Returns True if the current position contains an end-of-line control character.
1,767
1,778
def at_eol(self, allow_unicode_eol=True): """Returns True if the current position contains an end-of-line control character. """ c = self.peek() if not c: return True # End of file is treated as end of line elif allow_unicode_eol: return helpers.char_is_unicode_eol(c) else: return helpers.char_is_json_eol(c)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1767-L1778
25
[ 0, 1, 2, 3, 4 ]
41.666667
[ 5, 6, 7, 8, 9, 11 ]
50
false
14.825334
12
3
50
2
def at_eol(self, allow_unicode_eol=True): c = self.peek() if not c: return True # End of file is treated as end of line elif allow_unicode_eol: return helpers.char_is_unicode_eol(c) else: return helpers.char_is_json_eol(c)
18,443
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.peek
(self, offset=0)
return self.__rawbuf[i]
Returns the character at the current position, or at a given offset away from the current position. If the position is beyond the limits of the document size, then an empty string '' is returned.
Returns the character at the current position, or at a given offset away from the current position. If the position is beyond the limits of the document size, then an empty string '' is returned.
1,780
1,790
def peek(self, offset=0): """Returns the character at the current position, or at a given offset away from the current position. If the position is beyond the limits of the document size, then an empty string '' is returned. """ i = self.cpos + offset if i < 0 or i >= self.__cmax: return '' return self.__rawbuf[i]
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1780-L1790
25
[ 0, 1, 2, 3, 4, 5, 6 ]
63.636364
[ 7, 8, 9, 10 ]
36.363636
false
14.825334
11
3
63.636364
4
def peek(self, offset=0): i = self.cpos + offset if i < 0 or i >= self.__cmax: return '' return self.__rawbuf[i]
18,444
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.peekstr
(self, span=1, offset=0)
return self.__rawbuf[i: j]
Returns one or more characters starting at the current position, or at a given offset away from the current position, and continuing for the given span length. If the offset and span go outside the limit of the current document size, then the returned string may be shorter than the requested span length.
Returns one or more characters starting at the current position, or at a given offset away from the current position, and continuing for the given span length. If the offset and span go outside the limit of the current document size, then the returned string may be shorter than the requested span length.
1,792
1,805
def peekstr(self, span=1, offset=0): """Returns one or more characters starting at the current position, or at a given offset away from the current position, and continuing for the given span length. If the offset and span go outside the limit of the current document size, then the returned string may be shorter than the requested span length. """ i = self.cpos + offset j = i + span if i < 0 or i >= self.__cmax: return '' return self.__rawbuf[i: j]
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1792-L1805
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
64.285714
[ 9, 10, 11, 12, 13 ]
35.714286
false
14.825334
14
3
64.285714
6
def peekstr(self, span=1, offset=0): i = self.cpos + offset j = i + span if i < 0 or i >= self.__cmax: return '' return self.__rawbuf[i: j]
18,445
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.text_context
(self, context_size=20)
return s
A short human-readable textual excerpt of the document at the current position, in English.
A short human-readable textual excerpt of the document at the current position, in English.
1,808
1,819
def text_context(self, context_size=20): """A short human-readable textual excerpt of the document at the current position, in English. """ context_size = max(context_size, 4) s = self.peekstr(context_size + 1) if not s: return '' if len(s) > context_size: s = s[:context_size - 3] + "..." return s
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1808-L1819
25
[ 0, 1, 2, 3, 4 ]
41.666667
[ 5, 6, 7, 8, 9, 10, 11 ]
58.333333
false
14.825334
12
3
41.666667
2
def text_context(self, context_size=20): context_size = max(context_size, 4) s = self.peekstr(context_size + 1) if not s: return '' if len(s) > context_size: s = s[:context_size - 3] + "..." return s
18,446
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.startswith
(self, s)
return s == s2
Determines if the text at the current position starts with the given string. See also method: pop_if_startswith()
Determines if the text at the current position starts with the given string.
1,821
1,829
def startswith(self, s): """Determines if the text at the current position starts with the given string. See also method: pop_if_startswith() """ s2 = self.peekstr(len(s)) return s == s2
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1821-L1829
25
[ 0, 1, 2, 3, 4, 5, 6 ]
77.777778
[ 7, 8 ]
22.222222
false
14.825334
9
1
77.777778
4
def startswith(self, s): s2 = self.peekstr(len(s)) return s == s2
18,447
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.skip
(self, span=1)
return self.cpos - i
Advances the current position by one (or the given number) of characters. Will not advance beyond the end of the document. Returns the number of characters skipped.
Advances the current position by one (or the given number) of characters. Will not advance beyond the end of the document. Returns the number of characters skipped.
1,831
1,840
def skip(self, span=1): """Advances the current position by one (or the given number) of characters. Will not advance beyond the end of the document. Returns the number of characters skipped. """ i = self.cpos self.__pos.advance(self.peekstr(span)) return self.cpos - i
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1831-L1840
25
[ 0, 1, 2, 3, 4, 5, 6 ]
70
[ 7, 8, 9 ]
30
false
14.825334
10
1
70
3
def skip(self, span=1): i = self.cpos self.__pos.advance(self.peekstr(span)) return self.cpos - i
18,448
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.skipuntil
(self, testfn)
return self.cpos - i
Advances the current position until a given predicate test function succeeds, or the end of the document is reached. Returns the actual number of characters skipped. The provided test function should take a single unicode character and return a boolean value, such as: lambda c : c == '.' # Skip to next period See also methods: skipwhile() and popuntil()
Advances the current position until a given predicate test function succeeds, or the end of the document is reached.
1,842
1,863
def skipuntil(self, testfn): """Advances the current position until a given predicate test function succeeds, or the end of the document is reached. Returns the actual number of characters skipped. The provided test function should take a single unicode character and return a boolean value, such as: lambda c : c == '.' # Skip to next period See also methods: skipwhile() and popuntil() """ i = self.cpos while True: c = self.peek() if not c or testfn(c): break else: self.__pos.advance(c) return self.cpos - i
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1842-L1863
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
63.636364
[ 14, 15, 16, 17, 18, 20, 21 ]
31.818182
false
14.825334
22
4
68.181818
11
def skipuntil(self, testfn): i = self.cpos while True: c = self.peek() if not c or testfn(c): break else: self.__pos.advance(c) return self.cpos - i
18,449
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.skipwhile
(self, testfn)
return self.skipuntil(lambda c: not testfn(c))
Advances the current position until a given predicate test function fails, or the end of the document is reached. Returns the actual number of characters skipped. The provided test function should take a single unicode character and return a boolean value, such as: lambda c : c.isdigit() # Skip all digits See also methods: skipuntil() and popwhile()
Advances the current position until a given predicate test function fails, or the end of the document is reached.
1,865
1,879
def skipwhile(self, testfn): """Advances the current position until a given predicate test function fails, or the end of the document is reached. Returns the actual number of characters skipped. The provided test function should take a single unicode character and return a boolean value, such as: lambda c : c.isdigit() # Skip all digits See also methods: skipuntil() and popwhile() """ return self.skipuntil(lambda c: not testfn(c))
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1865-L1879
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
93.333333
[ 14 ]
6.666667
false
14.825334
15
1
93.333333
11
def skipwhile(self, testfn): return self.skipuntil(lambda c: not testfn(c))
18,450
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.skip_to_next_line
(self, allow_unicode_eol=True)
Advances the current position to the start of the next line. Will not advance beyond the end of the file. Note that the two-character sequence CR+LF is recognized as being just a single end-of-line marker.
Advances the current position to the start of the next line. Will not advance beyond the end of the file. Note that the two-character sequence CR+LF is recognized as being just a single end-of-line marker.
1,881
1,894
def skip_to_next_line(self, allow_unicode_eol=True): """Advances the current position to the start of the next line. Will not advance beyond the end of the file. Note that the two-character sequence CR+LF is recognized as being just a single end-of-line marker. """ ln = self.__pos.line while True: c = self.pop() if not c or self.__pos.line > ln: if c == '\r' and self.peek() == '\n': self.skip() break
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1881-L1894
25
[ 0, 1, 2, 3, 4, 5, 6 ]
50
[ 7, 8, 9, 10, 11, 12, 13 ]
50
false
14.825334
14
6
50
4
def skip_to_next_line(self, allow_unicode_eol=True): ln = self.__pos.line while True: c = self.pop() if not c or self.__pos.line > ln: if c == '\r' and self.peek() == '\n': self.skip() break
18,451
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.skipws
(self, allow_unicode_whitespace=True)
return n
Advances the current position past all whitespace, or until the end of the document is reached.
Advances the current position past all whitespace, or until the end of the document is reached.
1,896
1,906
def skipws(self, allow_unicode_whitespace=True): """Advances the current position past all whitespace, or until the end of the document is reached. """ if allow_unicode_whitespace: n = self.skipwhile(helpers.char_is_unicode_ws) else: n = self.skipwhile(helpers.char_is_json_ws) self.num_ws_skipped += n return n
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1896-L1906
25
[ 0, 1, 2, 3, 4 ]
45.454545
[ 5, 6, 8, 9, 10 ]
45.454545
false
14.825334
11
2
54.545455
2
def skipws(self, allow_unicode_whitespace=True): if allow_unicode_whitespace: n = self.skipwhile(helpers.char_is_unicode_ws) else: n = self.skipwhile(helpers.char_is_json_ws) self.num_ws_skipped += n return n
18,452
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.pop
(self)
return c
Returns the character at the current position and advances the position to the next character. At the end of the document this function returns an empty string.
Returns the character at the current position and advances the position to the next character. At the end of the document this function returns an empty string.
1,908
1,917
def pop(self): """Returns the character at the current position and advances the position to the next character. At the end of the document this function returns an empty string. """ c = self.peek() if c: self.__pos.advance(c) return c
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1908-L1917
25
[ 0, 1, 2, 3, 4, 5 ]
60
[ 6, 7, 8, 9 ]
40
false
14.825334
10
2
60
3
def pop(self): c = self.peek() if c: self.__pos.advance(c) return c
18,453
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.popstr
(self, span=1, offset=0)
return s
Returns a string of one or more characters starting at the current position, and advances the position to the following character after the span. Will not go beyond the end of the document, so the returned string may be shorter than the requested span.
Returns a string of one or more characters starting at the current position, and advances the position to the following character after the span. Will not go beyond the end of the document, so the returned string may be shorter than the requested span.
1,919
1,930
def popstr(self, span=1, offset=0): """Returns a string of one or more characters starting at the current position, and advances the position to the following character after the span. Will not go beyond the end of the document, so the returned string may be shorter than the requested span. """ s = self.peekstr(span) if s: self.__pos.advance(s) return s
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1919-L1930
25
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
66.666667
[ 8, 9, 10, 11 ]
33.333333
false
14.825334
12
2
66.666667
5
def popstr(self, span=1, offset=0): s = self.peekstr(span) if s: self.__pos.advance(s) return s
18,454
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.popif
(self, testfn)
return ''
Just like the pop() function, but only returns the character if the given predicate test function succeeds.
Just like the pop() function, but only returns the character if the given predicate test function succeeds.
1,932
1,940
def popif(self, testfn): """Just like the pop() function, but only returns the character if the given predicate test function succeeds. """ c = self.peek() if c and testfn(c): self.__pos.advance(c) return c return ''
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1932-L1940
25
[ 0, 1, 2, 3 ]
44.444444
[ 4, 5, 6, 7, 8 ]
55.555556
false
14.825334
9
3
44.444444
2
def popif(self, testfn): c = self.peek() if c and testfn(c): self.__pos.advance(c) return c return ''
18,455
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.pop_while_in
(self, chars)
return None
Pops a sequence of characters at the current position as long as each of them is in the given set of characters.
Pops a sequence of characters at the current position as long as each of them is in the given set of characters.
1,942
1,953
def pop_while_in(self, chars): """Pops a sequence of characters at the current position as long as each of them is in the given set of characters. """ if not isinstance(chars, (set, frozenset)): cset = set(chars) c = self.peek() if c and c in cset: s = self.popwhile(lambda c: c and c in cset) return s return None
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1942-L1953
25
[ 0, 1, 2, 3, 4 ]
41.666667
[ 5, 6, 7, 8, 9, 10, 11 ]
58.333333
false
14.825334
12
5
41.666667
2
def pop_while_in(self, chars): if not isinstance(chars, (set, frozenset)): cset = set(chars) c = self.peek() if c and c in cset: s = self.popwhile(lambda c: c and c in cset) return s return None
18,456
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.pop_identifier
(self, match=None)
return None
Pops the sequence of characters at the current position that match the syntax for a JavaScript identifier.
Pops the sequence of characters at the current position that match the syntax for a JavaScript identifier.
1,955
1,964
def pop_identifier(self, match=None): """Pops the sequence of characters at the current position that match the syntax for a JavaScript identifier. """ c = self.peek() if c and helpers.char_is_identifier_leader(c): s = self.popwhile(helpers.char_is_identifier_tail) return s return None
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1955-L1964
25
[ 0, 1, 2, 3, 4 ]
50
[ 5, 6, 7, 8, 9 ]
50
false
14.825334
10
3
50
2
def pop_identifier(self, match=None): c = self.peek() if c and helpers.char_is_identifier_leader(c): s = self.popwhile(helpers.char_is_identifier_tail) return s return None
18,457
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.pop_if_startswith
(self, s)
return s2
Pops the sequence of characters if they match the given string. See also method: startswith()
Pops the sequence of characters if they match the given string.
1,966
1,976
def pop_if_startswith(self, s): """Pops the sequence of characters if they match the given string. See also method: startswith() """ s2 = self.peekstr(len(s)) if s2 != s: return None self.__pos.advance(s2) return s2
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1966-L1976
25
[ 0, 1, 2, 3, 4, 5 ]
54.545455
[ 6, 7, 8, 9, 10 ]
45.454545
false
14.825334
11
2
54.545455
3
def pop_if_startswith(self, s): s2 = self.peekstr(len(s)) if s2 != s: return None self.__pos.advance(s2) return s2
18,458
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.popwhile
(self, testfn, maxchars=None)
return ''.join(s)
Pops all the characters starting at the current position as long as each character passes the given predicate function test. If maxchars a numeric value instead of None then then no more than that number of characters will be popped regardless of the predicate test. See also methods: skipwhile() and popuntil()
Pops all the characters starting at the current position as long as each character passes the given predicate function test. If maxchars a numeric value instead of None then then no more than that number of characters will be popped regardless of the predicate test.
1,978
1,996
def popwhile(self, testfn, maxchars=None): """Pops all the characters starting at the current position as long as each character passes the given predicate function test. If maxchars a numeric value instead of None then then no more than that number of characters will be popped regardless of the predicate test. See also methods: skipwhile() and popuntil() """ s = [] i = 0 while maxchars is None or i < maxchars: c = self.popif(testfn) if not c: break s.append(c) i += 1 return ''.join(s)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1978-L1996
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
52.631579
[ 10, 11, 12, 13, 14, 15, 16, 17, 18 ]
47.368421
false
14.825334
19
4
52.631579
7
def popwhile(self, testfn, maxchars=None): s = [] i = 0 while maxchars is None or i < maxchars: c = self.popif(testfn) if not c: break s.append(c) i += 1 return ''.join(s)
18,459
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.popuntil
(self, testfn, maxchars=None)
return self.popwhile(lambda c: not testfn(c), maxchars=maxchars)
Just like popwhile() method except the predicate function should return True to stop the sequence rather than False. See also methods: skipuntil() and popwhile()
Just like popwhile() method except the predicate function should return True to stop the sequence rather than False.
1,998
2,005
def popuntil(self, testfn, maxchars=None): """Just like popwhile() method except the predicate function should return True to stop the sequence rather than False. See also methods: skipuntil() and popwhile() """ return self.popwhile(lambda c: not testfn(c), maxchars=maxchars)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L1998-L2005
25
[ 0, 1, 2, 3, 4, 5, 6 ]
87.5
[ 7 ]
12.5
false
14.825334
8
1
87.5
4
def popuntil(self, testfn, maxchars=None): return self.popwhile(lambda c: not testfn(c), maxchars=maxchars)
18,460
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
buffered_stream.__getitem__
(self, index)
Returns the character at the given index relative to the current position. If the index goes beyond the end of the input, or prior to the start when negative, then '' is returned. If the index provided is a slice object, then that range of characters is returned as a string. Note that a stride value other than 1 is not supported in the slice. To use a slice, do: s = my_stream[ 1:4 ]
Returns the character at the given index relative to the current position.
2,007
2,023
def __getitem__(self, index): """Returns the character at the given index relative to the current position. If the index goes beyond the end of the input, or prior to the start when negative, then '' is returned. If the index provided is a slice object, then that range of characters is returned as a string. Note that a stride value other than 1 is not supported in the slice. To use a slice, do: s = my_stream[ 1:4 ] """ if isinstance(index, slice): return self.peekstr(index.stop - index.start, index.start) else: return self.peek(index)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2007-L2023
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
76.470588
[ 13, 14, 16 ]
17.647059
false
14.825334
17
2
82.352941
10
def __getitem__(self, index): if isinstance(index, slice): return self.peekstr(index.stop - index.start, index.start) else: return self.peek(index)
18,461
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSONError.__init__
(self, message, *args, **kwargs)
2,074
2,093
def __init__(self, message, *args, **kwargs): self.severity = 'error' self._position = None self.outer_position = None self.context_description = None for kw, val in list(kwargs.items()): if kw == 'severity': if val not in self.severities: raise TypeError("%s given invalid severity %r" % (self.__class__.__name__, val)) self.severity = val elif kw == 'position': self.position = val elif kw == 'outer_position': self.outer_position = val elif kw == 'context_description' or kw == 'context': self.context_description = val else: raise TypeError("%s does not accept %r keyword argument" % (self.__class__.__name__, kw)) super(JSONError, self).__init__(message, *args) self.message = message
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2074-L2093
25
[ 0 ]
5
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19 ]
90
false
14.825334
20
8
10
0
def __init__(self, message, *args, **kwargs): self.severity = 'error' self._position = None self.outer_position = None self.context_description = None for kw, val in list(kwargs.items()): if kw == 'severity': if val not in self.severities: raise TypeError("%s given invalid severity %r" % (self.__class__.__name__, val)) self.severity = val elif kw == 'position': self.position = val elif kw == 'outer_position': self.outer_position = val elif kw == 'context_description' or kw == 'context': self.context_description = val else: raise TypeError("%s does not accept %r keyword argument" % (self.__class__.__name__, kw)) super(JSONError, self).__init__(message, *args) self.message = message
18,462
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSONError.position
(self)
return self._position
2,096
2,097
def position(self): return self._position
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2096-L2097
25
[ 0 ]
50
[ 1 ]
50
false
14.825334
2
1
50
0
def position(self): return self._position
18,463
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSONError.position
(self, pos)
2,100
2,104
def position(self, pos): if pos == 0: self._position = 0 # position_marker() # start of input else: self._position = pos
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2100-L2104
25
[ 0 ]
20
[ 1, 2, 4 ]
60
false
14.825334
5
2
40
0
def position(self, pos): if pos == 0: self._position = 0 # position_marker() # start of input else: self._position = pos
18,464
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSONError.__repr__
(self)
return s
2,106
2,115
def __repr__(self): s = "%s(%r" % (self.__class__.__name__, self.message) for a in self.args[1:]: s += ", %r" % (a,) if self.position: s += ", position=%r" % (self.position,) if self.outer_position: s += ", outer_position=%r" % (self.outer_position,) s += ", severity=%r)" % (self.severity,) return s
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2106-L2115
25
[ 0 ]
10
[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
90
false
14.825334
10
4
10
0
def __repr__(self): s = "%s(%r" % (self.__class__.__name__, self.message) for a in self.args[1:]: s += ", %r" % (a,) if self.position: s += ", position=%r" % (self.position,) if self.outer_position: s += ", outer_position=%r" % (self.outer_position,) s += ", severity=%r)" % (self.severity,) return s
18,465
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSONError.pretty_description
(self, show_positions=True, filename=None)
return err
2,117
2,169
def pretty_description(self, show_positions=True, filename=None): if filename: pfx = filename.rstrip().rstrip(':') + ':' else: pfx = '' # Print file position as numeric abbreviation err = pfx if self.position == 0: err += '0:0:' elif self.position: err += '%d:%d:' % (self.position.line, self.position.column) else: err += ' ' # Print severity and main error message err += " %s: %s" % (self.severity.capitalize(), self.message) if len(self.args) > 1: err += ': ' for anum, a in enumerate(self.args[1:]): if anum > 1: err += ', ' astr = repr(a) if len(astr) > 30: astr = astr[:30] + '...' err += astr # Print out exception chain e2 = self while e2: if hasattr(e2, '__cause__') and isinstance(e2.__cause__, Exception): e2 = e2.__cause__ e2desc = str(e2).strip() if not e2desc: e2desc = repr(e2).strip() err += "\n | Cause: %s" % e2desc.strip().replace('\n', '\n | ') else: e2 = None # Show file position if show_positions and self.position is not None: if self.position == 0: err += "\n | At start of input" else: err += "\n | At %s" % (self.position.describe(show_text=False),) if self.position.text_after: err += "\n | near text: %r" % (self.position.text_after,) # Show context if show_positions and self.outer_position: if self.context_description: cdesc = self.context_description.capitalize() else: cdesc = "Context" err += "\n | %s started at %s" % (cdesc, self.outer_position.describe(show_text=False),) if self.outer_position.text_after: err += "\n | with text: %r" % (self.outer_position.text_after,) return err
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2117-L2169
25
[ 0 ]
1.886792
[ 1, 2, 4, 6, 7, 8, 9, 10, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 32, 34, 36, 37, 38, 40, 41, 42, 44, 45, 46, 48, 49, 50, 51, 52 ]
79.245283
false
14.825334
53
20
20.754717
0
def pretty_description(self, show_positions=True, filename=None): if filename: pfx = filename.rstrip().rstrip(':') + ':' else: pfx = '' # Print file position as numeric abbreviation err = pfx if self.position == 0: err += '0:0:' elif self.position: err += '%d:%d:' % (self.position.line, self.position.column) else: err += ' ' # Print severity and main error message err += " %s: %s" % (self.severity.capitalize(), self.message) if len(self.args) > 1: err += ': ' for anum, a in enumerate(self.args[1:]): if anum > 1: err += ', ' astr = repr(a) if len(astr) > 30: astr = astr[:30] + '...' err += astr # Print out exception chain e2 = self while e2: if hasattr(e2, '__cause__') and isinstance(e2.__cause__, Exception): e2 = e2.__cause__ e2desc = str(e2).strip() if not e2desc: e2desc = repr(e2).strip() err += "\n | Cause: %s" % e2desc.strip().replace('\n', '\n | ') else: e2 = None # Show file position if show_positions and self.position is not None: if self.position == 0: err += "\n | At start of input" else: err += "\n | At %s" % (self.position.describe(show_text=False),) if self.position.text_after: err += "\n | near text: %r" % (self.position.text_after,) # Show context if show_positions and self.outer_position: if self.context_description: cdesc = self.context_description.capitalize() else: cdesc = "Context" err += "\n | %s started at %s" % (cdesc, self.outer_position.describe(show_text=False),) if self.outer_position.text_after: err += "\n | with text: %r" % (self.outer_position.text_after,) return err
18,466
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSONDecodeHookError.__init__
(self, hook_name, exc_info, encoded_obj, *args, **kwargs)
2,183
2,194
def __init__(self, hook_name, exc_info, encoded_obj, *args, **kwargs): self.hook_name = hook_name if not exc_info: exc_info = (None, None, None) exc_type, self.hook_exception, self.hook_traceback = exc_info self.object_type = type(encoded_obj) msg = "Hook %s raised %r while decoding type <%s>" % ( hook_name, self.hook_exception.__class__.__name__, self.object_type.__name__) if len(args) >= 1: msg += ": " + args[0] args = args[1:] super(JSONDecodeHookError, self).__init__(msg, *args, **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2183-L2194
25
[ 0 ]
8.333333
[ 1, 2, 3, 4, 5, 6, 8, 9, 10, 11 ]
83.333333
false
14.825334
12
3
16.666667
0
def __init__(self, hook_name, exc_info, encoded_obj, *args, **kwargs): self.hook_name = hook_name if not exc_info: exc_info = (None, None, None) exc_type, self.hook_exception, self.hook_traceback = exc_info self.object_type = type(encoded_obj) msg = "Hook %s raised %r while decoding type <%s>" % ( hook_name, self.hook_exception.__class__.__name__, self.object_type.__name__) if len(args) >= 1: msg += ": " + args[0] args = args[1:] super(JSONDecodeHookError, self).__init__(msg, *args, **kwargs)
18,467
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSONEncodeHookError.__init__
(self, hook_name, exc_info, encoded_obj, *args, **kwargs)
2,208
2,219
def __init__(self, hook_name, exc_info, encoded_obj, *args, **kwargs): self.hook_name = hook_name if not exc_info: exc_info = (None, None, None) exc_type, self.hook_exception, self.hook_traceback = exc_info self.object_type = type(encoded_obj) msg = "Hook %s raised %r while encoding type <%s>" % ( self.hook_name, self.hook_exception.__class__.__name__, self.object_type.__name__) if len(args) >= 1: msg += ": " + args[0] args = args[1:] super(JSONEncodeHookError, self).__init__(msg, *args, **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2208-L2219
25
[ 0 ]
8.333333
[ 1, 2, 3, 4, 5, 6, 8, 9, 10, 11 ]
83.333333
false
14.825334
12
3
16.666667
0
def __init__(self, hook_name, exc_info, encoded_obj, *args, **kwargs): self.hook_name = hook_name if not exc_info: exc_info = (None, None, None) exc_type, self.hook_exception, self.hook_traceback = exc_info self.object_type = type(encoded_obj) msg = "Hook %s raised %r while encoding type <%s>" % ( self.hook_name, self.hook_exception.__class__.__name__, self.object_type.__name__) if len(args) >= 1: msg += ": " + args[0] args = args[1:] super(JSONEncodeHookError, self).__init__(msg, *args, **kwargs)
18,468
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
encode_state.__init__
(self, jsopts=None, parent=None)
2,232
2,244
def __init__(self, jsopts=None, parent=None): import sys self.chunks = [] if not parent: self.parent = None self.nest_level = 0 self.options = jsopts self.escape_unicode_test = False # or a function f(unichar)=>True/False else: self.parent = parent self.nest_level = parent.nest_level + 1 self.escape_unicode_test = parent.escape_unicode_test self.options = parent.options
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2232-L2244
25
[ 0 ]
7.692308
[ 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12 ]
84.615385
false
14.825334
13
2
15.384615
0
def __init__(self, jsopts=None, parent=None): import sys self.chunks = [] if not parent: self.parent = None self.nest_level = 0 self.options = jsopts self.escape_unicode_test = False # or a function f(unichar)=>True/False else: self.parent = parent self.nest_level = parent.nest_level + 1 self.escape_unicode_test = parent.escape_unicode_test self.options = parent.options
18,469
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
encode_state.make_substate
(self)
return encode_state(parent=self)
2,246
2,247
def make_substate(self): return encode_state(parent=self)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2246-L2247
25
[ 0 ]
50
[ 1 ]
50
false
14.825334
2
1
50
0
def make_substate(self): return encode_state(parent=self)
18,470
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
encode_state.join_substate
(self, other_state)
2,249
2,251
def join_substate(self, other_state): self.chunks.extend(other_state.chunks) other_state.chunks = []
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2249-L2251
25
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
14.825334
3
1
33.333333
0
def join_substate(self, other_state): self.chunks.extend(other_state.chunks) other_state.chunks = []
18,471
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
encode_state.append
(self, s)
Adds a string to the end of the current JSON document
Adds a string to the end of the current JSON document
2,253
2,255
def append(self, s): """Adds a string to the end of the current JSON document""" self.chunks.append(s)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2253-L2255
25
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
14.825334
3
1
66.666667
1
def append(self, s): self.chunks.append(s)
18,472
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
encode_state.combine
(self)
return s
Returns the accumulated string and resets the state to empty
Returns the accumulated string and resets the state to empty
2,257
2,261
def combine(self): """Returns the accumulated string and resets the state to empty""" s = ''.join(self.chunks) self.chunks = [] return s
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2257-L2261
25
[ 0, 1 ]
40
[ 2, 3, 4 ]
60
false
14.825334
5
1
40
1
def combine(self): s = ''.join(self.chunks) self.chunks = [] return s
18,473
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
encode_state.__eq__
(self, other_state)
return self.nest_level == other_state.nest_level and \ self.chunks == other_state.chunks
2,263
2,265
def __eq__(self, other_state): return self.nest_level == other_state.nest_level and \ self.chunks == other_state.chunks
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2263-L2265
25
[ 0 ]
33.333333
[ 1 ]
33.333333
false
14.825334
3
2
66.666667
0
def __eq__(self, other_state): return self.nest_level == other_state.nest_level and \ self.chunks == other_state.chunks
18,474
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
encode_state.__lt__
(self, other_state)
return self.chunks < other_state.chunks
2,267
2,270
def __lt__(self, other_state): if self.nest_level != other_state.nest_level: return self.nest_level < other_state.nest_level return self.chunks < other_state.chunks
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2267-L2270
25
[ 0 ]
25
[ 1, 2, 3 ]
75
false
14.825334
4
2
25
0
def __lt__(self, other_state): if self.nest_level != other_state.nest_level: return self.nest_level < other_state.nest_level return self.chunks < other_state.chunks
18,475
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_statistics.__init__
(self)
2,293
2,327
def __init__(self): # Nesting self.max_depth = 0 self.max_items_in_array = 0 self.max_items_in_object = 0 # Integer stats self.num_ints = 0 self.num_ints_8bit = 0 self.num_ints_16bit = 0 self.num_ints_32bit = 0 self.num_ints_53bit = 0 # ints which will overflow IEEE doubles self.num_ints_64bit = 0 self.num_ints_long = 0 self.num_negative_zero_ints = 0 # Floating-point stats self.num_negative_zero_floats = 0 self.num_floats = 0 self.num_floats_decimal = 0 # overflowed 'float' # String stats self.num_strings = 0 self.max_string_length = 0 self.total_string_length = 0 self.min_codepoint = None self.max_codepoint = None # Other data type stats self.num_arrays = 0 self.num_objects = 0 self.num_bools = 0 self.num_nulls = 0 self.num_undefineds = 0 self.num_nans = 0 self.num_infinities = 0 self.num_comments = 0 self.num_identifiers = 0 # JavaScript identifiers self.num_excess_whitespace = 0
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2293-L2327
25
[ 0, 1 ]
5.714286
[ 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 ]
82.857143
false
14.825334
35
1
17.142857
0
def __init__(self): # Nesting self.max_depth = 0 self.max_items_in_array = 0 self.max_items_in_object = 0 # Integer stats self.num_ints = 0 self.num_ints_8bit = 0 self.num_ints_16bit = 0 self.num_ints_32bit = 0 self.num_ints_53bit = 0 # ints which will overflow IEEE doubles self.num_ints_64bit = 0 self.num_ints_long = 0 self.num_negative_zero_ints = 0 # Floating-point stats self.num_negative_zero_floats = 0 self.num_floats = 0 self.num_floats_decimal = 0 # overflowed 'float' # String stats self.num_strings = 0 self.max_string_length = 0 self.total_string_length = 0 self.min_codepoint = None self.max_codepoint = None # Other data type stats self.num_arrays = 0 self.num_objects = 0 self.num_bools = 0 self.num_nulls = 0 self.num_undefineds = 0 self.num_nans = 0 self.num_infinities = 0 self.num_comments = 0 self.num_identifiers = 0 # JavaScript identifiers self.num_excess_whitespace = 0
18,476
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_statistics.num_infinites
(self)
return self.num_infinities
Misspelled 'num_infinities' for backwards compatibility
Misspelled 'num_infinities' for backwards compatibility
2,330
2,332
def num_infinites(self): """Misspelled 'num_infinities' for backwards compatibility""" return self.num_infinities
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2330-L2332
25
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
14.825334
3
1
66.666667
1
def num_infinites(self): return self.num_infinities
18,477
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_statistics.pretty_description
(self, prefix='')
2,334
2,404
def pretty_description(self, prefix=''): import unicodedata lines = [ "Number of integers:", " 8-bit: %5d (%d to %d)" % (self.num_ints_8bit, self.int8_min, self.int8_max), " 16-bit: %5d (%d to %d)" % (self.num_ints_16bit, self.int16_min, self.int16_max), " 32-bit: %5d (%d to %d)" % (self.num_ints_32bit, self.int32_min, self.int32_max), " > 53-bit: %5d (%d to %d - overflows JavaScript)" % ( self.num_ints_53bit, self.double_int_min, self.double_int_max), " 64-bit: %5d (%d to %d)" % (self.num_ints_64bit, self.int64_min, self.int64_max), " > 64 bit: %5d (not portable, may require a \"Big Num\" package)" % self.num_ints_long, " total ints: %5d" % self.num_ints, " Num -0: %5d (negative-zero integers are not portable)" % self.num_negative_zero_ints, "Number of floats:", " doubles: %5d" % self.num_floats, " > doubles: %5d (will overflow IEEE doubles)" % self.num_floats_decimal, " total flts: %5d" % (self.num_floats + self.num_floats_decimal), " Num -0.0: %5d (negative-zero floats are usually portable)" % self.num_negative_zero_floats, "Number of:", " nulls: %5d" % self.num_nulls, " booleans: %5d" % self.num_bools, " arrays: %5d" % self.num_arrays, " objects: %5d" % self.num_objects, "Strings:", " number: %5d strings" % self.num_strings, " max length: %5d characters" % self.max_string_length, " total chars: %5d across all strings" % self.total_string_length, ] if self.min_codepoint is not None: cp = 'U+%04X' % self.min_codepoint try: charname = unicodedata.name(chr(self.min_codepoint)) except ValueError: charname = '? UNKNOWN CHARACTER' lines.append(" min codepoint: %6s (%s)" % (cp, charname)) else: lines.append(" min codepoint: %6s" % ('n/a',)) if self.max_codepoint is not None: cp = 'U+%04X' % self.max_codepoint try: charname = unicodedata.name(chr(self.max_codepoint)) except ValueError: charname = '? UNKNOWN CHARACTER' lines.append(" max codepoint: %6s (%s)" % (cp, charname)) else: lines.append(" max codepoint: %6s" % ('n/a',)) lines.extend([ "Other JavaScript items:", " NaN: %5d" % self.num_nans, " Infinite: %5d" % self.num_infinities, " undefined: %5d" % self.num_undefineds, " Comments: %5d" % self.num_comments, " Identifiers: %5d" % self.num_identifiers, "Max items in any array: %5d" % self.max_items_in_array, "Max keys in any object: %5d" % self.max_items_in_object, "Max nesting depth: %5d" % self.max_depth, ]) if self.total_chars == 0: lines.append("Unnecessary whitespace: 0 of 0 characters") else: lines.append( "Unnecessary whitespace: %5d of %d characters (%.2f%%)" \ % (self.num_excess_whitespace, self.total_chars, self.num_excess_whitespace * 100.0 / self.total_chars)) if prefix: return '\n'.join([prefix + s for s in lines]) + '\n' else: return '\n'.join(lines) + '\n'
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2334-L2404
25
[ 0 ]
1.408451
[ 1, 2, 29, 30, 31, 32, 33, 34, 35, 37, 39, 40, 41, 42, 43, 44, 45, 47, 49, 60, 61, 63, 67, 68, 70 ]
35.211268
false
14.825334
71
8
64.788732
0
def pretty_description(self, prefix=''): import unicodedata lines = [ "Number of integers:", " 8-bit: %5d (%d to %d)" % (self.num_ints_8bit, self.int8_min, self.int8_max), " 16-bit: %5d (%d to %d)" % (self.num_ints_16bit, self.int16_min, self.int16_max), " 32-bit: %5d (%d to %d)" % (self.num_ints_32bit, self.int32_min, self.int32_max), " > 53-bit: %5d (%d to %d - overflows JavaScript)" % ( self.num_ints_53bit, self.double_int_min, self.double_int_max), " 64-bit: %5d (%d to %d)" % (self.num_ints_64bit, self.int64_min, self.int64_max), " > 64 bit: %5d (not portable, may require a \"Big Num\" package)" % self.num_ints_long, " total ints: %5d" % self.num_ints, " Num -0: %5d (negative-zero integers are not portable)" % self.num_negative_zero_ints, "Number of floats:", " doubles: %5d" % self.num_floats, " > doubles: %5d (will overflow IEEE doubles)" % self.num_floats_decimal, " total flts: %5d" % (self.num_floats + self.num_floats_decimal), " Num -0.0: %5d (negative-zero floats are usually portable)" % self.num_negative_zero_floats, "Number of:", " nulls: %5d" % self.num_nulls, " booleans: %5d" % self.num_bools, " arrays: %5d" % self.num_arrays, " objects: %5d" % self.num_objects, "Strings:", " number: %5d strings" % self.num_strings, " max length: %5d characters" % self.max_string_length, " total chars: %5d across all strings" % self.total_string_length, ] if self.min_codepoint is not None: cp = 'U+%04X' % self.min_codepoint try: charname = unicodedata.name(chr(self.min_codepoint)) except ValueError: charname = '? UNKNOWN CHARACTER' lines.append(" min codepoint: %6s (%s)" % (cp, charname)) else: lines.append(" min codepoint: %6s" % ('n/a',)) if self.max_codepoint is not None: cp = 'U+%04X' % self.max_codepoint try: charname = unicodedata.name(chr(self.max_codepoint)) except ValueError: charname = '? UNKNOWN CHARACTER' lines.append(" max codepoint: %6s (%s)" % (cp, charname)) else: lines.append(" max codepoint: %6s" % ('n/a',)) lines.extend([ "Other JavaScript items:", " NaN: %5d" % self.num_nans, " Infinite: %5d" % self.num_infinities, " undefined: %5d" % self.num_undefineds, " Comments: %5d" % self.num_comments, " Identifiers: %5d" % self.num_identifiers, "Max items in any array: %5d" % self.max_items_in_array, "Max keys in any object: %5d" % self.max_items_in_object, "Max nesting depth: %5d" % self.max_depth, ]) if self.total_chars == 0: lines.append("Unnecessary whitespace: 0 of 0 characters") else: lines.append( "Unnecessary whitespace: %5d of %d characters (%.2f%%)" \ % (self.num_excess_whitespace, self.total_chars, self.num_excess_whitespace * 100.0 / self.total_chars)) if prefix: return '\n'.join([prefix + s for s in lines]) + '\n' else: return '\n'.join(lines) + '\n'
18,478
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.__init__
(self, options=None)
2,417
2,419
def __init__(self, options=None): self.reset() self.options = options
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2417-L2419
25
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
14.825334
3
1
33.333333
0
def __init__(self, options=None): self.reset() self.options = options
18,479
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.reset
(self)
Clears all errors, statistics, and input text.
Clears all errors, statistics, and input text.
2,421
2,430
def reset(self): """Clears all errors, statistics, and input text.""" self.buf = None self.errors = [] self.obj = None self.cur_depth = 0 # how deep in nested structures are we? self.stats = decode_statistics() self._have_warned_nonbmp = False self._have_warned_long_string = False self._have_warned_max_depth = False
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2421-L2430
25
[ 0, 1 ]
20
[ 2, 3, 4, 5, 6, 7, 8, 9 ]
80
false
14.825334
10
1
20
1
def reset(self): self.buf = None self.errors = [] self.obj = None self.cur_depth = 0 # how deep in nested structures are we? self.stats = decode_statistics() self._have_warned_nonbmp = False self._have_warned_long_string = False self._have_warned_max_depth = False
18,480
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.should_stop
(self)
return False
2,433
2,436
def should_stop(self): if self.has_fatal: return True return False
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2433-L2436
25
[ 0 ]
25
[ 1, 2, 3 ]
75
false
14.825334
4
2
25
0
def should_stop(self): if self.has_fatal: return True return False
18,481
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.has_errors
(self)
return len([err for err in self.errors if err.severity in ('fatal', 'error')]) > 0
Have any errors been seen already?
Have any errors been seen already?
2,439
2,441
def has_errors(self): """Have any errors been seen already?""" return len([err for err in self.errors if err.severity in ('fatal', 'error')]) > 0
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2439-L2441
25
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
14.825334
3
2
66.666667
1
def has_errors(self): return len([err for err in self.errors if err.severity in ('fatal', 'error')]) > 0
18,482
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.has_fatal
(self)
return len([err for err in self.errors if err.severity in ('fatal',)]) > 0
Have any errors been seen already?
Have any errors been seen already?
2,444
2,446
def has_fatal(self): """Have any errors been seen already?""" return len([err for err in self.errors if err.severity in ('fatal',)]) > 0
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2444-L2446
25
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
14.825334
3
2
66.666667
1
def has_fatal(self): return len([err for err in self.errors if err.severity in ('fatal',)]) > 0
18,483
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.set_input
(self, txt, encoding=None)
Initialize the state by setting the input document text.
Initialize the state by setting the input document text.
2,448
2,470
def set_input(self, txt, encoding=None): """Initialize the state by setting the input document text.""" import sys self.reset() try: self.buf = buffered_stream(txt, encoding=encoding) except JSONError as err: err.position = 0 # set position to start of file err.severity = 'fatal' self.push_exception(err) except Exception as err: # Re-raise as JSONDecodeError e2 = sys.exc_info() newerr = JSONDecodeError("Error while reading input", position=0, severity='fatal') self.push_exception(err) self.buf = None else: if self.buf.bom: self.push_cond(self.options.bom, "JSON document was prefixed by a BOM (Byte Order Mark)", self.buf.bom) if not self.buf: self.push_fatal("Aborting, can not read JSON document.", position=0)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2448-L2470
25
[ 0, 1 ]
8.695652
[ 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 17, 18, 21, 22 ]
73.913043
false
14.825334
23
5
26.086957
1
def set_input(self, txt, encoding=None): import sys self.reset() try: self.buf = buffered_stream(txt, encoding=encoding) except JSONError as err: err.position = 0 # set position to start of file err.severity = 'fatal' self.push_exception(err) except Exception as err: # Re-raise as JSONDecodeError e2 = sys.exc_info() newerr = JSONDecodeError("Error while reading input", position=0, severity='fatal') self.push_exception(err) self.buf = None else: if self.buf.bom: self.push_cond(self.options.bom, "JSON document was prefixed by a BOM (Byte Order Mark)", self.buf.bom) if not self.buf: self.push_fatal("Aborting, can not read JSON document.", position=0)
18,484
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.push_exception
(self, exc)
Add an already-built exception to the error list.
Add an already-built exception to the error list.
2,472
2,474
def push_exception(self, exc): """Add an already-built exception to the error list.""" self.errors.append(exc)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2472-L2474
25
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
14.825334
3
1
66.666667
1
def push_exception(self, exc): self.errors.append(exc)
18,485
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.push_fatal
(self, message, *args, **kwargs)
Create a fatal error.
Create a fatal error.
2,476
2,479
def push_fatal(self, message, *args, **kwargs): """Create a fatal error.""" kwargs['severity'] = 'fatal' self.__push_err(message, *args, **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2476-L2479
25
[ 0, 1 ]
50
[ 2, 3 ]
50
false
14.825334
4
1
50
1
def push_fatal(self, message, *args, **kwargs): kwargs['severity'] = 'fatal' self.__push_err(message, *args, **kwargs)
18,486
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.push_error
(self, message, *args, **kwargs)
Create an error.
Create an error.
2,481
2,484
def push_error(self, message, *args, **kwargs): """Create an error.""" kwargs['severity'] = 'error' self.__push_err(message, *args, **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2481-L2484
25
[ 0, 1 ]
50
[ 2, 3 ]
50
false
14.825334
4
1
50
1
def push_error(self, message, *args, **kwargs): kwargs['severity'] = 'error' self.__push_err(message, *args, **kwargs)
18,487
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.push_warning
(self, message, *args, **kwargs)
Create a warning.
Create a warning.
2,486
2,489
def push_warning(self, message, *args, **kwargs): """Create a warning.""" kwargs['severity'] = 'warning' self.__push_err(message, *args, **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2486-L2489
25
[ 0, 1 ]
50
[ 2, 3 ]
50
false
14.825334
4
1
50
1
def push_warning(self, message, *args, **kwargs): kwargs['severity'] = 'warning' self.__push_err(message, *args, **kwargs)
18,488
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.push_info
(self, message, *args, **kwargs)
Create a informational message.
Create a informational message.
2,491
2,494
def push_info(self, message, *args, **kwargs): """Create a informational message.""" kwargs['severity'] = 'info' self.__push_err(message, *args, **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2491-L2494
25
[ 0, 1 ]
50
[ 2, 3 ]
50
false
14.825334
4
1
50
1
def push_info(self, message, *args, **kwargs): kwargs['severity'] = 'info' self.__push_err(message, *args, **kwargs)
18,489
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.push_cond
(self, behavior_value, message, *args, **kwargs)
Creates an conditional error or warning message. The behavior value (from json_options) controls whether a message will be pushed and whether it is an error or warning message.
Creates an conditional error or warning message.
2,496
2,510
def push_cond(self, behavior_value, message, *args, **kwargs): """Creates an conditional error or warning message. The behavior value (from json_options) controls whether a message will be pushed and whether it is an error or warning message. """ if behavior_value == ALLOW: return elif behavior_value == WARN: kwargs['severity'] = 'warning' else: kwargs['severity'] = 'error' self.__push_err(message, *args, **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2496-L2510
25
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
53.333333
[ 8, 9, 10, 11, 13, 14 ]
40
false
14.825334
15
3
60
5
def push_cond(self, behavior_value, message, *args, **kwargs): if behavior_value == ALLOW: return elif behavior_value == WARN: kwargs['severity'] = 'warning' else: kwargs['severity'] = 'error' self.__push_err(message, *args, **kwargs)
18,490
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.__push_err
(self, message, *args, **kwargs)
Stores an error in the error list.
Stores an error in the error list.
2,512
2,533
def __push_err(self, message, *args, **kwargs): """Stores an error in the error list.""" position = None outer_position = None severity = 'error' context_description = None for kw, val in list(kwargs.items()): if kw == 'position': position = val elif kw == 'outer_position': outer_position = val elif kw == 'severity': severity = val elif kw == 'context_description' or kw == 'context': context_description = val else: raise TypeError('Unknown keyword argument', kw) if position is None and self.buf: position = self.buf.position # Current position err = JSONDecodeError(message, position=position, outer_position=outer_position, context_description=context_description, severity=severity, *args) self.push_exception(err)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2512-L2533
25
[ 0, 1 ]
9.090909
[ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 21 ]
81.818182
false
14.825334
22
9
18.181818
1
def __push_err(self, message, *args, **kwargs): position = None outer_position = None severity = 'error' context_description = None for kw, val in list(kwargs.items()): if kw == 'position': position = val elif kw == 'outer_position': outer_position = val elif kw == 'severity': severity = val elif kw == 'context_description' or kw == 'context': context_description = val else: raise TypeError('Unknown keyword argument', kw) if position is None and self.buf: position = self.buf.position # Current position err = JSONDecodeError(message, position=position, outer_position=outer_position, context_description=context_description, severity=severity, *args) self.push_exception(err)
18,491
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.update_depth_stats
(self, **kwargs)
2,535
2,542
def update_depth_stats(self, **kwargs): st = self.stats st.max_depth = max(st.max_depth, self.cur_depth) if not self._have_warned_max_depth and self.cur_depth > self.options.warn_max_depth: self._have_warned_max_depth = True self.push_cond(self.options.non_portable, "Arrays or objects nested deeper than %d levels may not be portable" \ % self.options.warn_max_depth)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2535-L2542
25
[ 0 ]
12.5
[ 1, 2, 3, 4, 5 ]
62.5
false
14.825334
8
3
37.5
0
def update_depth_stats(self, **kwargs): st = self.stats st.max_depth = max(st.max_depth, self.cur_depth) if not self._have_warned_max_depth and self.cur_depth > self.options.warn_max_depth: self._have_warned_max_depth = True self.push_cond(self.options.non_portable, "Arrays or objects nested deeper than %d levels may not be portable" \ % self.options.warn_max_depth)
18,492
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.update_string_stats
(self, s, **kwargs)
2,544
2,568
def update_string_stats(self, s, **kwargs): st = self.stats st.num_strings += 1 st.max_string_length = max(st.max_string_length, len(s)) st.total_string_length += len(s) if self.options.warn_string_length and len( s) > self.options.warn_string_length and not self._have_warned_long_string: self._have_warned_long_string = True self.push_cond(self.options.non_portable, "Strings longer than %d may not be portable" % self.options.warn_string_length, **kwargs) if len(s) > 0: mincp = ord(min(s)) maxcp = ord(max(s)) if st.min_codepoint is None: st.min_codepoint = mincp st.max_codepoint = maxcp else: st.min_codepoint = min(st.min_codepoint, mincp) st.max_codepoint = max(st.max_codepoint, maxcp) if maxcp > 0xffff and not self._have_warned_nonbmp: self._have_warned_nonbmp = True self.push_cond(self.options.non_portable, "Strings containing non-BMP characters (U+%04X) may not be portable" % maxcp, **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2544-L2568
25
[ 0 ]
4
[ 1, 2, 3, 4, 5, 7, 8, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22 ]
72
false
14.825334
25
8
28
0
def update_string_stats(self, s, **kwargs): st = self.stats st.num_strings += 1 st.max_string_length = max(st.max_string_length, len(s)) st.total_string_length += len(s) if self.options.warn_string_length and len( s) > self.options.warn_string_length and not self._have_warned_long_string: self._have_warned_long_string = True self.push_cond(self.options.non_portable, "Strings longer than %d may not be portable" % self.options.warn_string_length, **kwargs) if len(s) > 0: mincp = ord(min(s)) maxcp = ord(max(s)) if st.min_codepoint is None: st.min_codepoint = mincp st.max_codepoint = maxcp else: st.min_codepoint = min(st.min_codepoint, mincp) st.max_codepoint = max(st.max_codepoint, maxcp) if maxcp > 0xffff and not self._have_warned_nonbmp: self._have_warned_nonbmp = True self.push_cond(self.options.non_portable, "Strings containing non-BMP characters (U+%04X) may not be portable" % maxcp, **kwargs)
18,493
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.update_negzero_int_stats
(self, **kwargs)
2,570
2,576
def update_negzero_int_stats(self, **kwargs): st = self.stats st.num_negative_zero_ints += 1 if st.num_negative_zero_ints == 1: # Only warn once self.push_cond(self.options.non_portable, "Negative zero (-0) integers are usually not portable", **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2570-L2576
25
[ 0 ]
14.285714
[ 1, 2, 3, 4 ]
57.142857
false
14.825334
7
2
42.857143
0
def update_negzero_int_stats(self, **kwargs): st = self.stats st.num_negative_zero_ints += 1 if st.num_negative_zero_ints == 1: # Only warn once self.push_cond(self.options.non_portable, "Negative zero (-0) integers are usually not portable", **kwargs)
18,494
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.update_negzero_float_stats
(self, **kwargs)
2,578
2,584
def update_negzero_float_stats(self, **kwargs): st = self.stats st.num_negative_zero_floats += 1 if st.num_negative_zero_floats == 1: # Only warn once self.push_cond(self.options.non_portable, "Negative zero (-0.0) numbers may not be portable", **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2578-L2584
25
[ 0 ]
14.285714
[ 1, 2, 3, 4 ]
57.142857
false
14.825334
7
2
42.857143
0
def update_negzero_float_stats(self, **kwargs): st = self.stats st.num_negative_zero_floats += 1 if st.num_negative_zero_floats == 1: # Only warn once self.push_cond(self.options.non_portable, "Negative zero (-0.0) numbers may not be portable", **kwargs)
18,495
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.update_float_stats
(self, float_value, **kwargs)
2,586
2,604
def update_float_stats(self, float_value, **kwargs): st = self.stats if 'sign' in kwargs: del kwargs['sign'] if helpers.is_negzero(float_value): self.update_negzero_float_stats(**kwargs) if helpers.is_infinite(float_value): st.num_infinities += 1 if isinstance(float_value, decimal.Decimal): st.num_floats_decimal += 1 if st.num_floats_decimal == 1: # Only warn once self.push_cond(self.options.non_portable, "Floats larger or more precise than an IEEE \"double\" may not be portable", **kwargs) elif isinstance(float_value, float): st.num_floats += 1
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2586-L2604
25
[ 0 ]
5.263158
[ 1, 2, 3, 5, 6, 8, 9, 11, 12, 13, 14, 17, 18 ]
68.421053
false
14.825334
19
7
31.578947
0
def update_float_stats(self, float_value, **kwargs): st = self.stats if 'sign' in kwargs: del kwargs['sign'] if helpers.is_negzero(float_value): self.update_negzero_float_stats(**kwargs) if helpers.is_infinite(float_value): st.num_infinities += 1 if isinstance(float_value, decimal.Decimal): st.num_floats_decimal += 1 if st.num_floats_decimal == 1: # Only warn once self.push_cond(self.options.non_portable, "Floats larger or more precise than an IEEE \"double\" may not be portable", **kwargs) elif isinstance(float_value, float): st.num_floats += 1
18,496
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
decode_state.update_integer_stats
(self, int_value, **kwargs)
2,606
2,635
def update_integer_stats(self, int_value, **kwargs): sign = kwargs.get('sign', 1) if 'sign' in kwargs: del kwargs['sign'] if int_value == 0 and sign < 0: self.update_negzero_int_stats(**kwargs) if sign < 0: int_value = - int_value st = self.stats st.num_ints += 1 if st.int8_min <= int_value <= st.int8_max: st.num_ints_8bit += 1 elif st.int16_min <= int_value <= st.int16_max: st.num_ints_16bit += 1 elif st.int32_min <= int_value <= st.int32_max: st.num_ints_32bit += 1 elif st.int64_min <= int_value <= st.int64_max: st.num_ints_64bit += 1 else: st.num_ints_long += 1 if int_value < st.double_int_min or st.double_int_max < int_value: st.num_ints_53bit += 1 if st.num_ints_53bit == 1: # Only warn once self.push_cond(self.options.non_portable, "Integers larger than 53-bits are not portable", **kwargs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2606-L2635
25
[ 0 ]
3.333333
[ 1, 2, 3, 5, 6, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 25, 26, 27 ]
73.333333
false
14.825334
30
12
26.666667
0
def update_integer_stats(self, int_value, **kwargs): sign = kwargs.get('sign', 1) if 'sign' in kwargs: del kwargs['sign'] if int_value == 0 and sign < 0: self.update_negzero_int_stats(**kwargs) if sign < 0: int_value = - int_value st = self.stats st.num_ints += 1 if st.int8_min <= int_value <= st.int8_max: st.num_ints_8bit += 1 elif st.int16_min <= int_value <= st.int16_max: st.num_ints_16bit += 1 elif st.int32_min <= int_value <= st.int32_max: st.num_ints_32bit += 1 elif st.int64_min <= int_value <= st.int64_max: st.num_ints_64bit += 1 else: st.num_ints_long += 1 if int_value < st.double_int_min or st.double_int_max < int_value: st.num_ints_53bit += 1 if st.num_ints_53bit == 1: # Only warn once self.push_cond(self.options.non_portable, "Integers larger than 53-bits are not portable", **kwargs)
18,497
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
_behaviors_metaclass.__new__
(cls, clsname, bases, attrs)
return super(_behaviors_metaclass, cls).__new__(cls, clsname, bases, attrs)
2,689
2,799
def __new__(cls, clsname, bases, attrs): values = attrs.get('_behavior_values') attrs['values'] = property(lambda self: set(self._behavior_values), doc='Set of possible behavior values') behaviors = attrs.get('_behaviors') def get_behavior(self, name): """Returns the value for a given behavior""" try: return getattr(self, '_behavior_' + name) except AttributeError: raise ValueError('Unknown behavior', name) attrs['get_behavior'] = get_behavior def set_behavior(self, name, value): """Changes the value for a given behavior""" if value not in self._behavior_values: raise ValueError('Unknown value for behavior', value) varname = '_behavior_' + name if hasattr(self, varname): setattr(self, varname, value) else: raise ValueError('Unknown behavior', name) attrs['set_behavior'] = set_behavior def describe_behavior(self, name): """Returns documentation about a given behavior.""" for n, doc in self._behaviors: if n == name: return doc else: raise AttributeError('No such behavior', name) attrs['describe_behavior'] = describe_behavior for name, doc in behaviors: attrs['_behavior_' + name] = True for v in values: vs = v + '_' + name def getx(self, name=name, forval=v): return self.get_behavior(name) == forval attrs['is_' + v + '_' + name] = property(getx, doc=v.capitalize() + ' ' + doc) # method value_name() fnset = lambda self, _name=name, _value=v: self.set_behavior(_name, _value) fnset.__name__ = v + '_' + name fnset.__doc__ = 'Set behavior ' + name + ' to ' + v + "." attrs[fnset.__name__] = fnset def get_value_for_behavior(self, name=name): return self.get_behavior(name) def set_value_for_behavior(self, value, name=name): self.set_behavior(name, value) attrs[name] = property(get_value_for_behavior, set_value_for_behavior, doc=doc) @property def all_behaviors(self): """Returns the names of all known behaviors.""" return set([t[0] for t in self._behaviors]) attrs['all_behaviors'] = all_behaviors def set_all(self, value): """Changes all behaviors to have the given value.""" if value not in self._behavior_values: raise ValueError('Unknown behavior', value) for name in self.all_behaviors: setattr(self, '_behavior_' + name, value) attrs['set_all'] = set_all def is_all(self, value): """Determines if all the behaviors have the given value.""" if value not in self._behavior_values: raise ValueError('Unknown behavior', value) for name in self.all_behaviors: if getattr(self, '_behavior_' + name) != value: return False return True attrs['is_all'] = is_all for v in values: # property value_behaviors def getbehaviorsfor(self, value=v): return set([name for name in self.all_behaviors if getattr(self, name) == value]) attrs[v + '_behaviors'] = property(getbehaviorsfor, doc='Return the set of behaviors with the value ' + v + '.') # method set_all_value() setfn = lambda self, _value=v: set_all(self, _value) setfn.__name__ = 'set_all_' + v setfn.__doc__ = 'Set all behaviors to value ' + v + "." attrs[setfn.__name__] = setfn # property is_all_value attrs['is_all_' + v] = property(lambda self, v=v: is_all(self, v), doc='Determines if all the behaviors have the value ' + v + '.') def behaviors_eq(self, other): """Determines if two options objects are equivalent.""" if self.all_behaviors != other.all_behaviors: return False return self.allowed_behaviors == other.allowed_behaviors attrs['__eq__'] = behaviors_eq return super(_behaviors_metaclass, cls).__new__(cls, clsname, bases, attrs)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2689-L2799
25
[ 0, 1, 2, 3, 4, 5, 6, 11, 12, 13, 14, 15, 23, 24, 25, 26, 27, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 53, 54, 56, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 72, 73, 74, 75, 76, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 107, 108, 109, 110 ]
69.369369
[ 7, 8, 9, 10, 16, 17, 18, 19, 20, 22, 28, 29, 30, 32, 42, 52, 55, 62, 68, 69, 70, 71, 77, 78, 79, 80, 81, 82, 89, 104, 105, 106 ]
28.828829
false
14.825334
111
28
71.171171
0
def __new__(cls, clsname, bases, attrs): values = attrs.get('_behavior_values') attrs['values'] = property(lambda self: set(self._behavior_values), doc='Set of possible behavior values') behaviors = attrs.get('_behaviors') def get_behavior(self, name): try: return getattr(self, '_behavior_' + name) except AttributeError: raise ValueError('Unknown behavior', name) attrs['get_behavior'] = get_behavior def set_behavior(self, name, value): if value not in self._behavior_values: raise ValueError('Unknown value for behavior', value) varname = '_behavior_' + name if hasattr(self, varname): setattr(self, varname, value) else: raise ValueError('Unknown behavior', name) attrs['set_behavior'] = set_behavior def describe_behavior(self, name): for n, doc in self._behaviors: if n == name: return doc else: raise AttributeError('No such behavior', name) attrs['describe_behavior'] = describe_behavior for name, doc in behaviors: attrs['_behavior_' + name] = True for v in values: vs = v + '_' + name def getx(self, name=name, forval=v): return self.get_behavior(name) == forval attrs['is_' + v + '_' + name] = property(getx, doc=v.capitalize() + ' ' + doc) # method value_name() fnset = lambda self, _name=name, _value=v: self.set_behavior(_name, _value) fnset.__name__ = v + '_' + name fnset.__doc__ = 'Set behavior ' + name + ' to ' + v + "." attrs[fnset.__name__] = fnset def get_value_for_behavior(self, name=name): return self.get_behavior(name) def set_value_for_behavior(self, value, name=name): self.set_behavior(name, value) attrs[name] = property(get_value_for_behavior, set_value_for_behavior, doc=doc) @property def all_behaviors(self): return set([t[0] for t in self._behaviors]) attrs['all_behaviors'] = all_behaviors def set_all(self, value): if value not in self._behavior_values: raise ValueError('Unknown behavior', value) for name in self.all_behaviors: setattr(self, '_behavior_' + name, value) attrs['set_all'] = set_all def is_all(self, value): if value not in self._behavior_values: raise ValueError('Unknown behavior', value) for name in self.all_behaviors: if getattr(self, '_behavior_' + name) != value: return False return True attrs['is_all'] = is_all for v in values: # property value_behaviors def getbehaviorsfor(self, value=v): return set([name for name in self.all_behaviors if getattr(self, name) == value]) attrs[v + '_behaviors'] = property(getbehaviorsfor, doc='Return the set of behaviors with the value ' + v + '.') # method set_all_value() setfn = lambda self, _value=v: set_all(self, _value) setfn.__name__ = 'set_all_' + v setfn.__doc__ = 'Set all behaviors to value ' + v + "." attrs[setfn.__name__] = setfn # property is_all_value attrs['is_all_' + v] = property(lambda self, v=v: is_all(self, v), doc='Determines if all the behaviors have the value ' + v + '.') def behaviors_eq(self, other): if self.all_behaviors != other.all_behaviors: return False return self.allowed_behaviors == other.allowed_behaviors attrs['__eq__'] = behaviors_eq return super(_behaviors_metaclass, cls).__new__(cls, clsname, bases, attrs)
18,498
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.reset_to_defaults
(self)
2,923
2,981
def reset_to_defaults(self): # Plain attrs (other than above behaviors) are simply copied # by value, either during initialization (via keyword # arguments) or via the copy() method. self._plain_attrs = ['leading_zero_radix', 'encode_namedtuple_as_object', 'encode_enum_as', 'encode_compactly', 'escape_unicode', 'always_escape_chars', 'warn_string_length', 'warn_max_depth', 'int_as_float', 'decimal_context', 'float_type', 'keep_format', 'date_format', 'datetime_format', 'time_format', 'timedelta_format', 'sort_keys', 'indent_amount', 'indent_tab_width', 'indent_limit', 'max_items_per_line', 'py2str_encoding'] self.strictness = STRICTNESS_WARN self._leading_zero_radix = 8 # via property: leading_zero_radix self._sort_keys = SORT_SMART # via property: sort_keys self.int_as_float = False self.float_type = NUMBER_AUTO self.decimal_context = (decimal.DefaultContext if decimal else None) self.keep_format = False # keep track of when numbers are hex, octal, etc. self.encode_namedtuple_as_object = True self._encode_enum_as = 'name' # via property self.encode_compactly = True self.escape_unicode = False self.always_escape_chars = None # None, or a set of Unicode characters to always escape self.warn_string_length = 0xfffd # with 16-bit length prefix self.warn_max_depth = 64 self.date_format = 'iso' # or strftime format self.datetime_format = 'iso' # or strftime format self.time_format = 'iso' # or strftime format self.timedelta_format = 'iso' # or 'hms' self.sort_keys = SORT_ALPHA self.indent_amount = 2 self.indent_tab_width = 0 # 0, or number of equivalent spaces self.indent_limit = None self.max_items_per_line = 1 # When encoding how many items per array/object # before breaking into multiple lines # For interpreting Python 2 'str' types: if _py_major == 2: self.py2str_encoding = 'ascii' else: self.py2str_encoding = None
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2923-L2981
25
[ 0, 1, 2, 3 ]
6.779661
[ 4, 25, 26, 27, 29, 30, 31, 32, 34, 35, 36, 37, 38, 40, 41, 43, 44, 45, 46, 48, 49, 50, 51, 52, 55, 56, 58 ]
45.762712
false
14.825334
59
2
54.237288
0
def reset_to_defaults(self): # Plain attrs (other than above behaviors) are simply copied # by value, either during initialization (via keyword # arguments) or via the copy() method. self._plain_attrs = ['leading_zero_radix', 'encode_namedtuple_as_object', 'encode_enum_as', 'encode_compactly', 'escape_unicode', 'always_escape_chars', 'warn_string_length', 'warn_max_depth', 'int_as_float', 'decimal_context', 'float_type', 'keep_format', 'date_format', 'datetime_format', 'time_format', 'timedelta_format', 'sort_keys', 'indent_amount', 'indent_tab_width', 'indent_limit', 'max_items_per_line', 'py2str_encoding'] self.strictness = STRICTNESS_WARN self._leading_zero_radix = 8 # via property: leading_zero_radix self._sort_keys = SORT_SMART # via property: sort_keys self.int_as_float = False self.float_type = NUMBER_AUTO self.decimal_context = (decimal.DefaultContext if decimal else None) self.keep_format = False # keep track of when numbers are hex, octal, etc. self.encode_namedtuple_as_object = True self._encode_enum_as = 'name' # via property self.encode_compactly = True self.escape_unicode = False self.always_escape_chars = None # None, or a set of Unicode characters to always escape self.warn_string_length = 0xfffd # with 16-bit length prefix self.warn_max_depth = 64 self.date_format = 'iso' # or strftime format self.datetime_format = 'iso' # or strftime format self.time_format = 'iso' # or strftime format self.timedelta_format = 'iso' # or 'hms' self.sort_keys = SORT_ALPHA self.indent_amount = 2 self.indent_tab_width = 0 # 0, or number of equivalent spaces self.indent_limit = None self.max_items_per_line = 1 # When encoding how many items per array/object # before breaking into multiple lines # For interpreting Python 2 'str' types: if _py_major == 2: self.py2str_encoding = 'ascii' else: self.py2str_encoding = None
18,499
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.__init__
(self, **kwargs)
Set JSON encoding and decoding options. If 'strict' is set to True, then only strictly-conforming JSON output will be produced. Note that this means that some types of values may not be convertable and will result in a JSONEncodeError exception. If 'compactly' is set to True, then the resulting string will have all extraneous white space removed; if False then the string will be "pretty printed" with whitespace and indentation added to make it more readable. If 'escape_unicode' is set to True, then all non-ASCII characters will be represented as a unicode escape sequence; if False then the actual real unicode character will be inserted if possible. The 'escape_unicode' can also be a function, which when called with a single argument of a unicode character will return True if the character should be escaped or False if it should not.
Set JSON encoding and decoding options.
2,983
3,085
def __init__(self, **kwargs): """Set JSON encoding and decoding options. If 'strict' is set to True, then only strictly-conforming JSON output will be produced. Note that this means that some types of values may not be convertable and will result in a JSONEncodeError exception. If 'compactly' is set to True, then the resulting string will have all extraneous white space removed; if False then the string will be "pretty printed" with whitespace and indentation added to make it more readable. If 'escape_unicode' is set to True, then all non-ASCII characters will be represented as a unicode escape sequence; if False then the actual real unicode character will be inserted if possible. The 'escape_unicode' can also be a function, which when called with a single argument of a unicode character will return True if the character should be escaped or False if it should not. """ self.reset_to_defaults() if 'strict' in kwargs: # Do this keyword first, so other keywords may override specific behaviors self.strictness = kwargs['strict'] for kw, val in list(kwargs.items()): if kw == 'compactly': # alias for 'encode_compactly' self.encode_compactly = val elif kw == 'strict': pass # Already handled elif kw == 'warnings': if val: self.suppress_warnings() elif kw == 'html_safe' or kw == 'xml_safe': if bool(val): if self.always_escape_chars is None: self.always_escape_chars = set('<>/&') else: self.always_escape_chars.update(set('<>/&')) elif kw == 'always_escape': if val: if self.always_escape_chars is None: self.always_escape_chars = set(val) else: self.always_escape_chars.update(set(val)) elif kw == 'int_as_float': self.int_as_float = bool(val) elif kw == 'keep_format': self.keep_format = bool(val) elif kw == 'float_type': if val in (NUMBER_AUTO, NUMBER_FLOAT, NUMBER_DECIMAL): self.float_type = val else: raise ValueError( "Unknown option %r for argument %r to initialize %s" % (val, kw, self.__class__.__name__)) elif kw == 'decimal' or kw == 'decimal_context': if decimal: if not val or val == 'default': self.decimal_context = decimal.DefaultContext elif val == 'basic': self.decimal_context = decimal.BasicContext elif val == 'extended': self.decimal_context = decimal.ExtendedContext elif isinstance(val, decimal.Context): self.decimal_context = val elif isinstance(val, int) or val[0].isdigit: prec = int(val) self.decimal_context = decimal.Context(prec=prec) else: raise ValueError( "Option for %r should be a decimal.Context, a number of significant digits, or one of 'default','basic', or 'extended'." % ( kw,)) elif kw in ('allow', 'warn', 'forbid', 'prevent', 'deny'): action = {'allow': ALLOW, 'warn': WARN, 'forbid': FORBID, 'prevent': FORBID, 'deny': FORBID}[kw] if isinstance(val, str): val = [b.replace('-', '_') for b in val.replace(',', ' ').split()] for behavior in val: self.set_behavior(behavior, action) elif kw.startswith('allow_') or kw.startswith('forbid_') or kw.startswith('prevent_') or kw.startswith( 'deny_') or kw.startswith('warn_'): action, behavior = kw.split('_', 1) if action == 'allow': if val: self.set_behavior(behavior, ALLOW) else: self.set_behavior(behavior, FORBID) elif action in ('forbid', 'prevent', 'deny'): if val: self.set_behavior(behavior, FORBID) else: self.set_behavior(behavior, ALLOW) elif action == 'warn': if val: self.set_behavior(behavior, WARN) else: self.set_behavior(behavior, ALLOW) elif kw in self._plain_attrs: setattr(self, kw, val) else: raise ValueError("Unknown keyword argument %r to initialize %s" % (kw, self.__class__.__name__))
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L2983-L3085
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
21.359223
[ 22, 24, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 75, 76, 77, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 98, 99, 100, 102 ]
64.07767
false
14.825334
103
44
35.92233
19
def __init__(self, **kwargs): self.reset_to_defaults() if 'strict' in kwargs: # Do this keyword first, so other keywords may override specific behaviors self.strictness = kwargs['strict'] for kw, val in list(kwargs.items()): if kw == 'compactly': # alias for 'encode_compactly' self.encode_compactly = val elif kw == 'strict': pass # Already handled elif kw == 'warnings': if val: self.suppress_warnings() elif kw == 'html_safe' or kw == 'xml_safe': if bool(val): if self.always_escape_chars is None: self.always_escape_chars = set('<>/&') else: self.always_escape_chars.update(set('<>/&')) elif kw == 'always_escape': if val: if self.always_escape_chars is None: self.always_escape_chars = set(val) else: self.always_escape_chars.update(set(val)) elif kw == 'int_as_float': self.int_as_float = bool(val) elif kw == 'keep_format': self.keep_format = bool(val) elif kw == 'float_type': if val in (NUMBER_AUTO, NUMBER_FLOAT, NUMBER_DECIMAL): self.float_type = val else: raise ValueError( "Unknown option %r for argument %r to initialize %s" % (val, kw, self.__class__.__name__)) elif kw == 'decimal' or kw == 'decimal_context': if decimal: if not val or val == 'default': self.decimal_context = decimal.DefaultContext elif val == 'basic': self.decimal_context = decimal.BasicContext elif val == 'extended': self.decimal_context = decimal.ExtendedContext elif isinstance(val, decimal.Context): self.decimal_context = val elif isinstance(val, int) or val[0].isdigit: prec = int(val) self.decimal_context = decimal.Context(prec=prec) else: raise ValueError( "Option for %r should be a decimal.Context, a number of significant digits, or one of 'default','basic', or 'extended'." % ( kw,)) elif kw in ('allow', 'warn', 'forbid', 'prevent', 'deny'): action = {'allow': ALLOW, 'warn': WARN, 'forbid': FORBID, 'prevent': FORBID, 'deny': FORBID}[kw] if isinstance(val, str): val = [b.replace('-', '_') for b in val.replace(',', ' ').split()] for behavior in val: self.set_behavior(behavior, action) elif kw.startswith('allow_') or kw.startswith('forbid_') or kw.startswith('prevent_') or kw.startswith( 'deny_') or kw.startswith('warn_'): action, behavior = kw.split('_', 1) if action == 'allow': if val: self.set_behavior(behavior, ALLOW) else: self.set_behavior(behavior, FORBID) elif action in ('forbid', 'prevent', 'deny'): if val: self.set_behavior(behavior, FORBID) else: self.set_behavior(behavior, ALLOW) elif action == 'warn': if val: self.set_behavior(behavior, WARN) else: self.set_behavior(behavior, ALLOW) elif kw in self._plain_attrs: setattr(self, kw, val) else: raise ValueError("Unknown keyword argument %r to initialize %s" % (kw, self.__class__.__name__))
18,500
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.copy
(self)
return other
3,087
3,090
def copy(self): other = self.__class__() other.copy_from(self) return other
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3087-L3090
25
[ 0 ]
25
[ 1, 2, 3 ]
75
false
14.825334
4
1
25
0
def copy(self): other = self.__class__() other.copy_from(self) return other
18,501
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.copy_from
(self, other)
3,092
3,108
def copy_from(self, other): if self is other: return # Myself! self.strictness = other.strictness # sets behaviors in bulk for name in self.all_behaviors: self.set_behavior(name, other.get_behavior(name)) for name in self._plain_attrs: val = getattr(other, name) if isinstance(val, set): val = val.copy() elif decimal and isinstance(val, decimal.Decimal): val = val.copy() setattr(self, name, val)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3092-L3108
25
[ 0 ]
5.882353
[ 1, 2, 4, 6, 7, 9, 10, 11, 12, 13, 14, 16 ]
70.588235
false
14.825334
17
7
29.411765
0
def copy_from(self, other): if self is other: return # Myself! self.strictness = other.strictness # sets behaviors in bulk for name in self.all_behaviors: self.set_behavior(name, other.get_behavior(name)) for name in self._plain_attrs: val = getattr(other, name) if isinstance(val, set): val = val.copy() elif decimal and isinstance(val, decimal.Decimal): val = val.copy() setattr(self, name, val)
18,502
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.spaces_to_next_indent_level
(self, min_spaces=1, subtract=0)
return ' ' * n
3,110
3,115
def spaces_to_next_indent_level(self, min_spaces=1, subtract=0): n = self.indent_amount - subtract if n < 0: n = 0 n = max(min_spaces, n) return ' ' * n
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3110-L3115
25
[ 0 ]
16.666667
[ 1, 2, 3, 4, 5 ]
83.333333
false
14.825334
6
2
16.666667
0
def spaces_to_next_indent_level(self, min_spaces=1, subtract=0): n = self.indent_amount - subtract if n < 0: n = 0 n = max(min_spaces, n) return ' ' * n
18,503
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.indentation_for_level
(self, level=0)
Returns a whitespace string used for indenting.
Returns a whitespace string used for indenting.
3,117
3,128
def indentation_for_level(self, level=0): """Returns a whitespace string used for indenting.""" if self.indent_limit is not None and level > self.indent_limit: n = self.indent_limit else: n = level n *= self.indent_amount if self.indent_tab_width: tw, sw = divmod(n, self.indent_tab_width) return '\t' * tw + ' ' * sw else: return ' ' * n
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3117-L3128
25
[ 0, 1 ]
16.666667
[ 2, 3, 5, 6, 7, 8, 9, 11 ]
66.666667
false
14.825334
12
4
33.333333
1
def indentation_for_level(self, level=0): if self.indent_limit is not None and level > self.indent_limit: n = self.indent_limit else: n = level n *= self.indent_amount if self.indent_tab_width: tw, sw = divmod(n, self.indent_tab_width) return '\t' * tw + ' ' * sw else: return ' ' * n
18,504
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.set_indent
(self, num_spaces, tab_width=0, limit=None)
Changes the indentation properties when outputting JSON in non-compact mode. 'num_spaces' is the number of spaces to insert for each level of indentation, which defaults to 2. 'tab_width', if not 0, is the number of spaces which is equivalent to one tab character. Tabs will be output where possible rather than runs of spaces. 'limit', if not None, is the maximum indentation level after which no further indentation will be output.
Changes the indentation properties when outputting JSON in non-compact mode.
3,130
3,149
def set_indent(self, num_spaces, tab_width=0, limit=None): """Changes the indentation properties when outputting JSON in non-compact mode. 'num_spaces' is the number of spaces to insert for each level of indentation, which defaults to 2. 'tab_width', if not 0, is the number of spaces which is equivalent to one tab character. Tabs will be output where possible rather than runs of spaces. 'limit', if not None, is the maximum indentation level after which no further indentation will be output. """ n = int(num_spaces) if n < 0: raise ValueError("indentation amount can not be negative", n) self.indent_amount = n self.indent_tab_width = tab_width self.indent_limit = limit
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3130-L3149
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
70
[ 14, 15, 16, 17, 18, 19 ]
30
false
14.825334
20
2
70
11
def set_indent(self, num_spaces, tab_width=0, limit=None): n = int(num_spaces) if n < 0: raise ValueError("indentation amount can not be negative", n) self.indent_amount = n self.indent_tab_width = tab_width self.indent_limit = limit
18,505
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.sort_keys
(self)
return self._sort_keys
The method used to sort dictionary keys when encoding JSON
The method used to sort dictionary keys when encoding JSON
3,152
3,155
def sort_keys(self): """The method used to sort dictionary keys when encoding JSON """ return self._sort_keys
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3152-L3155
25
[ 0, 1, 2 ]
75
[ 3 ]
25
false
14.825334
4
1
75
1
def sort_keys(self): return self._sort_keys
18,506
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.sort_keys
(self, method)
3,158
3,170
def sort_keys(self, method): if not method: self._sort_keys = SORT_NONE elif callable(method): self._sort_keys = method elif method in sorting_methods: self._sort_keys = method elif method in sorting_method_aliases: # alias self._sort_keys = sorting_method_aliases[method] elif method == True: self._sort_keys = SORT_ALPHA else: raise ValueError("Not a valid sorting method: %r" % method)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3158-L3170
25
[ 0 ]
7.692308
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12 ]
84.615385
false
14.825334
13
6
15.384615
0
def sort_keys(self, method): if not method: self._sort_keys = SORT_NONE elif callable(method): self._sort_keys = method elif method in sorting_methods: self._sort_keys = method elif method in sorting_method_aliases: # alias self._sort_keys = sorting_method_aliases[method] elif method == True: self._sort_keys = SORT_ALPHA else: raise ValueError("Not a valid sorting method: %r" % method)
18,507
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.encode_enum_as
(self)
return self._encode_enum_as
The strategy for encoding Python Enum values.
The strategy for encoding Python Enum values.
3,173
3,176
def encode_enum_as(self): """The strategy for encoding Python Enum values. """ return self._encode_enum_as
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3173-L3176
25
[ 0, 1, 2 ]
75
[ 3 ]
25
false
14.825334
4
1
75
1
def encode_enum_as(self): return self._encode_enum_as
18,508
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.encode_enum_as
(self, val)
3,179
3,182
def encode_enum_as(self, val): if val not in ('name', 'qname', 'value'): raise ValueError("encode_enum_as must be one of 'name','qname', or 'value'") self._encode_enum_as = val
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3179-L3182
25
[ 0 ]
25
[ 1, 2, 3 ]
75
false
14.825334
4
2
25
0
def encode_enum_as(self, val): if val not in ('name', 'qname', 'value'): raise ValueError("encode_enum_as must be one of 'name','qname', or 'value'") self._encode_enum_as = val
18,509
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.zero_float
(self)
The numeric value 0.0, either a float or a decimal.
The numeric value 0.0, either a float or a decimal.
3,185
3,190
def zero_float(self): """The numeric value 0.0, either a float or a decimal.""" if decimal and self.float_type == NUMBER_DECIMAL: return self.decimal_context.create_decimal('0.0') else: return 0.0
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3185-L3190
25
[ 0, 1 ]
33.333333
[ 2, 3, 5 ]
50
false
14.825334
6
3
50
1
def zero_float(self): if decimal and self.float_type == NUMBER_DECIMAL: return self.decimal_context.create_decimal('0.0') else: return 0.0
18,510
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.negzero_float
(self)
The numeric value -0.0, either a float or a decimal.
The numeric value -0.0, either a float or a decimal.
3,193
3,198
def negzero_float(self): """The numeric value -0.0, either a float or a decimal.""" if decimal and self.float_type == NUMBER_DECIMAL: return self.decimal_context.create_decimal('-0.0') else: return -0.0
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3193-L3198
25
[ 0, 1 ]
33.333333
[ 2, 3, 5 ]
50
false
14.825334
6
3
50
1
def negzero_float(self): if decimal and self.float_type == NUMBER_DECIMAL: return self.decimal_context.create_decimal('-0.0') else: return -0.0
18,511
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.nan
(self)
The numeric value NaN, either a float or a decimal.
The numeric value NaN, either a float or a decimal.
3,201
3,206
def nan(self): """The numeric value NaN, either a float or a decimal.""" if decimal and self.float_type == NUMBER_DECIMAL: return self.decimal_context.create_decimal('NaN') else: return nan
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3201-L3206
25
[ 0, 1 ]
33.333333
[ 2, 3, 5 ]
50
false
14.825334
6
3
50
1
def nan(self): if decimal and self.float_type == NUMBER_DECIMAL: return self.decimal_context.create_decimal('NaN') else: return nan
18,512
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.inf
(self)
The numeric value Infinity, either a float or a decimal.
The numeric value Infinity, either a float or a decimal.
3,209
3,214
def inf(self): """The numeric value Infinity, either a float or a decimal.""" if decimal and self.float_type == NUMBER_DECIMAL: return self.decimal_context.create_decimal('Infinity') else: return inf
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3209-L3214
25
[ 0, 1 ]
33.333333
[ 2, 3, 5 ]
50
false
14.825334
6
3
50
1
def inf(self): if decimal and self.float_type == NUMBER_DECIMAL: return self.decimal_context.create_decimal('Infinity') else: return inf
18,513
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.neginf
(self)
The numeric value -Infinity, either a float or a decimal.
The numeric value -Infinity, either a float or a decimal.
3,217
3,222
def neginf(self): """The numeric value -Infinity, either a float or a decimal.""" if decimal and self.float_type == NUMBER_DECIMAL: return self.decimal_context.create_decimal('-Infinity') else: return neginf
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3217-L3222
25
[ 0, 1 ]
33.333333
[ 2, 3, 5 ]
50
false
14.825334
6
3
50
1
def neginf(self): if decimal and self.float_type == NUMBER_DECIMAL: return self.decimal_context.create_decimal('-Infinity') else: return neginf
18,514
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.make_int
(self, s, sign=None, number_format=NUMBER_FORMAT_DECIMAL)
return n
Makes an integer value according to the current options. First argument should be a string representation of the number, or an integer. Returns a number value, which could be an int, float, or decimal.
Makes an integer value according to the current options.
3,224
3,291
def make_int(self, s, sign=None, number_format=NUMBER_FORMAT_DECIMAL): """Makes an integer value according to the current options. First argument should be a string representation of the number, or an integer. Returns a number value, which could be an int, float, or decimal. """ if isinstance(sign, int): if sign < 0: sign = '-' else: sign = '+' if isinstance(s, str): if s.startswith('-') or s.startswith('+'): sign = s[0] s = s[1:] if self.int_as_float: # Making a float/decimal if isinstance(s, int): if self.float_type == NUMBER_DECIMAL: n = self.decimal_context.create_decimal(s) if sign == '-': n = n.copy_negate() elif s == 0 and sign == '-': n = self.negzero_float elif -999999999999999 <= s <= 999999999999999: n = float(s) if sign == '-': n *= -1 else: n = float(s) if (n == inf or int(n) != s) and self.float_type != NUMBER_FLOAT: n = self.decimal_context.create_decimal(s) if sign == '-': n = n.copy_negate() elif sign == '-': n *= -1 else: # not already an int n = self.make_float(s, sign) n2 = self.make_float(s[:-1] + ('9' if s[-1] <= '5' else '0'), sign) if (n == inf or n == n2) and self.float_type != NUMBER_FLOAT: n = self.make_decimal(s, sign) elif isinstance(s, int): # already an integer n = s if sign == '-': if n == 0: n = self.negzero_float else: n *= -1 else: # Making an actual integer try: n = int(s) except ValueError: n = self.nan else: if sign == '-': if n == 0: n = self.negzero_float else: n *= -1 if isinstance(n, int) and self.keep_format: n = json_int(n, number_format=number_format) return n
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3224-L3291
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
13.235294
[ 9, 10, 11, 13, 14, 15, 16, 17, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 47, 48, 49, 50, 52, 55, 56, 57, 58, 60, 61, 62, 64, 65, 66, 67 ]
70.588235
false
14.825334
68
30
29.411765
6
def make_int(self, s, sign=None, number_format=NUMBER_FORMAT_DECIMAL): if isinstance(sign, int): if sign < 0: sign = '-' else: sign = '+' if isinstance(s, str): if s.startswith('-') or s.startswith('+'): sign = s[0] s = s[1:] if self.int_as_float: # Making a float/decimal if isinstance(s, int): if self.float_type == NUMBER_DECIMAL: n = self.decimal_context.create_decimal(s) if sign == '-': n = n.copy_negate() elif s == 0 and sign == '-': n = self.negzero_float elif -999999999999999 <= s <= 999999999999999: n = float(s) if sign == '-': n *= -1 else: n = float(s) if (n == inf or int(n) != s) and self.float_type != NUMBER_FLOAT: n = self.decimal_context.create_decimal(s) if sign == '-': n = n.copy_negate() elif sign == '-': n *= -1 else: # not already an int n = self.make_float(s, sign) n2 = self.make_float(s[:-1] + ('9' if s[-1] <= '5' else '0'), sign) if (n == inf or n == n2) and self.float_type != NUMBER_FLOAT: n = self.make_decimal(s, sign) elif isinstance(s, int): # already an integer n = s if sign == '-': if n == 0: n = self.negzero_float else: n *= -1 else: # Making an actual integer try: n = int(s) except ValueError: n = self.nan else: if sign == '-': if n == 0: n = self.negzero_float else: n *= -1 if isinstance(n, int) and self.keep_format: n = json_int(n, number_format=number_format) return n
18,515
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.make_decimal
(self, s, sign='+')
return f
Converts a string into a decimal or float value.
Converts a string into a decimal or float value.
3,293
3,319
def make_decimal(self, s, sign='+'): """Converts a string into a decimal or float value.""" if not decimal or self.float_type == NUMBER_FLOAT: return self.make_float(s, sign) if s.startswith('-') or s.startswith('+'): sign = s[0] s = s[1:] elif isinstance(sign, int): if sign < 0: sign = '-' else: sign = '+' try: f = self.decimal_context.create_decimal(s) except decimal.InvalidOperation: f = self.decimal_context.create_decimal('NaN') except decimal.Overflow: if sign == '-': f = self.decimal_context.create_decimal('-Infinity') else: f = self.decimal_context.create_decimal('Infinity') else: if sign == '-': f = f.copy_negate() return f
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3293-L3319
25
[ 0, 1 ]
7.407407
[ 2, 3, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 17, 18, 19, 20, 22, 24, 25, 26 ]
74.074074
false
14.825334
27
11
25.925926
1
def make_decimal(self, s, sign='+'): if not decimal or self.float_type == NUMBER_FLOAT: return self.make_float(s, sign) if s.startswith('-') or s.startswith('+'): sign = s[0] s = s[1:] elif isinstance(sign, int): if sign < 0: sign = '-' else: sign = '+' try: f = self.decimal_context.create_decimal(s) except decimal.InvalidOperation: f = self.decimal_context.create_decimal('NaN') except decimal.Overflow: if sign == '-': f = self.decimal_context.create_decimal('-Infinity') else: f = self.decimal_context.create_decimal('Infinity') else: if sign == '-': f = f.copy_negate() return f
18,516
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.make_float
(self, s, sign='+')
return f
Converts a string into a float or decimal value.
Converts a string into a float or decimal value.
3,321
3,342
def make_float(self, s, sign='+'): """Converts a string into a float or decimal value.""" if decimal and self.float_type == NUMBER_DECIMAL: return self.make_decimal(s, sign) if s.startswith('-') or s.startswith('+'): sign = s[0] s = s[1:] elif isinstance(sign, int): if sign < 0: sign = '-' else: sign = '+' try: f = float(s) except ValueError: f = nan else: if sign == '-': f *= -1 return f
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3321-L3342
25
[ 0, 1 ]
9.090909
[ 2, 3, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 17, 19, 20, 21 ]
72.727273
false
14.825334
22
9
27.272727
1
def make_float(self, s, sign='+'): if decimal and self.float_type == NUMBER_DECIMAL: return self.make_decimal(s, sign) if s.startswith('-') or s.startswith('+'): sign = s[0] s = s[1:] elif isinstance(sign, int): if sign < 0: sign = '-' else: sign = '+' try: f = float(s) except ValueError: f = nan else: if sign == '-': f *= -1 return f
18,517
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.leading_zero_radix
(self)
return self._leading_zero_radix
The radix to be used for numbers with leading zeros. 8 or 10
The radix to be used for numbers with leading zeros. 8 or 10
3,345
3,348
def leading_zero_radix(self): """The radix to be used for numbers with leading zeros. 8 or 10 """ return self._leading_zero_radix
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3345-L3348
25
[ 0, 1, 2 ]
75
[ 3 ]
25
false
14.825334
4
1
75
1
def leading_zero_radix(self): return self._leading_zero_radix
18,518
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.leading_zero_radix
(self, radix)
3,351
3,363
def leading_zero_radix(self, radix): if isinstance(radix, str): try: radix = int(radix) except ValueError: radix = radix.lower() if radix == 'octal' or radix == 'oct' or radix == '8': radix = 8 elif radix == 'decimal' or radix == 'dec': radix = 10 if radix not in (8, 10): raise ValueError("Radix must either be 8 (octal) or 10 (decimal)") self._leading_zero_radix = radix
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3351-L3363
25
[ 0 ]
7.692308
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
92.307692
false
14.825334
13
9
7.692308
0
def leading_zero_radix(self, radix): if isinstance(radix, str): try: radix = int(radix) except ValueError: radix = radix.lower() if radix == 'octal' or radix == 'oct' or radix == '8': radix = 8 elif radix == 'decimal' or radix == 'dec': radix = 10 if radix not in (8, 10): raise ValueError("Radix must either be 8 (octal) or 10 (decimal)") self._leading_zero_radix = radix
18,519
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.leading_zero_radix_as_word
(self)
return {8: 'octal', 10: 'decimal'}[self._leading_zero_radix]
3,366
3,367
def leading_zero_radix_as_word(self): return {8: 'octal', 10: 'decimal'}[self._leading_zero_radix]
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3366-L3367
25
[ 0 ]
50
[ 1 ]
50
false
14.825334
2
1
50
0
def leading_zero_radix_as_word(self): return {8: 'octal', 10: 'decimal'}[self._leading_zero_radix]
18,520
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.suppress_warnings
(self)
3,369
3,371
def suppress_warnings(self): for name in self.warn_behaviors: self.set_behavior(name, 'allow')
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3369-L3371
25
[ 0 ]
33.333333
[ 1, 2 ]
66.666667
false
14.825334
3
2
33.333333
0
def suppress_warnings(self): for name in self.warn_behaviors: self.set_behavior(name, 'allow')
18,521
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.allow_or_warn_behaviors
(self)
return self.allow_behaviors.union(self.warn_behaviors)
Returns the set of all behaviors that are not forbidden (i.e., are allowed or warned).
Returns the set of all behaviors that are not forbidden (i.e., are allowed or warned).
3,374
3,376
def allow_or_warn_behaviors(self): """Returns the set of all behaviors that are not forbidden (i.e., are allowed or warned).""" return self.allow_behaviors.union(self.warn_behaviors)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3374-L3376
25
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
14.825334
3
1
66.666667
1
def allow_or_warn_behaviors(self): return self.allow_behaviors.union(self.warn_behaviors)
18,522
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.strictness
(self)
return self._strictness
3,379
3,380
def strictness(self): return self._strictness
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3379-L3380
25
[ 0 ]
50
[ 1 ]
50
false
14.825334
2
1
50
0
def strictness(self): return self._strictness
18,523
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
json_options.strictness
(self, strict)
Changes whether the options should be re-configured for strict JSON conformance.
Changes whether the options should be re-configured for strict JSON conformance.
3,383
3,407
def strictness(self, strict): """Changes whether the options should be re-configured for strict JSON conformance.""" if strict == STRICTNESS_WARN: self._strictness = STRICTNESS_WARN self.set_all_warn() elif strict == STRICTNESS_STRICT or strict is True: self._strictness = STRICTNESS_STRICT self.keep_format = False self.set_all_forbid() self.warn_duplicate_keys() self.warn_zero_byte() self.warn_bom() self.warn_non_portable() elif strict == STRICTNESS_TOLERANT or strict is False: self._strictness = STRICTNESS_TOLERANT self.set_all_allow() self.warn_duplicate_keys() self.warn_zero_byte() self.warn_leading_zeros() self.leading_zero_radix = 8 self.warn_bom() self.allow_non_portable() else: raise ValueError("Unknown strictness options %r" % strict) self.allow_any_type_at_start()
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3383-L3407
25
[ 0, 1 ]
8
[ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24 ]
88
false
14.825334
25
6
12
1
def strictness(self, strict): if strict == STRICTNESS_WARN: self._strictness = STRICTNESS_WARN self.set_all_warn() elif strict == STRICTNESS_STRICT or strict is True: self._strictness = STRICTNESS_STRICT self.keep_format = False self.set_all_forbid() self.warn_duplicate_keys() self.warn_zero_byte() self.warn_bom() self.warn_non_portable() elif strict == STRICTNESS_TOLERANT or strict is False: self._strictness = STRICTNESS_TOLERANT self.set_all_allow() self.warn_duplicate_keys() self.warn_zero_byte() self.warn_leading_zeros() self.leading_zero_radix = 8 self.warn_bom() self.allow_non_portable() else: raise ValueError("Unknown strictness options %r" % strict) self.allow_any_type_at_start()
18,524
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.__init__
(self, **kwargs)
Creates a JSON encoder/decoder object. You may pass encoding and decoding options either by passing an argument named 'json_options' with an instance of a json_options class; or with individual keyword/values that will be used to initialize a new json_options object. You can also set hooks by using keyword arguments using the hook name; e.g., encode_dict=my_hook_func.
Creates a JSON encoder/decoder object.
3,479
3,516
def __init__(self, **kwargs): """Creates a JSON encoder/decoder object. You may pass encoding and decoding options either by passing an argument named 'json_options' with an instance of a json_options class; or with individual keyword/values that will be used to initialize a new json_options object. You can also set hooks by using keyword arguments using the hook name; e.g., encode_dict=my_hook_func. """ import sys, unicodedata, re kwargs = kwargs.copy() # Initialize hooks for hookname in self.all_hook_names: if hookname in kwargs: self.set_hook(hookname, kwargs[hookname]) del kwargs[hookname] else: self.set_hook(hookname, None) # Set options if 'json_options' in kwargs: self._options = kwargs['json_options'] else: self._options = json_options(**kwargs) # The following is a boolean map of the first 256 characters # which will quickly tell us which of those characters never # need to be escaped. self._asciiencodable = \ [32 <= c < 128 \ and chr(c) not in self._rev_escapes \ and not unicodedata.category(chr(c)) in ['Cc', 'Cf', 'Zl', 'Zp'] for c in range(0, 256)]
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3479-L3516
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
31.578947
[ 12, 14, 16, 17, 18, 19, 21, 24, 25, 27, 33 ]
28.947368
false
14.825334
38
7
71.052632
9
def __init__(self, **kwargs): import sys, unicodedata, re kwargs = kwargs.copy() # Initialize hooks for hookname in self.all_hook_names: if hookname in kwargs: self.set_hook(hookname, kwargs[hookname]) del kwargs[hookname] else: self.set_hook(hookname, None) # Set options if 'json_options' in kwargs: self._options = kwargs['json_options'] else: self._options = json_options(**kwargs) # The following is a boolean map of the first 256 characters # which will quickly tell us which of those characters never # need to be escaped. self._asciiencodable = \ [32 <= c < 128 \ and chr(c) not in self._rev_escapes \ and not unicodedata.category(chr(c)) in ['Cc', 'Cf', 'Zl', 'Zp'] for c in range(0, 256)]
18,525
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.options
(self)
return self._options
The optional behaviors used, e.g., the JSON conformance strictness. Returns an instance of json_options.
The optional behaviors used, e.g., the JSON conformance strictness. Returns an instance of json_options.
3,519
3,524
def options(self): """The optional behaviors used, e.g., the JSON conformance strictness. Returns an instance of json_options. """ return self._options
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3519-L3524
25
[ 0, 1, 2, 3, 4 ]
83.333333
[ 5 ]
16.666667
false
14.825334
6
1
83.333333
2
def options(self): return self._options
18,526
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.clear_hook
(self, hookname)
Unsets a hook callback, as previously set with set_hook().
Unsets a hook callback, as previously set with set_hook().
3,526
3,528
def clear_hook(self, hookname): """Unsets a hook callback, as previously set with set_hook().""" self.set_hook(hookname, None)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3526-L3528
25
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
14.825334
3
1
66.666667
1
def clear_hook(self, hookname): self.set_hook(hookname, None)
18,527
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.clear_all_hooks
(self)
Unsets all hook callbacks, as previously set with set_hook().
Unsets all hook callbacks, as previously set with set_hook().
3,530
3,533
def clear_all_hooks(self): """Unsets all hook callbacks, as previously set with set_hook().""" for hookname in self.all_hook_names: self.clear_hook(hookname)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3530-L3533
25
[ 0, 1 ]
50
[ 2, 3 ]
50
false
14.825334
4
2
50
1
def clear_all_hooks(self): for hookname in self.all_hook_names: self.clear_hook(hookname)
18,528
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.set_hook
(self, hookname, function)
Sets a user-defined callback function used during encoding or decoding. The 'hookname' argument must be a string containing the name of one of the available hooks, listed below. The 'function' argument must either be None, which disables the hook, or a callable function. Hooks do not stack, if you set a hook it will undo any previously set hook. Netsted values. When decoding JSON that has nested objects or arrays, the decoding hooks will be called once for every corresponding value, even if nested. Generally the decoding hooks will be called from the inner-most value outward, and then left to right. Skipping. Any hook function may raise a JSONSkipHook exception if it does not wish to handle the particular invocation. This will have the effect of skipping the hook for that particular value, as if the hook was net set. AVAILABLE HOOKS: * decode_string Called for every JSON string literal with the Python-equivalent string value as an argument. Expects to get a Python object in return. * decode_float: Called for every JSON number that looks like a float (has a "."). The string representation of the number is passed as an argument. Expects to get a Python object in return. * decode_number: Called for every JSON number. The string representation of the number is passed as an argument. Expects to get a Python object in return. NOTE: If the number looks like a float and the 'decode_float' hook is set, then this hook will not be called. * decode_array: Called for every JSON array. A Python list is passed as the argument, and expects to get a Python object back. NOTE: this hook will get called for every array, even for nested arrays. * decode_object: Called for every JSON object. A Python dictionary is passed as the argument, and expects to get a Python object back. NOTE: this hook will get called for every object, even for nested objects. * encode_value: Called for every Python object which is to be encoded into JSON. * encode_dict: Called for every Python dictionary or anything that looks like a dictionary. * encode_dict_key: Called for every dictionary key. * encode_sequence: Called for every Python sequence-like object that is not a dictionary or string. This includes lists and tuples. * encode_bytes: Called for every Python bytes or bytearray type; or for any memoryview with a byte ('B') item type. (Python 3 only) * encode_default: Called for any Python type which can not otherwise be converted into JSON, even after applying any other encoding hooks.
Sets a user-defined callback function used during encoding or decoding.
3,535
3,616
def set_hook(self, hookname, function): """Sets a user-defined callback function used during encoding or decoding. The 'hookname' argument must be a string containing the name of one of the available hooks, listed below. The 'function' argument must either be None, which disables the hook, or a callable function. Hooks do not stack, if you set a hook it will undo any previously set hook. Netsted values. When decoding JSON that has nested objects or arrays, the decoding hooks will be called once for every corresponding value, even if nested. Generally the decoding hooks will be called from the inner-most value outward, and then left to right. Skipping. Any hook function may raise a JSONSkipHook exception if it does not wish to handle the particular invocation. This will have the effect of skipping the hook for that particular value, as if the hook was net set. AVAILABLE HOOKS: * decode_string Called for every JSON string literal with the Python-equivalent string value as an argument. Expects to get a Python object in return. * decode_float: Called for every JSON number that looks like a float (has a "."). The string representation of the number is passed as an argument. Expects to get a Python object in return. * decode_number: Called for every JSON number. The string representation of the number is passed as an argument. Expects to get a Python object in return. NOTE: If the number looks like a float and the 'decode_float' hook is set, then this hook will not be called. * decode_array: Called for every JSON array. A Python list is passed as the argument, and expects to get a Python object back. NOTE: this hook will get called for every array, even for nested arrays. * decode_object: Called for every JSON object. A Python dictionary is passed as the argument, and expects to get a Python object back. NOTE: this hook will get called for every object, even for nested objects. * encode_value: Called for every Python object which is to be encoded into JSON. * encode_dict: Called for every Python dictionary or anything that looks like a dictionary. * encode_dict_key: Called for every dictionary key. * encode_sequence: Called for every Python sequence-like object that is not a dictionary or string. This includes lists and tuples. * encode_bytes: Called for every Python bytes or bytearray type; or for any memoryview with a byte ('B') item type. (Python 3 only) * encode_default: Called for any Python type which can not otherwise be converted into JSON, even after applying any other encoding hooks. """ if hookname in self.all_hook_names: att = hookname + '_hook' if function != None and not callable(function): raise ValueError("Hook %r must be None or a callable function" % hookname) setattr(self, att, function) else: raise ValueError("Unknown hook name %r" % hookname)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3535-L3616
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74 ]
91.463415
[ 75, 76, 77, 78, 79, 81 ]
7.317073
false
14.825334
82
4
92.682927
72
def set_hook(self, hookname, function): if hookname in self.all_hook_names: att = hookname + '_hook' if function != None and not callable(function): raise ValueError("Hook %r must be None or a callable function" % hookname) setattr(self, att, function) else: raise ValueError("Unknown hook name %r" % hookname)
18,529
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.has_hook
(self, hook_name)
return callable(hook)
3,618
3,622
def has_hook(self, hook_name): if not hook_name or hook_name not in self.all_hook_names: return False hook = getattr(self, hook_name + '_hook') return callable(hook)
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3618-L3622
25
[ 0 ]
20
[ 1, 2, 3, 4 ]
80
false
14.825334
5
3
20
0
def has_hook(self, hook_name): if not hook_name or hook_name not in self.all_hook_names: return False hook = getattr(self, hook_name + '_hook') return callable(hook)
18,530
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.call_hook
(self, hook_name, input_object, position=None, *args, **kwargs)
return rval
Wrapper function to invoke a user-supplied hook function. This will capture any exceptions raised by the hook and do something appropriate with it.
Wrapper function to invoke a user-supplied hook function.
3,624
3,659
def call_hook(self, hook_name, input_object, position=None, *args, **kwargs): """Wrapper function to invoke a user-supplied hook function. This will capture any exceptions raised by the hook and do something appropriate with it. """ import sys if hook_name not in self.all_hook_names: raise AttributeError("No such hook %r" % hook_name) hook = getattr(self, hook_name + '_hook') if not callable(hook): raise TypeError("Hook is not callable: %r" % (hook,)) try: rval = hook(input_object, *args, **kwargs) except JSONSkipHook: raise # Do nothing except Exception as err: exc_info = sys.exc_info() if hook_name.startswith('encode_'): ex_class = JSONEncodeHookError else: ex_class = JSONDecodeHookError if isinstance(err, JSONStopProcessing): severity = 'fatal' else: severity = 'error' newerr = ex_class(hook_name, exc_info, input_object, *args, position=position, severity=severity) # Simulate Python 3's: "raise X from Y" exception chaining newerr.__cause__ = err newerr.__traceback__ = exc_info[2] raise newerr return rval
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3624-L3659
25
[ 0, 1, 2, 3, 4, 5, 6 ]
19.444444
[ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 24, 25, 27, 29, 32, 33, 34, 35 ]
63.888889
false
14.825334
36
7
36.111111
4
def call_hook(self, hook_name, input_object, position=None, *args, **kwargs): import sys if hook_name not in self.all_hook_names: raise AttributeError("No such hook %r" % hook_name) hook = getattr(self, hook_name + '_hook') if not callable(hook): raise TypeError("Hook is not callable: %r" % (hook,)) try: rval = hook(input_object, *args, **kwargs) except JSONSkipHook: raise # Do nothing except Exception as err: exc_info = sys.exc_info() if hook_name.startswith('encode_'): ex_class = JSONEncodeHookError else: ex_class = JSONDecodeHookError if isinstance(err, JSONStopProcessing): severity = 'fatal' else: severity = 'error' newerr = ex_class(hook_name, exc_info, input_object, *args, position=position, severity=severity) # Simulate Python 3's: "raise X from Y" exception chaining newerr.__cause__ = err newerr.__traceback__ = exc_info[2] raise newerr return rval
18,531
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.isws
(self, c)
Determines if the given character is considered as white space. Note that Javscript is much more permissive on what it considers to be whitespace than does JSON. Ref. ECMAScript section 7.2
Determines if the given character is considered as white space. Note that Javscript is much more permissive on what it considers to be whitespace than does JSON. Ref. ECMAScript section 7.2
3,661
3,678
def isws(self, c): """Determines if the given character is considered as white space. Note that Javscript is much more permissive on what it considers to be whitespace than does JSON. Ref. ECMAScript section 7.2 """ if not self.options.unicode_whitespace: return c in ' \t\n\r' else: if not isinstance(c, str): c = str(c) if c in ' \t\n\r\f\v': return True import unicodedata return unicodedata.category(c) == 'Zs'
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3661-L3678
25
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
50
[ 9, 10, 12, 13, 14, 15, 16, 17 ]
44.444444
false
14.825334
18
4
55.555556
6
def isws(self, c): if not self.options.unicode_whitespace: return c in ' \t\n\r' else: if not isinstance(c, str): c = str(c) if c in ' \t\n\r\f\v': return True import unicodedata return unicodedata.category(c) == 'Zs'
18,532
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.islineterm
(self, c)
return False
Determines if the given character is considered a line terminator. Ref. ECMAScript section 7.3
Determines if the given character is considered a line terminator.
3,680
3,690
def islineterm(self, c): """Determines if the given character is considered a line terminator. Ref. ECMAScript section 7.3 """ if c == '\r' or c == '\n': return True if c == '\u2028' or c == '\u2029': # unicodedata.category(c) in ['Zl', 'Zp'] return True return False
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3680-L3690
25
[ 0, 1, 2, 3, 4, 5 ]
54.545455
[ 6, 7, 8, 9, 10 ]
45.454545
false
14.825334
11
5
54.545455
3
def islineterm(self, c): if c == '\r' or c == '\n': return True if c == '\u2028' or c == '\u2029': # unicodedata.category(c) in ['Zl', 'Zp'] return True return False
18,533
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.recover_parser
(self, state)
return stopchar
Try to recover after a syntax error by locating the next "known" position.
Try to recover after a syntax error by locating the next "known" position.
3,692
3,702
def recover_parser(self, state): """Try to recover after a syntax error by locating the next "known" position.""" buf = state.buf buf.skipuntil(lambda c: c in ",:[]{}\"\';" or helpers.char_is_unicode_eol(c)) stopchar = buf.peek() self.skipws(state) if buf.at_end: state.push_info("Could not recover parsing after previous error", position=buf.position) else: state.push_info("Recovering parsing after character %r" % stopchar, position=buf.position) return stopchar
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3692-L3702
25
[ 0, 1 ]
18.181818
[ 2, 3, 4, 5, 6, 7, 9, 10 ]
72.727273
false
14.825334
11
3
27.272727
1
def recover_parser(self, state): buf = state.buf buf.skipuntil(lambda c: c in ",:[]{}\"\';" or helpers.char_is_unicode_eol(c)) stopchar = buf.peek() self.skipws(state) if buf.at_end: state.push_info("Could not recover parsing after previous error", position=buf.position) else: state.push_info("Recovering parsing after character %r" % stopchar, position=buf.position) return stopchar
18,534
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.decode_null
(self, state)
return None
Intermediate-level decoder for ECMAScript 'null' keyword. Takes a string and a starting index, and returns a Python None object and the index of the next unparsed character.
Intermediate-level decoder for ECMAScript 'null' keyword. Takes a string and a starting index, and returns a Python None object and the index of the next unparsed character.
3,704
3,717
def decode_null(self, state): """ Intermediate-level decoder for ECMAScript 'null' keyword. Takes a string and a starting index, and returns a Python None object and the index of the next unparsed character. """ buf = state.buf start_position = buf.position kw = buf.pop_identifier() if not kw or kw != 'null': state.push_error("Expected a 'null' keyword'", kw, position=start_position) else: state.stats.num_nulls += 1 return None
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3704-L3717
25
[ 0, 1, 2, 3, 4, 5 ]
42.857143
[ 6, 7, 8, 9, 10, 12, 13 ]
50
false
14.825334
14
3
50
3
def decode_null(self, state): buf = state.buf start_position = buf.position kw = buf.pop_identifier() if not kw or kw != 'null': state.push_error("Expected a 'null' keyword'", kw, position=start_position) else: state.stats.num_nulls += 1 return None
18,535
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.encode_undefined
(self, state)
Produces the ECMAScript 'undefined' keyword.
Produces the ECMAScript 'undefined' keyword.
3,719
3,721
def encode_undefined(self, state): """Produces the ECMAScript 'undefined' keyword.""" state.append('undefined')
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3719-L3721
25
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
14.825334
3
1
66.666667
1
def encode_undefined(self, state): state.append('undefined')
18,536
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.encode_null
(self, state)
Produces the JSON 'null' keyword.
Produces the JSON 'null' keyword.
3,723
3,725
def encode_null(self, state): """Produces the JSON 'null' keyword.""" state.append('null')
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3723-L3725
25
[ 0, 1 ]
66.666667
[ 2 ]
33.333333
false
14.825334
3
1
66.666667
1
def encode_null(self, state): state.append('null')
18,537
akfamily/akshare
087025d8d6f799b30ca114013e82c1ad22dc9294
akshare/utils/demjson.py
JSON.decode_boolean
(self, state)
return (kw == 'true')
Intermediate-level decode for JSON boolean literals. Takes a string and a starting index, and returns a Python bool (True or False) and the index of the next unparsed character.
Intermediate-level decode for JSON boolean literals.
3,727
3,741
def decode_boolean(self, state): """Intermediate-level decode for JSON boolean literals. Takes a string and a starting index, and returns a Python bool (True or False) and the index of the next unparsed character. """ buf = state.buf start_position = buf.position kw = buf.pop_identifier() if not kw or kw not in ('true', 'false'): state.push_error("Expected a 'true' or 'false' keyword'", kw, position=start_position) else: state.stats.num_bools += 1 return (kw == 'true')
https://github.com/akfamily/akshare/blob/087025d8d6f799b30ca114013e82c1ad22dc9294/project25/akshare/utils/demjson.py#L3727-L3741
25
[ 0, 1, 2, 3, 4, 5, 6 ]
46.666667
[ 7, 8, 9, 10, 11, 13, 14 ]
46.666667
false
14.825334
15
3
53.333333
4
def decode_boolean(self, state): buf = state.buf start_position = buf.position kw = buf.pop_identifier() if not kw or kw not in ('true', 'false'): state.push_error("Expected a 'true' or 'false' keyword'", kw, position=start_position) else: state.stats.num_bools += 1 return (kw == 'true')
18,538