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
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path.isabsolute
(self, isabsolute)
Raises: AttributeError if _force_absolute(self) returns True.
Raises: AttributeError if _force_absolute(self) returns True.
602
611
def isabsolute(self, isabsolute): """ Raises: AttributeError if _force_absolute(self) returns True. """ if self._force_absolute(self): s = ('Path.isabsolute is True and read-only for URLs with a netloc' ' (a username, password, host, and/or port). A URL path must ' "start with a '/' to separate itself from a netloc.") raise AttributeError(s) self._isabsolute = isabsolute
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L602-L611
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
96.258065
10
2
100
1
def isabsolute(self, isabsolute): if self._force_absolute(self): s = ('Path.isabsolute is True and read-only for URLs with a netloc' ' (a username, password, host, and/or port). A URL path must ' "start with a '/' to separate itself from a netloc.") raise AttributeError(s) self._isabsolute = isabsolute
28,163
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path.isdir
(self)
return (self.segments == [] or (self.segments and self.segments[-1] == ''))
Returns: True if the path ends on a directory, False otherwise. If True, the last segment is '', representing the trailing '/' of the path.
Returns: True if the path ends on a directory, False otherwise. If True, the last segment is '', representing the trailing '/' of the path.
614
621
def isdir(self): """ Returns: True if the path ends on a directory, False otherwise. If True, the last segment is '', representing the trailing '/' of the path. """ return (self.segments == [] or (self.segments and self.segments[-1] == ''))
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L614-L621
45
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
96.258065
8
3
100
3
def isdir(self): return (self.segments == [] or (self.segments and self.segments[-1] == ''))
28,164
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path.isfile
(self)
return not self.isdir
Returns: True if the path ends on a file, False otherwise. If True, the last segment is not '', representing some file as the last segment of the path.
Returns: True if the path ends on a file, False otherwise. If True, the last segment is not '', representing some file as the last segment of the path.
624
630
def isfile(self): """ Returns: True if the path ends on a file, False otherwise. If True, the last segment is not '', representing some file as the last segment of the path. """ return not self.isdir
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L624-L630
45
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
96.258065
7
1
100
3
def isfile(self): return not self.isdir
28,165
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path.__truediv__
(self, path)
return copy.add(path)
632
634
def __truediv__(self, path): copy = deepcopy(self) return copy.add(path)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L632-L634
45
[ 0, 1, 2 ]
100
[]
0
true
96.258065
3
1
100
0
def __truediv__(self, path): copy = deepcopy(self) return copy.add(path)
28,166
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path.__eq__
(self, other)
return str(self) == str(other)
636
637
def __eq__(self, other): return str(self) == str(other)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L636-L637
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __eq__(self, other): return str(self) == str(other)
28,167
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path.__ne__
(self, other)
return not self == other
639
640
def __ne__(self, other): return not self == other
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L639-L640
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __ne__(self, other): return not self == other
28,168
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path.__bool__
(self)
return len(self.segments) > 0
642
643
def __bool__(self): return len(self.segments) > 0
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L642-L643
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __bool__(self): return len(self.segments) > 0
28,169
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path.__str__
(self)
return self._path_from_segments(segments)
646
653
def __str__(self): segments = list(self.segments) if self.isabsolute: if not segments: segments = ['', ''] else: segments.insert(0, '') return self._path_from_segments(segments)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L646-L653
45
[ 0, 1, 2, 3, 4, 6, 7 ]
87.5
[]
0
false
96.258065
8
3
100
0
def __str__(self): segments = list(self.segments) if self.isabsolute: if not segments: segments = ['', ''] else: segments.insert(0, '') return self._path_from_segments(segments)
28,170
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path.__repr__
(self)
return "%s('%s')" % (self.__class__.__name__, str(self))
655
656
def __repr__(self): return "%s('%s')" % (self.__class__.__name__, str(self))
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L655-L656
45
[ 0 ]
50
[ 1 ]
50
false
96.258065
2
1
50
0
def __repr__(self): return "%s('%s')" % (self.__class__.__name__, str(self))
28,171
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path._segments_from_path
(self, path)
return [unquote(segment) for segment in segments]
Returns: The list of path segments from the path string <path>. Raises: UserWarning if <path> is an improperly encoded path string and self.strict is True. TODO(grun): Accept both list values and string values and refactor the list vs string interface testing to this common method.
Returns: The list of path segments from the path string <path>.
658
689
def _segments_from_path(self, path): """ Returns: The list of path segments from the path string <path>. Raises: UserWarning if <path> is an improperly encoded path string and self.strict is True. TODO(grun): Accept both list values and string values and refactor the list vs string interface testing to this common method. """ segments = [] for segment in path.split('/'): if not is_valid_encoded_path_segment(segment): segment = quote(utf8(segment)) if self.strict: s = ("Improperly encoded path string received: '%s'. " "Proceeding, but did you mean '%s'?" % (path, self._path_from_segments(segments))) warnings.warn(s, UserWarning) segments.append(utf8(segment)) del segment # In Python 3, utf8() returns Bytes objects that must be decoded into # strings before they can be passed to unquote(). In Python 2, utf8() # returns strings that can be passed directly to urllib.unquote(). segments = [ segment.decode('utf8') if isinstance(segment, bytes) and not isinstance(segment, str) else segment for segment in segments] return [unquote(segment) for segment in segments]
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L658-L689
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 ]
87.5
[ 16, 19 ]
6.25
false
96.258065
32
7
93.75
8
def _segments_from_path(self, path): segments = [] for segment in path.split('/'): if not is_valid_encoded_path_segment(segment): segment = quote(utf8(segment)) if self.strict: s = ("Improperly encoded path string received: '%s'. " "Proceeding, but did you mean '%s'?" % (path, self._path_from_segments(segments))) warnings.warn(s, UserWarning) segments.append(utf8(segment)) del segment # In Python 3, utf8() returns Bytes objects that must be decoded into # strings before they can be passed to unquote(). In Python 2, utf8() # returns strings that can be passed directly to urllib.unquote(). segments = [ segment.decode('utf8') if isinstance(segment, bytes) and not isinstance(segment, str) else segment for segment in segments] return [unquote(segment) for segment in segments]
28,172
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Path._path_from_segments
(self, segments)
return '/'.join(segments)
Combine the provided path segments <segments> into a path string. Path segments in <segments> will be quoted. Returns: A path string with quoted path segments.
Combine the provided path segments <segments> into a path string. Path segments in <segments> will be quoted.
691
701
def _path_from_segments(self, segments): """ Combine the provided path segments <segments> into a path string. Path segments in <segments> will be quoted. Returns: A path string with quoted path segments. """ segments = [ quote(utf8(attemptstr(segment)), self.SAFE_SEGMENT_CHARS) for segment in segments] return '/'.join(segments)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L691-L701
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
96.258065
11
2
100
4
def _path_from_segments(self, segments): segments = [ quote(utf8(attemptstr(segment)), self.SAFE_SEGMENT_CHARS) for segment in segments] return '/'.join(segments)
28,173
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.__init__
(self, query='', strict=False)
904
909
def __init__(self, query='', strict=False): self.strict = strict self._params = omdict1D() self.load(query)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L904-L909
45
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
96.258065
6
1
100
0
def __init__(self, query='', strict=False): self.strict = strict self._params = omdict1D() self.load(query)
28,174
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.load
(self, query)
return self
911
914
def load(self, query): items = self._items(query) self.params.load(items) return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L911-L914
45
[ 0, 1, 2, 3 ]
100
[]
0
true
96.258065
4
1
100
0
def load(self, query): items = self._items(query) self.params.load(items) return self
28,175
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.add
(self, args)
return self
916
919
def add(self, args): for param, value in self._items(args): self.params.add(param, value) return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L916-L919
45
[ 0, 1, 2, 3 ]
100
[]
0
true
96.258065
4
2
100
0
def add(self, args): for param, value in self._items(args): self.params.add(param, value) return self
28,176
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.set
(self, mapping)
return self
Adopt all mappings in <mapping>, replacing any existing mappings with the same key. If a key has multiple values in <mapping>, they are all adopted. Examples: Query({1:1}).set([(1,None),(2,2)]).params.allitems() == [(1,None),(2,2)] Query({1:None,2:None}).set([(1,1),(2,2),(1,11)]).params.allitems() == [(1,1),(2,2),(1,11)] Query({1:None}).set([(1,[1,11,111])]).params.allitems() == [(1,1),(1,11),(1,111)] Returns: <self>.
Adopt all mappings in <mapping>, replacing any existing mappings with the same key. If a key has multiple values in <mapping>, they are all adopted.
921
938
def set(self, mapping): """ Adopt all mappings in <mapping>, replacing any existing mappings with the same key. If a key has multiple values in <mapping>, they are all adopted. Examples: Query({1:1}).set([(1,None),(2,2)]).params.allitems() == [(1,None),(2,2)] Query({1:None,2:None}).set([(1,1),(2,2),(1,11)]).params.allitems() == [(1,1),(2,2),(1,11)] Query({1:None}).set([(1,[1,11,111])]).params.allitems() == [(1,1),(1,11),(1,111)] Returns: <self>. """ self.params.updateall(mapping) return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L921-L938
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
100
[]
0
true
96.258065
18
1
100
13
def set(self, mapping): self.params.updateall(mapping) return self
28,177
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.remove
(self, query)
return self
940
962
def remove(self, query): if query is True: self.load('') return self # Single key to remove. items = [query] # Dictionary or multivalue dictionary of items to remove. if callable_attr(query, 'items'): items = self._items(query) # List of keys or items to remove. elif non_string_iterable(query): items = query for item in items: if non_string_iterable(item) and len(item) == 2: key, value = item self.params.popvalue(key, value, None) else: key = item self.params.pop(key, None) return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L940-L962
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22 ]
95.652174
[]
0
false
96.258065
23
7
100
0
def remove(self, query): if query is True: self.load('') return self # Single key to remove. items = [query] # Dictionary or multivalue dictionary of items to remove. if callable_attr(query, 'items'): items = self._items(query) # List of keys or items to remove. elif non_string_iterable(query): items = query for item in items: if non_string_iterable(item) and len(item) == 2: key, value = item self.params.popvalue(key, value, None) else: key = item self.params.pop(key, None) return self
28,178
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.params
(self)
return self._params
965
966
def params(self): return self._params
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L965-L966
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def params(self): return self._params
28,179
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.params
(self, params)
969
974
def params(self, params): items = self._items(params) self._params.clear() for key, value in items: self._params.add(key, value)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L969-L974
45
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
96.258065
6
2
100
0
def params(self, params): items = self._items(params) self._params.clear() for key, value in items: self._params.add(key, value)
28,180
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.encode
(self, delimiter='&', quote_plus=True, dont_quote='', delimeter=_absent)
return query
Examples: Query('a=a&b=#').encode() == 'a=a&b=%23' Query('a=a&b=#').encode(';') == 'a=a;b=%23' Query('a+b=c@d').encode(dont_quote='@') == 'a+b=c@d' Query('a+b=c@d').encode(quote_plus=False) == 'a%20b=c%40d' Until furl v0.4.6, the 'delimiter' argument was incorrectly spelled 'delimeter'. For backwards compatibility, accept both the correct 'delimiter' and the old, misspelled 'delimeter'. Keys and values are encoded application/x-www-form-urlencoded if <quote_plus> is True, percent-encoded otherwise. <dont_quote> exempts valid query characters from being percent-encoded, either in their entirety with dont_quote=True, or selectively with dont_quote=<string>, like dont_quote='/?@_'. Invalid query characters -- those not in self.SAFE_KEY_CHARS, like '#' and '^' -- are always encoded, even if included in <dont_quote>. For example: Query('#=^').encode(dont_quote='#^') == '%23=%5E'. Returns: A URL encoded query string using <delimiter> as the delimiter separating key:value pairs. The most common and default delimiter is '&', but ';' can also be specified. ';' is W3C recommended.
Examples:
976
1,033
def encode(self, delimiter='&', quote_plus=True, dont_quote='', delimeter=_absent): """ Examples: Query('a=a&b=#').encode() == 'a=a&b=%23' Query('a=a&b=#').encode(';') == 'a=a;b=%23' Query('a+b=c@d').encode(dont_quote='@') == 'a+b=c@d' Query('a+b=c@d').encode(quote_plus=False) == 'a%20b=c%40d' Until furl v0.4.6, the 'delimiter' argument was incorrectly spelled 'delimeter'. For backwards compatibility, accept both the correct 'delimiter' and the old, misspelled 'delimeter'. Keys and values are encoded application/x-www-form-urlencoded if <quote_plus> is True, percent-encoded otherwise. <dont_quote> exempts valid query characters from being percent-encoded, either in their entirety with dont_quote=True, or selectively with dont_quote=<string>, like dont_quote='/?@_'. Invalid query characters -- those not in self.SAFE_KEY_CHARS, like '#' and '^' -- are always encoded, even if included in <dont_quote>. For example: Query('#=^').encode(dont_quote='#^') == '%23=%5E'. Returns: A URL encoded query string using <delimiter> as the delimiter separating key:value pairs. The most common and default delimiter is '&', but ';' can also be specified. ';' is W3C recommended. """ if delimeter is not _absent: delimiter = delimeter quote_key = create_quote_fn(self.SAFE_KEY_CHARS, quote_plus) quote_value = create_quote_fn(self.SAFE_VALUE_CHARS, quote_plus) pairs = [] for key, value in self.params.iterallitems(): utf8key = utf8(key, utf8(attemptstr(key))) quoted_key = quote_key(utf8key, dont_quote) if value is None: # Example: http://sprop.su/?key. pair = quoted_key else: # Example: http://sprop.su/?key=value. utf8value = utf8(value, utf8(attemptstr(value))) quoted_value = quote_value(utf8value, dont_quote) if not quoted_key: # Unquote '=' to allow queries like '?==='. quoted_value = quoted_value.replace('%3D', '=') pair = '%s=%s' % (quoted_key, quoted_value) pairs.append(pair) query = delimiter.join(pairs) return query
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L976-L1033
45
[ 0, 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 ]
50
[]
0
false
96.258065
58
5
100
27
def encode(self, delimiter='&', quote_plus=True, dont_quote='', delimeter=_absent): if delimeter is not _absent: delimiter = delimeter quote_key = create_quote_fn(self.SAFE_KEY_CHARS, quote_plus) quote_value = create_quote_fn(self.SAFE_VALUE_CHARS, quote_plus) pairs = [] for key, value in self.params.iterallitems(): utf8key = utf8(key, utf8(attemptstr(key))) quoted_key = quote_key(utf8key, dont_quote) if value is None: # Example: http://sprop.su/?key. pair = quoted_key else: # Example: http://sprop.su/?key=value. utf8value = utf8(value, utf8(attemptstr(value))) quoted_value = quote_value(utf8value, dont_quote) if not quoted_key: # Unquote '=' to allow queries like '?==='. quoted_value = quoted_value.replace('%3D', '=') pair = '%s=%s' % (quoted_key, quoted_value) pairs.append(pair) query = delimiter.join(pairs) return query
28,181
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.asdict
(self)
return { 'encoded': str(self), 'params': self.params.allitems(), }
1,035
1,039
def asdict(self): return { 'encoded': str(self), 'params': self.params.allitems(), }
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1035-L1039
45
[ 0, 1 ]
40
[]
0
false
96.258065
5
1
100
0
def asdict(self): return { 'encoded': str(self), 'params': self.params.allitems(), }
28,182
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.__eq__
(self, other)
return str(self) == str(other)
1,041
1,042
def __eq__(self, other): return str(self) == str(other)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1041-L1042
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __eq__(self, other): return str(self) == str(other)
28,183
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.__ne__
(self, other)
return not self == other
1,044
1,045
def __ne__(self, other): return not self == other
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1044-L1045
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __ne__(self, other): return not self == other
28,184
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.__bool__
(self)
return len(self.params) > 0
1,047
1,048
def __bool__(self): return len(self.params) > 0
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1047-L1048
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __bool__(self): return len(self.params) > 0
28,185
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.__str__
(self)
return self.encode()
1,051
1,052
def __str__(self): return self.encode()
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1051-L1052
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __str__(self): return self.encode()
28,186
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query.__repr__
(self)
return "%s('%s')" % (self.__class__.__name__, str(self))
1,054
1,055
def __repr__(self): return "%s('%s')" % (self.__class__.__name__, str(self))
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1054-L1055
45
[ 0 ]
50
[ 1 ]
50
false
96.258065
2
1
50
0
def __repr__(self): return "%s('%s')" % (self.__class__.__name__, str(self))
28,187
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query._items
(self, items)
return items
Extract and return the key:value items from various containers. Some containers that could hold key:value items are - List of (key,value) tuples. - Dictionaries of key:value items. - Multivalue dictionary of key:value items, with potentially repeated keys. - Query string with encoded params and values. Keys and values are passed through unmodified unless they were passed in within an encoded query string, like 'a=a%20a&b=b'. Keys and values passed in within an encoded query string are unquoted by urlparse.parse_qsl(), which uses urllib.unquote_plus() internally. Returns: List of items as (key, value) tuples. Keys and values are passed through unmodified unless they were passed in as part of an encoded query string, in which case the final keys and values that are returned will be unquoted. Raises: UserWarning if <path> is an improperly encoded path string and self.strict is True.
Extract and return the key:value items from various containers. Some containers that could hold key:value items are
1,057
1,103
def _items(self, items): """ Extract and return the key:value items from various containers. Some containers that could hold key:value items are - List of (key,value) tuples. - Dictionaries of key:value items. - Multivalue dictionary of key:value items, with potentially repeated keys. - Query string with encoded params and values. Keys and values are passed through unmodified unless they were passed in within an encoded query string, like 'a=a%20a&b=b'. Keys and values passed in within an encoded query string are unquoted by urlparse.parse_qsl(), which uses urllib.unquote_plus() internally. Returns: List of items as (key, value) tuples. Keys and values are passed through unmodified unless they were passed in as part of an encoded query string, in which case the final keys and values that are returned will be unquoted. Raises: UserWarning if <path> is an improperly encoded path string and self.strict is True. """ if not items: items = [] # Multivalue Dictionary-like interface. e.g. {'a':1, 'a':2, # 'b':2} elif callable_attr(items, 'allitems'): items = list(items.allitems()) elif callable_attr(items, 'iterallitems'): items = list(items.iterallitems()) # Dictionary-like interface. e.g. {'a':1, 'b':2, 'c':3} elif callable_attr(items, 'items'): items = list(items.items()) elif callable_attr(items, 'iteritems'): items = list(items.iteritems()) # Encoded query string. e.g. 'a=1&b=2&c=3' elif isinstance(items, six.string_types): items = self._extract_items_from_querystr(items) # Default to list of key:value items interface. e.g. [('a','1'), # ('b','2')] else: items = list(items) return items
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1057-L1103
45
[ 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, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 44, 45, 46 ]
95.744681
[ 32, 37 ]
4.255319
false
96.258065
47
7
95.744681
22
def _items(self, items): if not items: items = [] # Multivalue Dictionary-like interface. e.g. {'a':1, 'a':2, # 'b':2} elif callable_attr(items, 'allitems'): items = list(items.allitems()) elif callable_attr(items, 'iterallitems'): items = list(items.iterallitems()) # Dictionary-like interface. e.g. {'a':1, 'b':2, 'c':3} elif callable_attr(items, 'items'): items = list(items.items()) elif callable_attr(items, 'iteritems'): items = list(items.iteritems()) # Encoded query string. e.g. 'a=1&b=2&c=3' elif isinstance(items, six.string_types): items = self._extract_items_from_querystr(items) # Default to list of key:value items interface. e.g. [('a','1'), # ('b','2')] else: items = list(items) return items
28,188
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Query._extract_items_from_querystr
(self, querystr)
return items
1,105
1,131
def _extract_items_from_querystr(self, querystr): items = [] pairstrs = querystr.split('&') pairs = [item.split('=', 1) for item in pairstrs] pairs = [(p[0], lget(p, 1, '')) for p in pairs] # Pad with value ''. for pairstr, (key, value) in six.moves.zip(pairstrs, pairs): valid_key = is_valid_encoded_query_key(key) valid_value = is_valid_encoded_query_value(value) if self.strict and (not valid_key or not valid_value): msg = ( "Incorrectly percent encoded query string received: '%s'. " "Proceeding, but did you mean '%s'?" % (querystr, urllib.parse.urlencode(pairs))) warnings.warn(msg, UserWarning) key_decoded = unquote(key.replace('+', ' ')) # Empty value without a '=', e.g. '?sup'. if key == pairstr: value_decoded = None else: value_decoded = unquote(value.replace('+', ' ')) items.append((key_decoded, value_decoded)) return items
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1105-L1131
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26 ]
77.777778
[ 11, 15 ]
7.407407
false
96.258065
27
8
92.592593
0
def _extract_items_from_querystr(self, querystr): items = [] pairstrs = querystr.split('&') pairs = [item.split('=', 1) for item in pairstrs] pairs = [(p[0], lget(p, 1, '')) for p in pairs] # Pad with value ''. for pairstr, (key, value) in six.moves.zip(pairstrs, pairs): valid_key = is_valid_encoded_query_key(key) valid_value = is_valid_encoded_query_value(value) if self.strict and (not valid_key or not valid_value): msg = ( "Incorrectly percent encoded query string received: '%s'. " "Proceeding, but did you mean '%s'?" % (querystr, urllib.parse.urlencode(pairs))) warnings.warn(msg, UserWarning) key_decoded = unquote(key.replace('+', ' ')) # Empty value without a '=', e.g. '?sup'. if key == pairstr: value_decoded = None else: value_decoded = unquote(value.replace('+', ' ')) items.append((key_decoded, value_decoded)) return items
28,189
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.__init__
(self, fragment='', strict=False)
1,194
1,200
def __init__(self, fragment='', strict=False): FragmentPathCompositionInterface.__init__(self, strict=strict) QueryCompositionInterface.__init__(self, strict=strict) self.strict = strict self.separator = True self.load(fragment)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1194-L1200
45
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
96.258065
7
1
100
0
def __init__(self, fragment='', strict=False): FragmentPathCompositionInterface.__init__(self, strict=strict) QueryCompositionInterface.__init__(self, strict=strict) self.strict = strict self.separator = True self.load(fragment)
28,190
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.load
(self, fragment)
1,202
1,231
def load(self, fragment): self.path.load('') self.query.load('') if fragment is None: fragment = '' toks = fragment.split('?', 1) if len(toks) == 0: self._path.load('') self._query.load('') elif len(toks) == 1: # Does this fragment look like a path or a query? Default to # path. if '=' in fragment: # Query example: '#woofs=dogs'. self._query.load(fragment) else: # Path example: '#supinthisthread'. self._path.load(fragment) else: # Does toks[1] actually look like a query? Like 'a=a' or # 'a=' or '=a'? if '=' in toks[1]: self._path.load(toks[0]) self._query.load(toks[1]) # If toks[1] doesn't look like a query, the user probably # provided a fragment string like 'a?b?' that was intended # to be adopted as-is, not a two part fragment with path 'a' # and query 'b?'. else: self._path.load(fragment)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1202-L1231
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 17, 20, 21, 22, 23, 24, 25, 26, 27, 29 ]
76.666667
[ 9, 10, 15 ]
10
false
96.258065
30
6
90
0
def load(self, fragment): self.path.load('') self.query.load('') if fragment is None: fragment = '' toks = fragment.split('?', 1) if len(toks) == 0: self._path.load('') self._query.load('') elif len(toks) == 1: # Does this fragment look like a path or a query? Default to # path. if '=' in fragment: # Query example: '#woofs=dogs'. self._query.load(fragment) else: # Path example: '#supinthisthread'. self._path.load(fragment) else: # Does toks[1] actually look like a query? Like 'a=a' or # 'a=' or '=a'? if '=' in toks[1]: self._path.load(toks[0]) self._query.load(toks[1]) # If toks[1] doesn't look like a query, the user probably # provided a fragment string like 'a?b?' that was intended # to be adopted as-is, not a two part fragment with path 'a' # and query 'b?'. else: self._path.load(fragment)
28,191
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.add
(self, path=_absent, args=_absent)
return self
1,233
1,239
def add(self, path=_absent, args=_absent): if path is not _absent: self.path.add(path) if args is not _absent: self.query.add(args) return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1233-L1239
45
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
96.258065
7
3
100
0
def add(self, path=_absent, args=_absent): if path is not _absent: self.path.add(path) if args is not _absent: self.query.add(args) return self
28,192
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.set
(self, path=_absent, args=_absent, separator=_absent)
return self
1,241
1,249
def set(self, path=_absent, args=_absent, separator=_absent): if path is not _absent: self.path.load(path) if args is not _absent: self.query.load(args) if separator is True or separator is False: self.separator = separator return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1241-L1249
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
96.258065
9
5
100
0
def set(self, path=_absent, args=_absent, separator=_absent): if path is not _absent: self.path.load(path) if args is not _absent: self.query.load(args) if separator is True or separator is False: self.separator = separator return self
28,193
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.remove
(self, fragment=_absent, path=_absent, args=_absent)
return self
1,251
1,259
def remove(self, fragment=_absent, path=_absent, args=_absent): if fragment is True: self.load('') if path is not _absent: self.path.remove(path) if args is not _absent: self.query.remove(args) return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1251-L1259
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
96.258065
9
4
100
0
def remove(self, fragment=_absent, path=_absent, args=_absent): if fragment is True: self.load('') if path is not _absent: self.path.remove(path) if args is not _absent: self.query.remove(args) return self
28,194
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.asdict
(self)
return { 'encoded': str(self), 'separator': self.separator, 'path': self.path.asdict(), 'query': self.query.asdict(), }
1,261
1,267
def asdict(self): return { 'encoded': str(self), 'separator': self.separator, 'path': self.path.asdict(), 'query': self.query.asdict(), }
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1261-L1267
45
[ 0, 1 ]
28.571429
[]
0
false
96.258065
7
1
100
0
def asdict(self): return { 'encoded': str(self), 'separator': self.separator, 'path': self.path.asdict(), 'query': self.query.asdict(), }
28,195
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.__eq__
(self, other)
return str(self) == str(other)
1,269
1,270
def __eq__(self, other): return str(self) == str(other)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1269-L1270
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __eq__(self, other): return str(self) == str(other)
28,196
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.__ne__
(self, other)
return not self == other
1,272
1,273
def __ne__(self, other): return not self == other
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1272-L1273
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __ne__(self, other): return not self == other
28,197
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.__setattr__
(self, attr, value)
1,275
1,278
def __setattr__(self, attr, value): if (not PathCompositionInterface.__setattr__(self, attr, value) and not QueryCompositionInterface.__setattr__(self, attr, value)): object.__setattr__(self, attr, value)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1275-L1278
45
[ 0, 1, 3 ]
75
[]
0
false
96.258065
4
3
100
0
def __setattr__(self, attr, value): if (not PathCompositionInterface.__setattr__(self, attr, value) and not QueryCompositionInterface.__setattr__(self, attr, value)): object.__setattr__(self, attr, value)
28,198
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.__bool__
(self)
return bool(self.path) or bool(self.query)
1,280
1,281
def __bool__(self): return bool(self.path) or bool(self.query)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1280-L1281
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
2
100
0
def __bool__(self): return bool(self.path) or bool(self.query)
28,199
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.__str__
(self)
return path + separator + query
1,284
1,296
def __str__(self): path, query = str(self._path), str(self._query) # If there is no query or self.separator is False, decode all # '?' characters in the path from their percent encoded form # '%3F' to '?'. This allows for fragment strings containg '?'s, # like '#dog?machine?yes'. if path and (not query or not self.separator): path = path.replace('%3F', '?') separator = '?' if path and query and self.separator else '' return path + separator + query
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1284-L1296
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
100
[]
0
true
96.258065
13
6
100
0
def __str__(self): path, query = str(self._path), str(self._query) # If there is no query or self.separator is False, decode all # '?' characters in the path from their percent encoded form # '%3F' to '?'. This allows for fragment strings containg '?'s, # like '#dog?machine?yes'. if path and (not query or not self.separator): path = path.replace('%3F', '?') separator = '?' if path and query and self.separator else '' return path + separator + query
28,200
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
Fragment.__repr__
(self)
return "%s('%s')" % (self.__class__.__name__, str(self))
1,298
1,299
def __repr__(self): return "%s('%s')" % (self.__class__.__name__, str(self))
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1298-L1299
45
[ 0 ]
50
[ 1 ]
50
false
96.258065
2
1
50
0
def __repr__(self): return "%s('%s')" % (self.__class__.__name__, str(self))
28,201
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.__init__
(self, url='', args=_absent, path=_absent, fragment=_absent, scheme=_absent, netloc=_absent, origin=_absent, fragment_path=_absent, fragment_args=_absent, fragment_separator=_absent, host=_absent, port=_absent, query=_absent, query_params=_absent, username=_absent, password=_absent, strict=False)
Raises: ValueError on invalid URL or invalid URL component(s) provided.
Raises: ValueError on invalid URL or invalid URL component(s) provided.
1,367
1,387
def __init__(self, url='', args=_absent, path=_absent, fragment=_absent, scheme=_absent, netloc=_absent, origin=_absent, fragment_path=_absent, fragment_args=_absent, fragment_separator=_absent, host=_absent, port=_absent, query=_absent, query_params=_absent, username=_absent, password=_absent, strict=False): """ Raises: ValueError on invalid URL or invalid URL component(s) provided. """ URLPathCompositionInterface.__init__(self, strict=strict) QueryCompositionInterface.__init__(self, strict=strict) FragmentCompositionInterface.__init__(self, strict=strict) self.strict = strict self.load(url) # Raises ValueError on invalid URL. self.set( # Raises ValueError on invalid URL component(s). args=args, path=path, fragment=fragment, scheme=scheme, netloc=netloc, origin=origin, fragment_path=fragment_path, fragment_args=fragment_args, fragment_separator=fragment_separator, host=host, port=port, query=query, query_params=query_params, username=username, password=password)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1367-L1387
45
[ 0, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
66.666667
[]
0
false
96.258065
21
1
100
1
def __init__(self, url='', args=_absent, path=_absent, fragment=_absent, scheme=_absent, netloc=_absent, origin=_absent, fragment_path=_absent, fragment_args=_absent, fragment_separator=_absent, host=_absent, port=_absent, query=_absent, query_params=_absent, username=_absent, password=_absent, strict=False): URLPathCompositionInterface.__init__(self, strict=strict) QueryCompositionInterface.__init__(self, strict=strict) FragmentCompositionInterface.__init__(self, strict=strict) self.strict = strict self.load(url) # Raises ValueError on invalid URL. self.set( # Raises ValueError on invalid URL component(s). args=args, path=path, fragment=fragment, scheme=scheme, netloc=netloc, origin=origin, fragment_path=fragment_path, fragment_args=fragment_args, fragment_separator=fragment_separator, host=host, port=port, query=query, query_params=query_params, username=username, password=password)
28,202
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.load
(self, url)
return self
Parse and load a URL. Raises: ValueError on invalid URL, like a malformed IPv6 address or invalid port.
Parse and load a URL.
1,389
1,416
def load(self, url): """ Parse and load a URL. Raises: ValueError on invalid URL, like a malformed IPv6 address or invalid port. """ self.username = self.password = None self._host = self._port = self._scheme = None if url is None: url = '' if not isinstance(url, six.string_types): url = str(url) # urlsplit() raises a ValueError on malformed IPv6 addresses in # Python 2.7+. tokens = urlsplit(url) self.netloc = tokens.netloc # Raises ValueError in Python 2.7+. self.scheme = tokens.scheme if not self.port: self._port = DEFAULT_PORTS.get(self.scheme) self.path.load(tokens.path) self.query.load(tokens.query) self.fragment.load(tokens.fragment) return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1389-L1416
45
[ 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 ]
100
[]
0
true
96.258065
28
4
100
4
def load(self, url): self.username = self.password = None self._host = self._port = self._scheme = None if url is None: url = '' if not isinstance(url, six.string_types): url = str(url) # urlsplit() raises a ValueError on malformed IPv6 addresses in # Python 2.7+. tokens = urlsplit(url) self.netloc = tokens.netloc # Raises ValueError in Python 2.7+. self.scheme = tokens.scheme if not self.port: self._port = DEFAULT_PORTS.get(self.scheme) self.path.load(tokens.path) self.query.load(tokens.query) self.fragment.load(tokens.fragment) return self
28,203
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.scheme
(self)
return self._scheme
1,419
1,420
def scheme(self): return self._scheme
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1419-L1420
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def scheme(self): return self._scheme
28,204
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.scheme
(self, scheme)
1,423
1,426
def scheme(self, scheme): if callable_attr(scheme, 'lower'): scheme = scheme.lower() self._scheme = scheme
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1423-L1426
45
[ 0, 1, 2, 3 ]
100
[]
0
true
96.258065
4
2
100
0
def scheme(self, scheme): if callable_attr(scheme, 'lower'): scheme = scheme.lower() self._scheme = scheme
28,205
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.host
(self)
return self._host
1,429
1,430
def host(self): return self._host
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1429-L1430
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def host(self): return self._host
28,206
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.host
(self, host)
Raises: ValueError on invalid host or malformed IPv6 address.
Raises: ValueError on invalid host or malformed IPv6 address.
1,433
1,456
def host(self, host): """ Raises: ValueError on invalid host or malformed IPv6 address. """ # Invalid IPv6 literal. urllib.parse.urlsplit('http://%s/' % host) # Raises ValueError. # Invalid host string. resembles_ipv6_literal = ( host is not None and lget(host, 0) == '[' and ':' in host and lget(host, -1) == ']') if (host is not None and not resembles_ipv6_literal and not is_valid_host(host)): errmsg = ( "Invalid host '%s'. Host strings must have at least one " "non-period character, can't contain any of '%s', and can't " "have adjacent periods.") raise ValueError(errmsg % (host, INVALID_HOST_CHARS)) if callable_attr(host, 'lower'): host = host.lower() if callable_attr(host, 'startswith') and host.startswith('xn--'): host = idna_decode(host) self._host = host
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1433-L1456
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ]
100
[]
0
true
96.258065
24
10
100
1
def host(self, host): # Invalid IPv6 literal. urllib.parse.urlsplit('http://%s/' % host) # Raises ValueError. # Invalid host string. resembles_ipv6_literal = ( host is not None and lget(host, 0) == '[' and ':' in host and lget(host, -1) == ']') if (host is not None and not resembles_ipv6_literal and not is_valid_host(host)): errmsg = ( "Invalid host '%s'. Host strings must have at least one " "non-period character, can't contain any of '%s', and can't " "have adjacent periods.") raise ValueError(errmsg % (host, INVALID_HOST_CHARS)) if callable_attr(host, 'lower'): host = host.lower() if callable_attr(host, 'startswith') and host.startswith('xn--'): host = idna_decode(host) self._host = host
28,207
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.port
(self)
return self._port or DEFAULT_PORTS.get(self.scheme)
1,459
1,460
def port(self): return self._port or DEFAULT_PORTS.get(self.scheme)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1459-L1460
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
2
100
0
def port(self): return self._port or DEFAULT_PORTS.get(self.scheme)
28,208
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.port
(self, port)
The port value can be 1-65535 or None, meaning no port specified. If <port> is None and self.scheme is a known scheme in DEFAULT_PORTS, the default port value from DEFAULT_PORTS will be used. Raises: ValueError on invalid port.
The port value can be 1-65535 or None, meaning no port specified. If <port> is None and self.scheme is a known scheme in DEFAULT_PORTS, the default port value from DEFAULT_PORTS will be used.
1,463
1,476
def port(self, port): """ The port value can be 1-65535 or None, meaning no port specified. If <port> is None and self.scheme is a known scheme in DEFAULT_PORTS, the default port value from DEFAULT_PORTS will be used. Raises: ValueError on invalid port. """ if port is None: self._port = DEFAULT_PORTS.get(self.scheme) elif is_valid_port(port): self._port = int(str(port)) else: raise ValueError("Invalid port '%s'." % port)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1463-L1476
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
96.258065
14
3
100
5
def port(self, port): if port is None: self._port = DEFAULT_PORTS.get(self.scheme) elif is_valid_port(port): self._port = int(str(port)) else: raise ValueError("Invalid port '%s'." % port)
28,209
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.netloc
(self)
return netloc
1,479
1,493
def netloc(self): userpass = quote(utf8(self.username) or '', safe='') if self.password is not None: userpass += ':' + quote(utf8(self.password), safe='') if userpass or self.username is not None: userpass += '@' netloc = idna_encode(self.host) if self.port and self.port != DEFAULT_PORTS.get(self.scheme): netloc = (netloc or '') + (':' + str(self.port)) if userpass or netloc: netloc = (userpass or '') + (netloc or '') return netloc
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1479-L1493
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]
100
[]
0
true
96.258065
15
12
100
0
def netloc(self): userpass = quote(utf8(self.username) or '', safe='') if self.password is not None: userpass += ':' + quote(utf8(self.password), safe='') if userpass or self.username is not None: userpass += '@' netloc = idna_encode(self.host) if self.port and self.port != DEFAULT_PORTS.get(self.scheme): netloc = (netloc or '') + (':' + str(self.port)) if userpass or netloc: netloc = (userpass or '') + (netloc or '') return netloc
28,210
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.netloc
(self, netloc)
Params: netloc: Network location string, like 'google.com' or 'user:pass@google.com:99'. Raises: ValueError on invalid port or malformed IPv6 address.
Params: netloc: Network location string, like 'google.com' or 'user:pass
1,496
1,537
def netloc(self, netloc): """ Params: netloc: Network location string, like 'google.com' or 'user:pass@google.com:99'. Raises: ValueError on invalid port or malformed IPv6 address. """ # Raises ValueError on malformed IPv6 addresses. urllib.parse.urlsplit('http://%s/' % netloc) username = password = host = port = None if netloc and '@' in netloc: userpass, netloc = netloc.split('@', 1) if ':' in userpass: username, password = userpass.split(':', 1) else: username = userpass if netloc and ':' in netloc: # IPv6 address literal. if ']' in netloc: colonpos, bracketpos = netloc.rfind(':'), netloc.rfind(']') if colonpos > bracketpos and colonpos != bracketpos + 1: raise ValueError("Invalid netloc '%s'." % netloc) elif colonpos > bracketpos and colonpos == bracketpos + 1: host, port = netloc.rsplit(':', 1) else: host = netloc else: host, port = netloc.rsplit(':', 1) host = host else: host = netloc # Avoid side effects by assigning self.port before self.host so # that if an exception is raised when assigning self.port, # self.host isn't updated. self.port = port # Raises ValueError on invalid port. self.host = host self.username = None if username is None else unquote(username) self.password = None if password is None else unquote(password)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1496-L1537
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41 ]
97.619048
[ 24 ]
2.380952
false
96.258065
42
11
97.619048
4
def netloc(self, netloc): # Raises ValueError on malformed IPv6 addresses. urllib.parse.urlsplit('http://%s/' % netloc) username = password = host = port = None if netloc and '@' in netloc: userpass, netloc = netloc.split('@', 1) if ':' in userpass: username, password = userpass.split(':', 1) else: username = userpass if netloc and ':' in netloc: # IPv6 address literal. if ']' in netloc: colonpos, bracketpos = netloc.rfind(':'), netloc.rfind(']') if colonpos > bracketpos and colonpos != bracketpos + 1: raise ValueError("Invalid netloc '%s'." % netloc) elif colonpos > bracketpos and colonpos == bracketpos + 1: host, port = netloc.rsplit(':', 1) else: host = netloc else: host, port = netloc.rsplit(':', 1) host = host else: host = netloc # Avoid side effects by assigning self.port before self.host so # that if an exception is raised when assigning self.port, # self.host isn't updated. self.port = port # Raises ValueError on invalid port. self.host = host self.username = None if username is None else unquote(username) self.password = None if password is None else unquote(password)
28,211
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.origin
(self)
return origin
1,540
1,548
def origin(self): port = '' scheme = self.scheme or '' host = idna_encode(self.host) or '' if self.port and self.port != DEFAULT_PORTS.get(self.scheme): port = ':%s' % self.port origin = '%s://%s%s' % (scheme, host, port) return origin
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1540-L1548
45
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
96.258065
9
5
100
0
def origin(self): port = '' scheme = self.scheme or '' host = idna_encode(self.host) or '' if self.port and self.port != DEFAULT_PORTS.get(self.scheme): port = ':%s' % self.port origin = '%s://%s%s' % (scheme, host, port) return origin
28,212
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.origin
(self, origin)
1,551
1,564
def origin(self, origin): if origin is None: self.scheme = self.netloc = None else: toks = origin.split('://', 1) if len(toks) == 1: host_port = origin else: self.scheme, host_port = toks if ':' in host_port: self.host, self.port = host_port.split(':', 1) else: self.host = host_port
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1551-L1564
45
[ 0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 13 ]
78.571429
[]
0
false
96.258065
14
4
100
0
def origin(self, origin): if origin is None: self.scheme = self.netloc = None else: toks = origin.split('://', 1) if len(toks) == 1: host_port = origin else: self.scheme, host_port = toks if ':' in host_port: self.host, self.port = host_port.split(':', 1) else: self.host = host_port
28,213
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.url
(self)
return self.tostr()
1,567
1,568
def url(self): return self.tostr()
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1567-L1568
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def url(self): return self.tostr()
28,214
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.url
(self, url)
return self.load(url)
1,571
1,572
def url(self, url): return self.load(url)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1571-L1572
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def url(self, url): return self.load(url)
28,215
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.add
(self, args=_absent, path=_absent, fragment_path=_absent, fragment_args=_absent, query_params=_absent)
return self
Add components to a URL and return this furl instance, <self>. If both <args> and <query_params> are provided, a UserWarning is raised because <args> is provided as a shortcut for <query_params>, not to be used simultaneously with <query_params>. Nonetheless, providing both <args> and <query_params> behaves as expected, with query keys and values from both <args> and <query_params> added to the query - <args> first, then <query_params>. Parameters: args: Shortcut for <query_params>. path: A list of path segments to add to the existing path segments, or a path string to join with the existing path string. query_params: A dictionary of query keys and values or list of key:value items to add to the query. fragment_path: A list of path segments to add to the existing fragment path segments, or a path string to join with the existing fragment path string. fragment_args: A dictionary of query keys and values or list of key:value items to add to the fragment's query. Returns: <self>. Raises: UserWarning if redundant and possibly conflicting <args> and <query_params> were provided.
Add components to a URL and return this furl instance, <self>.
1,574
1,621
def add(self, args=_absent, path=_absent, fragment_path=_absent, fragment_args=_absent, query_params=_absent): """ Add components to a URL and return this furl instance, <self>. If both <args> and <query_params> are provided, a UserWarning is raised because <args> is provided as a shortcut for <query_params>, not to be used simultaneously with <query_params>. Nonetheless, providing both <args> and <query_params> behaves as expected, with query keys and values from both <args> and <query_params> added to the query - <args> first, then <query_params>. Parameters: args: Shortcut for <query_params>. path: A list of path segments to add to the existing path segments, or a path string to join with the existing path string. query_params: A dictionary of query keys and values or list of key:value items to add to the query. fragment_path: A list of path segments to add to the existing fragment path segments, or a path string to join with the existing fragment path string. fragment_args: A dictionary of query keys and values or list of key:value items to add to the fragment's query. Returns: <self>. Raises: UserWarning if redundant and possibly conflicting <args> and <query_params> were provided. """ if args is not _absent and query_params is not _absent: s = ('Both <args> and <query_params> provided to furl.add(). ' '<args> is a shortcut for <query_params>, not to be used ' 'with <query_params>. See furl.add() documentation for more ' 'details.') warnings.warn(s, UserWarning) if path is not _absent: self.path.add(path) if args is not _absent: self.query.add(args) if query_params is not _absent: self.query.add(query_params) if fragment_path is not _absent or fragment_args is not _absent: self.fragment.add(path=fragment_path, args=fragment_args) return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1574-L1621
45
[ 0, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47 ]
39.583333
[]
0
false
96.258065
48
8
100
27
def add(self, args=_absent, path=_absent, fragment_path=_absent, fragment_args=_absent, query_params=_absent): if args is not _absent and query_params is not _absent: s = ('Both <args> and <query_params> provided to furl.add(). ' '<args> is a shortcut for <query_params>, not to be used ' 'with <query_params>. See furl.add() documentation for more ' 'details.') warnings.warn(s, UserWarning) if path is not _absent: self.path.add(path) if args is not _absent: self.query.add(args) if query_params is not _absent: self.query.add(query_params) if fragment_path is not _absent or fragment_args is not _absent: self.fragment.add(path=fragment_path, args=fragment_args) return self
28,216
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.set
(self, args=_absent, path=_absent, fragment=_absent, query=_absent, scheme=_absent, username=_absent, password=_absent, host=_absent, port=_absent, netloc=_absent, origin=_absent, query_params=_absent, fragment_path=_absent, fragment_args=_absent, fragment_separator=_absent)
return self
Set components of a url and return this furl instance, <self>. If any overlapping, and hence possibly conflicting, parameters are provided, appropriate UserWarning's will be raised. The groups of parameters that could potentially overlap are <scheme> and <origin> <origin>, <netloc>, and/or (<host> or <port>) <fragment> and (<fragment_path> and/or <fragment_args>) any two or all of <query>, <args>, and/or <query_params> In all of the above groups, the latter parameter(s) take precedence over the earlier parameter(s). So, for example furl('http://google.com/').set( netloc='yahoo.com:99', host='bing.com', port=40) will result in a UserWarning being raised and the url becoming 'http://bing.com:40/' not 'http://yahoo.com:99/ Parameters: args: Shortcut for <query_params>. path: A list of path segments or a path string to adopt. fragment: Fragment string to adopt. scheme: Scheme string to adopt. netloc: Network location string to adopt. origin: Scheme and netloc. query: Query string to adopt. query_params: A dictionary of query keys and values or list of key:value items to adopt. fragment_path: A list of path segments to adopt for the fragment's path or a path string to adopt as the fragment's path. fragment_args: A dictionary of query keys and values or list of key:value items for the fragment's query to adopt. fragment_separator: Boolean whether or not there should be a '?' separator between the fragment path and fragment query. host: Host string to adopt. port: Port number to adopt. username: Username string to adopt. password: Password string to adopt. Raises: ValueError on invalid port. UserWarning if <scheme> and <origin> are provided. UserWarning if <origin>, <netloc> and/or (<host> and/or <port>) are provided. UserWarning if <query>, <args>, and/or <query_params> are provided. UserWarning if <fragment> and (<fragment_path>, <fragment_args>, and/or <fragment_separator>) are provided. Returns: <self>.
Set components of a url and return this furl instance, <self>.
1,623
1,753
def set(self, args=_absent, path=_absent, fragment=_absent, query=_absent, scheme=_absent, username=_absent, password=_absent, host=_absent, port=_absent, netloc=_absent, origin=_absent, query_params=_absent, fragment_path=_absent, fragment_args=_absent, fragment_separator=_absent): """ Set components of a url and return this furl instance, <self>. If any overlapping, and hence possibly conflicting, parameters are provided, appropriate UserWarning's will be raised. The groups of parameters that could potentially overlap are <scheme> and <origin> <origin>, <netloc>, and/or (<host> or <port>) <fragment> and (<fragment_path> and/or <fragment_args>) any two or all of <query>, <args>, and/or <query_params> In all of the above groups, the latter parameter(s) take precedence over the earlier parameter(s). So, for example furl('http://google.com/').set( netloc='yahoo.com:99', host='bing.com', port=40) will result in a UserWarning being raised and the url becoming 'http://bing.com:40/' not 'http://yahoo.com:99/ Parameters: args: Shortcut for <query_params>. path: A list of path segments or a path string to adopt. fragment: Fragment string to adopt. scheme: Scheme string to adopt. netloc: Network location string to adopt. origin: Scheme and netloc. query: Query string to adopt. query_params: A dictionary of query keys and values or list of key:value items to adopt. fragment_path: A list of path segments to adopt for the fragment's path or a path string to adopt as the fragment's path. fragment_args: A dictionary of query keys and values or list of key:value items for the fragment's query to adopt. fragment_separator: Boolean whether or not there should be a '?' separator between the fragment path and fragment query. host: Host string to adopt. port: Port number to adopt. username: Username string to adopt. password: Password string to adopt. Raises: ValueError on invalid port. UserWarning if <scheme> and <origin> are provided. UserWarning if <origin>, <netloc> and/or (<host> and/or <port>) are provided. UserWarning if <query>, <args>, and/or <query_params> are provided. UserWarning if <fragment> and (<fragment_path>, <fragment_args>, and/or <fragment_separator>) are provided. Returns: <self>. """ def present(v): return v is not _absent if present(scheme) and present(origin): s = ('Possible parameter overlap: <scheme> and <origin>. See ' 'furl.set() documentation for more details.') warnings.warn(s, UserWarning) provided = [ present(netloc), present(origin), present(host) or present(port)] if sum(provided) >= 2: s = ('Possible parameter overlap: <origin>, <netloc> and/or ' '(<host> and/or <port>) provided. See furl.set() ' 'documentation for more details.') warnings.warn(s, UserWarning) if sum(present(p) for p in [args, query, query_params]) >= 2: s = ('Possible parameter overlap: <query>, <args>, and/or ' '<query_params> provided. See furl.set() documentation for ' 'more details.') warnings.warn(s, UserWarning) provided = [fragment_path, fragment_args, fragment_separator] if present(fragment) and any(present(p) for p in provided): s = ('Possible parameter overlap: <fragment> and ' '(<fragment_path>and/or <fragment_args>) or <fragment> ' 'and <fragment_separator> provided. See furl.set() ' 'documentation for more details.') warnings.warn(s, UserWarning) # Guard against side effects on exception. original_url = self.url try: if username is not _absent: self.username = username if password is not _absent: self.password = password if netloc is not _absent: # Raises ValueError on invalid port or malformed IP. self.netloc = netloc if origin is not _absent: # Raises ValueError on invalid port or malformed IP. self.origin = origin if scheme is not _absent: self.scheme = scheme if host is not _absent: # Raises ValueError on invalid host or malformed IP. self.host = host if port is not _absent: self.port = port # Raises ValueError on invalid port. if path is not _absent: self.path.load(path) if query is not _absent: self.query.load(query) if args is not _absent: self.query.load(args) if query_params is not _absent: self.query.load(query_params) if fragment is not _absent: self.fragment.load(fragment) if fragment_path is not _absent: self.fragment.path.load(fragment_path) if fragment_args is not _absent: self.fragment.query.load(fragment_args) if fragment_separator is not _absent: self.fragment.separator = fragment_separator except Exception: self.load(original_url) raise return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1623-L1753
45
[ 0, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130 ]
54.198473
[]
0
false
96.258065
131
25
100
55
def set(self, args=_absent, path=_absent, fragment=_absent, query=_absent, scheme=_absent, username=_absent, password=_absent, host=_absent, port=_absent, netloc=_absent, origin=_absent, query_params=_absent, fragment_path=_absent, fragment_args=_absent, fragment_separator=_absent): def present(v): return v is not _absent if present(scheme) and present(origin): s = ('Possible parameter overlap: <scheme> and <origin>. See ' 'furl.set() documentation for more details.') warnings.warn(s, UserWarning) provided = [ present(netloc), present(origin), present(host) or present(port)] if sum(provided) >= 2: s = ('Possible parameter overlap: <origin>, <netloc> and/or ' '(<host> and/or <port>) provided. See furl.set() ' 'documentation for more details.') warnings.warn(s, UserWarning) if sum(present(p) for p in [args, query, query_params]) >= 2: s = ('Possible parameter overlap: <query>, <args>, and/or ' '<query_params> provided. See furl.set() documentation for ' 'more details.') warnings.warn(s, UserWarning) provided = [fragment_path, fragment_args, fragment_separator] if present(fragment) and any(present(p) for p in provided): s = ('Possible parameter overlap: <fragment> and ' '(<fragment_path>and/or <fragment_args>) or <fragment> ' 'and <fragment_separator> provided. See furl.set() ' 'documentation for more details.') warnings.warn(s, UserWarning) # Guard against side effects on exception. original_url = self.url try: if username is not _absent: self.username = username if password is not _absent: self.password = password if netloc is not _absent: # Raises ValueError on invalid port or malformed IP. self.netloc = netloc if origin is not _absent: # Raises ValueError on invalid port or malformed IP. self.origin = origin if scheme is not _absent: self.scheme = scheme if host is not _absent: # Raises ValueError on invalid host or malformed IP. self.host = host if port is not _absent: self.port = port # Raises ValueError on invalid port. if path is not _absent: self.path.load(path) if query is not _absent: self.query.load(query) if args is not _absent: self.query.load(args) if query_params is not _absent: self.query.load(query_params) if fragment is not _absent: self.fragment.load(fragment) if fragment_path is not _absent: self.fragment.path.load(fragment_path) if fragment_args is not _absent: self.fragment.query.load(fragment_args) if fragment_separator is not _absent: self.fragment.separator = fragment_separator except Exception: self.load(original_url) raise return self
28,217
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.remove
(self, args=_absent, path=_absent, fragment=_absent, query=_absent, scheme=False, username=False, password=False, host=False, port=False, netloc=False, origin=False, query_params=_absent, fragment_path=_absent, fragment_args=_absent)
return self
Remove components of this furl's URL and return this furl instance, <self>. Parameters: args: Shortcut for query_params. path: A list of path segments to remove from the end of the existing path segments list, or a path string to remove from the end of the existing path string, or True to remove the path portion of the URL entirely. query: A list of query keys to remove from the query, if they exist, or True to remove the query portion of the URL entirely. query_params: A list of query keys to remove from the query, if they exist. port: If True, remove the port from the network location string, if it exists. fragment: If True, remove the fragment portion of the URL entirely. fragment_path: A list of path segments to remove from the end of the fragment's path segments or a path string to remove from the end of the fragment's path string. fragment_args: A list of query keys to remove from the fragment's query, if they exist. username: If True, remove the username, if it exists. password: If True, remove the password, if it exists. Returns: <self>.
Remove components of this furl's URL and return this furl instance, <self>.
1,755
1,820
def remove(self, args=_absent, path=_absent, fragment=_absent, query=_absent, scheme=False, username=False, password=False, host=False, port=False, netloc=False, origin=False, query_params=_absent, fragment_path=_absent, fragment_args=_absent): """ Remove components of this furl's URL and return this furl instance, <self>. Parameters: args: Shortcut for query_params. path: A list of path segments to remove from the end of the existing path segments list, or a path string to remove from the end of the existing path string, or True to remove the path portion of the URL entirely. query: A list of query keys to remove from the query, if they exist, or True to remove the query portion of the URL entirely. query_params: A list of query keys to remove from the query, if they exist. port: If True, remove the port from the network location string, if it exists. fragment: If True, remove the fragment portion of the URL entirely. fragment_path: A list of path segments to remove from the end of the fragment's path segments or a path string to remove from the end of the fragment's path string. fragment_args: A list of query keys to remove from the fragment's query, if they exist. username: If True, remove the username, if it exists. password: If True, remove the password, if it exists. Returns: <self>. """ if scheme is True: self.scheme = None if username is True: self.username = None if password is True: self.password = None if host is True: self.host = None if port is True: self.port = None if netloc is True: self.netloc = None if origin is True: self.origin = None if path is not _absent: self.path.remove(path) if args is not _absent: self.query.remove(args) if query is not _absent: self.query.remove(query) if query_params is not _absent: self.query.remove(query_params) if fragment is not _absent: self.fragment.remove(fragment) if fragment_path is not _absent: self.fragment.path.remove(fragment_path) if fragment_args is not _absent: self.fragment.query.remove(fragment_args) return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1755-L1820
45
[ 0, 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 ]
53.030303
[]
0
false
96.258065
66
15
100
26
def remove(self, args=_absent, path=_absent, fragment=_absent, query=_absent, scheme=False, username=False, password=False, host=False, port=False, netloc=False, origin=False, query_params=_absent, fragment_path=_absent, fragment_args=_absent): if scheme is True: self.scheme = None if username is True: self.username = None if password is True: self.password = None if host is True: self.host = None if port is True: self.port = None if netloc is True: self.netloc = None if origin is True: self.origin = None if path is not _absent: self.path.remove(path) if args is not _absent: self.query.remove(args) if query is not _absent: self.query.remove(query) if query_params is not _absent: self.query.remove(query_params) if fragment is not _absent: self.fragment.remove(fragment) if fragment_path is not _absent: self.fragment.path.remove(fragment_path) if fragment_args is not _absent: self.fragment.query.remove(fragment_args) return self
28,218
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.tostr
(self, query_delimiter='&', query_quote_plus=True, query_dont_quote='')
return str(url)
1,822
1,844
def tostr(self, query_delimiter='&', query_quote_plus=True, query_dont_quote=''): encoded_query = self.query.encode( query_delimiter, query_quote_plus, query_dont_quote) url = urllib.parse.urlunsplit(( self.scheme or '', # Must be text type in Python 3. self.netloc, str(self.path), encoded_query, str(self.fragment), )) # Differentiate between '' and None values for scheme and netloc. if self.scheme == '': url = ':' + url if self.netloc == '': if self.scheme is None: url = '//' + url elif strip_scheme(url) == '': url = url + '//' return str(url)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1822-L1844
45
[ 0, 2, 4, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 ]
60.869565
[]
0
false
96.258065
23
6
100
0
def tostr(self, query_delimiter='&', query_quote_plus=True, query_dont_quote=''): encoded_query = self.query.encode( query_delimiter, query_quote_plus, query_dont_quote) url = urllib.parse.urlunsplit(( self.scheme or '', # Must be text type in Python 3. self.netloc, str(self.path), encoded_query, str(self.fragment), )) # Differentiate between '' and None values for scheme and netloc. if self.scheme == '': url = ':' + url if self.netloc == '': if self.scheme is None: url = '//' + url elif strip_scheme(url) == '': url = url + '//' return str(url)
28,219
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.join
(self, *urls)
return self
1,846
1,852
def join(self, *urls): for url in urls: if not isinstance(url, six.string_types): url = str(url) newurl = urljoin(self.url, url) self.load(newurl) return self
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1846-L1852
45
[ 0, 1, 2, 3, 4, 5, 6 ]
100
[]
0
true
96.258065
7
3
100
0
def join(self, *urls): for url in urls: if not isinstance(url, six.string_types): url = str(url) newurl = urljoin(self.url, url) self.load(newurl) return self
28,220
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.copy
(self)
return self.__class__(self)
1,854
1,855
def copy(self): return self.__class__(self)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1854-L1855
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def copy(self): return self.__class__(self)
28,221
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.asdict
(self)
return { 'url': self.url, 'scheme': self.scheme, 'username': self.username, 'password': self.password, 'host': self.host, 'host_encoded': idna_encode(self.host), 'port': self.port, 'netloc': self.netloc, 'origin': self.origin, 'path': self.path.asdict(), 'query': self.query.asdict(), 'fragment': self.fragment.asdict(), }
1,857
1,871
def asdict(self): return { 'url': self.url, 'scheme': self.scheme, 'username': self.username, 'password': self.password, 'host': self.host, 'host_encoded': idna_encode(self.host), 'port': self.port, 'netloc': self.netloc, 'origin': self.origin, 'path': self.path.asdict(), 'query': self.query.asdict(), 'fragment': self.fragment.asdict(), }
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1857-L1871
45
[ 0, 1 ]
13.333333
[]
0
false
96.258065
15
1
100
0
def asdict(self): return { 'url': self.url, 'scheme': self.scheme, 'username': self.username, 'password': self.password, 'host': self.host, 'host_encoded': idna_encode(self.host), 'port': self.port, 'netloc': self.netloc, 'origin': self.origin, 'path': self.path.asdict(), 'query': self.query.asdict(), 'fragment': self.fragment.asdict(), }
28,222
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.__truediv__
(self, path)
return self.copy().add(path=path)
1,873
1,874
def __truediv__(self, path): return self.copy().add(path=path)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1873-L1874
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __truediv__(self, path): return self.copy().add(path=path)
28,223
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.__eq__
(self, other)
1,876
1,880
def __eq__(self, other): try: return self.url == other.url except AttributeError: return None
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1876-L1880
45
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
96.258065
5
2
100
0
def __eq__(self, other): try: return self.url == other.url except AttributeError: return None
28,224
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.__ne__
(self, other)
return not self == other
1,882
1,883
def __ne__(self, other): return not self == other
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1882-L1883
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __ne__(self, other): return not self == other
28,225
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.__setattr__
(self, attr, value)
1,885
1,889
def __setattr__(self, attr, value): if (not PathCompositionInterface.__setattr__(self, attr, value) and not QueryCompositionInterface.__setattr__(self, attr, value) and not FragmentCompositionInterface.__setattr__(self, attr, value)): object.__setattr__(self, attr, value)
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1885-L1889
45
[ 0, 1, 4 ]
60
[]
0
false
96.258065
5
4
100
0
def __setattr__(self, attr, value): if (not PathCompositionInterface.__setattr__(self, attr, value) and not QueryCompositionInterface.__setattr__(self, attr, value) and not FragmentCompositionInterface.__setattr__(self, attr, value)): object.__setattr__(self, attr, value)
28,226
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.__unicode__
(self)
return self.tostr()
1,891
1,892
def __unicode__(self): return self.tostr()
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1891-L1892
45
[ 0, 1 ]
100
[]
0
true
96.258065
2
1
100
0
def __unicode__(self): return self.tostr()
28,227
gruns/furl
774846234ff803606fdd289a7549f9b50b2b3677
furl/furl.py
furl.__repr__
(self)
return "%s('%s')" % (self.__class__.__name__, str(self))
1,894
1,895
def __repr__(self): return "%s('%s')" % (self.__class__.__name__, str(self))
https://github.com/gruns/furl/blob/774846234ff803606fdd289a7549f9b50b2b3677/project45/furl/furl.py#L1894-L1895
45
[ 0 ]
50
[ 1 ]
50
false
96.258065
2
1
50
0
def __repr__(self): return "%s('%s')" % (self.__class__.__name__, str(self))
28,228
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/tools.py
cross_platform_popen_params
(popen_params)
return popen_params
Wrap with this function a dictionary of ``subprocess.Popen`` kwargs and will be ready to work without unexpected behaviours in any platform. Currently, the implementation will add to them: - ``creationflags=0x08000000``: no extra unwanted window opens on Windows when the child process is created. Only added on Windows.
Wrap with this function a dictionary of ``subprocess.Popen`` kwargs and will be ready to work without unexpected behaviours in any platform. Currently, the implementation will add to them:
12
22
def cross_platform_popen_params(popen_params): """Wrap with this function a dictionary of ``subprocess.Popen`` kwargs and will be ready to work without unexpected behaviours in any platform. Currently, the implementation will add to them: - ``creationflags=0x08000000``: no extra unwanted window opens on Windows when the child process is created. Only added on Windows. """ if OS_NAME == "nt": popen_params["creationflags"] = 0x08000000 return popen_params
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/tools.py#L12-L22
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
100
11
2
100
6
def cross_platform_popen_params(popen_params): if OS_NAME == "nt": popen_params["creationflags"] = 0x08000000 return popen_params
28,333
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/tools.py
subprocess_call
(cmd, logger="bar")
Executes the given subprocess command. Set logger to None or a custom Proglog logger to avoid printings.
Executes the given subprocess command.
25
48
def subprocess_call(cmd, logger="bar"): """Executes the given subprocess command. Set logger to None or a custom Proglog logger to avoid printings. """ logger = proglog.default_bar_logger(logger) logger(message="Moviepy - Running:\n>>> " + " ".join(cmd)) popen_params = cross_platform_popen_params( {"stdout": sp.DEVNULL, "stderr": sp.PIPE, "stdin": sp.DEVNULL} ) proc = sp.Popen(cmd, **popen_params) out, err = proc.communicate() # proc.wait() proc.stderr.close() if proc.returncode: logger(message="Moviepy - Command returned an error") raise IOError(err.decode("utf8")) else: logger(message="Moviepy - Command successful") del proc
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/tools.py#L25-L48
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ]
100
[]
0
true
100
24
2
100
3
def subprocess_call(cmd, logger="bar"): logger = proglog.default_bar_logger(logger) logger(message="Moviepy - Running:\n>>> " + " ".join(cmd)) popen_params = cross_platform_popen_params( {"stdout": sp.DEVNULL, "stderr": sp.PIPE, "stdin": sp.DEVNULL} ) proc = sp.Popen(cmd, **popen_params) out, err = proc.communicate() # proc.wait() proc.stderr.close() if proc.returncode: logger(message="Moviepy - Command returned an error") raise IOError(err.decode("utf8")) else: logger(message="Moviepy - Command successful") del proc
28,334
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/tools.py
convert_to_seconds
(time)
return sum(mult * part for mult, part in zip(factors, reversed(time)))
Will convert any time into seconds. If the type of `time` is not valid, it's returned as is. Here are the accepted formats: >>> convert_to_seconds(15.4) # seconds 15.4 >>> convert_to_seconds((1, 21.5)) # (min,sec) 81.5 >>> convert_to_seconds((1, 1, 2)) # (hr, min, sec) 3662 >>> convert_to_seconds('01:01:33.045') 3693.045 >>> convert_to_seconds('01:01:33,5') # coma works too 3693.5 >>> convert_to_seconds('1:33,5') # only minutes and secs 99.5 >>> convert_to_seconds('33.5') # only secs 33.5
Will convert any time into seconds.
51
82
def convert_to_seconds(time): """Will convert any time into seconds. If the type of `time` is not valid, it's returned as is. Here are the accepted formats: >>> convert_to_seconds(15.4) # seconds 15.4 >>> convert_to_seconds((1, 21.5)) # (min,sec) 81.5 >>> convert_to_seconds((1, 1, 2)) # (hr, min, sec) 3662 >>> convert_to_seconds('01:01:33.045') 3693.045 >>> convert_to_seconds('01:01:33,5') # coma works too 3693.5 >>> convert_to_seconds('1:33,5') # only minutes and secs 99.5 >>> convert_to_seconds('33.5') # only secs 33.5 """ factors = (1, 60, 3600) if isinstance(time, str): time = [float(part.replace(",", ".")) for part in time.split(":")] if not isinstance(time, (tuple, list)): return time return sum(mult * part for mult, part in zip(factors, reversed(time)))
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/tools.py#L51-L82
46
[ 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 ]
100
[]
0
true
100
32
4
100
21
def convert_to_seconds(time): factors = (1, 60, 3600) if isinstance(time, str): time = [float(part.replace(",", ".")) for part in time.split(":")] if not isinstance(time, (tuple, list)): return time return sum(mult * part for mult, part in zip(factors, reversed(time)))
28,335
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/tools.py
deprecated_version_of
(func, old_name)
return deprecated_func
Indicates that a function is deprecated and has a new name. `func` is the new function and `old_name` is the name of the deprecated function. Returns ------- deprecated_func A function that does the same thing as `func`, but with a docstring and a printed message on call which say that the function is deprecated and that you should use `func` instead. Examples -------- >>> # The badly named method 'to_file' is replaced by 'write_file' >>> class Clip: >>> def write_file(self, some args): >>> # blablabla >>> >>> Clip.to_file = deprecated_version_of(Clip.write_file, 'to_file')
Indicates that a function is deprecated and has a new name.
85
124
def deprecated_version_of(func, old_name): """Indicates that a function is deprecated and has a new name. `func` is the new function and `old_name` is the name of the deprecated function. Returns ------- deprecated_func A function that does the same thing as `func`, but with a docstring and a printed message on call which say that the function is deprecated and that you should use `func` instead. Examples -------- >>> # The badly named method 'to_file' is replaced by 'write_file' >>> class Clip: >>> def write_file(self, some args): >>> # blablabla >>> >>> Clip.to_file = deprecated_version_of(Clip.write_file, 'to_file') """ # Detect new name of func new_name = func.__name__ warning = ( "The function ``%s`` is deprecated and is kept temporarily " "for backwards compatibility.\nPlease use the new name, " "``%s``, instead." ) % (old_name, new_name) def deprecated_func(*args, **kwargs): warnings.warn("MoviePy: " + warning, PendingDeprecationWarning) return func(*args, **kwargs) deprecated_func.__doc__ = warning return deprecated_func
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/tools.py#L85-L124
46
[ 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 ]
100
[]
0
true
100
40
2
100
22
def deprecated_version_of(func, old_name): # Detect new name of func new_name = func.__name__ warning = ( "The function ``%s`` is deprecated and is kept temporarily " "for backwards compatibility.\nPlease use the new name, " "``%s``, instead." ) % (old_name, new_name) def deprecated_func(*args, **kwargs): warnings.warn("MoviePy: " + warning, PendingDeprecationWarning) return func(*args, **kwargs) deprecated_func.__doc__ = warning return deprecated_func
28,336
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/tools.py
find_extension
(codec)
Returns the correspondent file extension for a codec. Parameters ---------- codec : str Video or audio codec name.
Returns the correspondent file extension for a codec.
149
170
def find_extension(codec): """Returns the correspondent file extension for a codec. Parameters ---------- codec : str Video or audio codec name. """ if codec in extensions_dict: # codec is already the extension return codec for ext, infos in extensions_dict.items(): if codec in infos.get("codec", []): return ext raise ValueError( "The audio_codec you chose is unknown by MoviePy. " "You should report this. In the meantime, you can " "specify a temp_audiofile with the right extension " "in write_videofile." )
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/tools.py#L149-L170
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
100
[]
0
true
100
22
4
100
7
def find_extension(codec): if codec in extensions_dict: # codec is already the extension return codec for ext, infos in extensions_dict.items(): if codec in infos.get("codec", []): return ext raise ValueError( "The audio_codec you chose is unknown by MoviePy. " "You should report this. In the meantime, you can " "specify a temp_audiofile with the right extension " "in write_videofile." )
28,337
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/utils.py
close_all_clips
(objects="globals", types=("audio", "video", "image"))
Closes all clips in a context. Follows different strategies retrieving the namespace from which the clips to close will be retrieved depending on the ``objects`` argument, and filtering by type of clips depending on the ``types`` argument. Parameters ---------- objects : str or dict, optional - If is a string an the value is ``"globals"``, will close all the clips contained by the ``globals()`` namespace. - If is a dictionary, the values of the dictionary could be clips to close, useful if you want to use ``locals()``. types : Iterable, optional Set of types of clips to close, being "audio", "video" or "image" the supported values.
Closes all clips in a context.
15
42
def close_all_clips(objects="globals", types=("audio", "video", "image")): """Closes all clips in a context. Follows different strategies retrieving the namespace from which the clips to close will be retrieved depending on the ``objects`` argument, and filtering by type of clips depending on the ``types`` argument. Parameters ---------- objects : str or dict, optional - If is a string an the value is ``"globals"``, will close all the clips contained by the ``globals()`` namespace. - If is a dictionary, the values of the dictionary could be clips to close, useful if you want to use ``locals()``. types : Iterable, optional Set of types of clips to close, being "audio", "video" or "image" the supported values. """ if objects == "globals": # pragma: no cover objects = globals() if hasattr(objects, "values"): objects = objects.values() types_tuple = tuple(CLIP_TYPES[key] for key in types) for obj in objects: if isinstance(obj, types_tuple): obj.close()
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/utils.py#L15-L42
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
84.615385
[ 22, 23, 24, 25, 26, 27 ]
23.076923
false
45.454545
28
5
76.923077
18
def close_all_clips(objects="globals", types=("audio", "video", "image")): if objects == "globals": # pragma: no cover objects = globals() if hasattr(objects, "values"): objects = objects.values() types_tuple = tuple(CLIP_TYPES[key] for key in types) for obj in objects: if isinstance(obj, types_tuple): obj.close()
28,338
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
outplace
(func, clip, *args, **kwargs)
return new_clip
Applies ``func(clip.copy(), *args, **kwargs)`` and returns ``clip.copy()``.
Applies ``func(clip.copy(), *args, **kwargs)`` and returns ``clip.copy()``.
11
15
def outplace(func, clip, *args, **kwargs): """Applies ``func(clip.copy(), *args, **kwargs)`` and returns ``clip.copy()``.""" new_clip = clip.copy() func(new_clip, *args, **kwargs) return new_clip
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L11-L15
46
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
97.222222
5
1
100
1
def outplace(func, clip, *args, **kwargs): new_clip = clip.copy() func(new_clip, *args, **kwargs) return new_clip
28,339
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
convert_masks_to_RGB
(func, clip, *args, **kwargs)
return func(clip, *args, **kwargs)
If the clip is a mask, convert it to RGB before running the function.
If the clip is a mask, convert it to RGB before running the function.
19
23
def convert_masks_to_RGB(func, clip, *args, **kwargs): """If the clip is a mask, convert it to RGB before running the function.""" if clip.is_mask: clip = clip.to_RGB() return func(clip, *args, **kwargs)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L19-L23
46
[ 0, 1, 2, 4 ]
80
[ 3 ]
20
false
97.222222
5
2
80
1
def convert_masks_to_RGB(func, clip, *args, **kwargs): if clip.is_mask: clip = clip.to_RGB() return func(clip, *args, **kwargs)
28,340
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
apply_to_mask
(func, clip, *args, **kwargs)
return new_clip
Applies the same function ``func`` to the mask of the clip created with ``func``.
Applies the same function ``func`` to the mask of the clip created with ``func``.
27
34
def apply_to_mask(func, clip, *args, **kwargs): """Applies the same function ``func`` to the mask of the clip created with ``func``. """ new_clip = func(clip, *args, **kwargs) if getattr(new_clip, "mask", None): new_clip.mask = func(new_clip.mask, *args, **kwargs) return new_clip
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L27-L34
46
[ 0, 1, 2, 3, 4, 5, 6, 7 ]
100
[]
0
true
97.222222
8
2
100
2
def apply_to_mask(func, clip, *args, **kwargs): new_clip = func(clip, *args, **kwargs) if getattr(new_clip, "mask", None): new_clip.mask = func(new_clip.mask, *args, **kwargs) return new_clip
28,341
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
apply_to_audio
(func, clip, *args, **kwargs)
return new_clip
Applies the function ``func`` to the audio of the clip created with ``func``.
Applies the function ``func`` to the audio of the clip created with ``func``.
38
43
def apply_to_audio(func, clip, *args, **kwargs): """Applies the function ``func`` to the audio of the clip created with ``func``.""" new_clip = func(clip, *args, **kwargs) if getattr(new_clip, "audio", None): new_clip.audio = func(new_clip.audio, *args, **kwargs) return new_clip
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L38-L43
46
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
97.222222
6
2
100
1
def apply_to_audio(func, clip, *args, **kwargs): new_clip = func(clip, *args, **kwargs) if getattr(new_clip, "audio", None): new_clip.audio = func(new_clip.audio, *args, **kwargs) return new_clip
28,342
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
requires_duration
(func, clip, *args, **kwargs)
Raises an error if the clip has no duration.
Raises an error if the clip has no duration.
47
52
def requires_duration(func, clip, *args, **kwargs): """Raises an error if the clip has no duration.""" if clip.duration is None: raise ValueError("Attribute 'duration' not set") else: return func(clip, *args, **kwargs)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L47-L52
46
[ 0, 1, 2, 3, 4, 5 ]
100
[]
0
true
97.222222
6
2
100
1
def requires_duration(func, clip, *args, **kwargs): if clip.duration is None: raise ValueError("Attribute 'duration' not set") else: return func(clip, *args, **kwargs)
28,343
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
requires_fps
(func, clip, *args, **kwargs)
Raises an error if the clip has no fps.
Raises an error if the clip has no fps.
56
61
def requires_fps(func, clip, *args, **kwargs): """Raises an error if the clip has no fps.""" if not hasattr(clip, "fps") or clip.fps is None: raise ValueError("Attribute 'fps' not set") else: return func(clip, *args, **kwargs)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L56-L61
46
[ 0, 1, 2, 4, 5 ]
83.333333
[ 3 ]
16.666667
false
97.222222
6
3
83.333333
1
def requires_fps(func, clip, *args, **kwargs): if not hasattr(clip, "fps") or clip.fps is None: raise ValueError("Attribute 'fps' not set") else: return func(clip, *args, **kwargs)
28,344
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
audio_video_fx
(func, clip, *args, **kwargs)
Use an audio function on a video/audio clip. This decorator tells that the function func (audioclip -> audioclip) can be also used on a video clip, at which case it returns a videoclip with unmodified video and modified audio.
Use an audio function on a video/audio clip.
65
78
def audio_video_fx(func, clip, *args, **kwargs): """Use an audio function on a video/audio clip. This decorator tells that the function func (audioclip -> audioclip) can be also used on a video clip, at which case it returns a videoclip with unmodified video and modified audio. """ if hasattr(clip, "audio"): new_clip = clip.copy() if clip.audio is not None: new_clip.audio = func(clip.audio, *args, **kwargs) return new_clip else: return func(clip, *args, **kwargs)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L65-L78
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]
100
[]
0
true
97.222222
14
3
100
5
def audio_video_fx(func, clip, *args, **kwargs): if hasattr(clip, "audio"): new_clip = clip.copy() if clip.audio is not None: new_clip.audio = func(clip.audio, *args, **kwargs) return new_clip else: return func(clip, *args, **kwargs)
28,345
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
preprocess_args
(fun, varnames)
return decorator.decorator(wrapper)
Applies fun to variables in varnames before launching the function.
Applies fun to variables in varnames before launching the function.
81
96
def preprocess_args(fun, varnames): """Applies fun to variables in varnames before launching the function.""" def wrapper(func, *args, **kwargs): names = inspect.getfullargspec(func).args new_args = [ fun(arg) if (name in varnames) and (arg is not None) else arg for (arg, name) in zip(args, names) ] new_kwargs = { kwarg: fun(value) if kwarg in varnames else value for (kwarg, value) in kwargs.items() } return func(*new_args, **new_kwargs) return decorator.decorator(wrapper)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L81-L96
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
100
[]
0
true
97.222222
16
4
100
1
def preprocess_args(fun, varnames): def wrapper(func, *args, **kwargs): names = inspect.getfullargspec(func).args new_args = [ fun(arg) if (name in varnames) and (arg is not None) else arg for (arg, name) in zip(args, names) ] new_kwargs = { kwarg: fun(value) if kwarg in varnames else value for (kwarg, value) in kwargs.items() } return func(*new_args, **new_kwargs) return decorator.decorator(wrapper)
28,346
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
convert_parameter_to_seconds
(varnames)
return preprocess_args(convert_to_seconds, varnames)
Converts the specified variables to seconds.
Converts the specified variables to seconds.
99
101
def convert_parameter_to_seconds(varnames): """Converts the specified variables to seconds.""" return preprocess_args(convert_to_seconds, varnames)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L99-L101
46
[ 0, 1, 2 ]
100
[]
0
true
97.222222
3
1
100
1
def convert_parameter_to_seconds(varnames): return preprocess_args(convert_to_seconds, varnames)
28,347
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
convert_path_to_string
(varnames)
return preprocess_args(os.fspath, varnames)
Converts the specified variables to a path string.
Converts the specified variables to a path string.
104
106
def convert_path_to_string(varnames): """Converts the specified variables to a path string.""" return preprocess_args(os.fspath, varnames)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L104-L106
46
[ 0, 1, 2 ]
100
[]
0
true
97.222222
3
1
100
1
def convert_path_to_string(varnames): return preprocess_args(os.fspath, varnames)
28,348
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
add_mask_if_none
(func, clip, *args, **kwargs)
return func(clip, *args, **kwargs)
Add a mask to the clip if there is none.
Add a mask to the clip if there is none.
110
114
def add_mask_if_none(func, clip, *args, **kwargs): """Add a mask to the clip if there is none.""" if clip.mask is None: clip = clip.add_mask() return func(clip, *args, **kwargs)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L110-L114
46
[ 0, 1, 2, 3, 4 ]
100
[]
0
true
97.222222
5
2
100
1
def add_mask_if_none(func, clip, *args, **kwargs): if clip.mask is None: clip = clip.add_mask() return func(clip, *args, **kwargs)
28,349
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/decorators.py
use_clip_fps_by_default
(func, clip, *args, **kwargs)
return func(clip, *new_args, **new_kwargs)
Will use ``clip.fps`` if no ``fps=...`` is provided in **kwargs**.
Will use ``clip.fps`` if no ``fps=...`` is provided in **kwargs**.
118
143
def use_clip_fps_by_default(func, clip, *args, **kwargs): """Will use ``clip.fps`` if no ``fps=...`` is provided in **kwargs**.""" def find_fps(fps): if fps is not None: return fps elif getattr(clip, "fps", None): return clip.fps raise AttributeError( "No 'fps' (frames per second) attribute specified" " for function %s and the clip has no 'fps' attribute. Either" " provide e.g. fps=24 in the arguments of the function, or define" " the clip's fps with `clip.fps=24`" % func.__name__ ) names = inspect.getfullargspec(func).args[1:] new_args = [ find_fps(arg) if (name == "fps") else arg for (arg, name) in zip(args, names) ] new_kwargs = { kwarg: find_fps(value) if kwarg == "fps" else value for (kwarg, value) in kwargs.items() } return func(clip, *new_args, **new_kwargs)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/decorators.py#L118-L143
46
[ 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 ]
100
[]
0
true
97.222222
26
5
100
1
def use_clip_fps_by_default(func, clip, *args, **kwargs): def find_fps(fps): if fps is not None: return fps elif getattr(clip, "fps", None): return clip.fps raise AttributeError( "No 'fps' (frames per second) attribute specified" " for function %s and the clip has no 'fps' attribute. Either" " provide e.g. fps=24 in the arguments of the function, or define" " the clip's fps with `clip.fps=24`" % func.__name__ ) names = inspect.getfullargspec(func).args[1:] new_args = [ find_fps(arg) if (name == "fps") else arg for (arg, name) in zip(args, names) ] new_kwargs = { kwarg: find_fps(value) if kwarg == "fps" else value for (kwarg, value) in kwargs.items() } return func(clip, *new_args, **new_kwargs)
28,350
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/__init__.py
preview
(self, *args, **kwargs)
NOT AVAILABLE: clip.preview requires importing from moviepy.editor
NOT AVAILABLE: clip.preview requires importing from moviepy.editor
55
57
def preview(self, *args, **kwargs): """NOT AVAILABLE: clip.preview requires importing from moviepy.editor""" raise ImportError("clip.preview requires importing from moviepy.editor")
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/__init__.py#L55-L57
46
[ 0, 1, 2 ]
100
[]
0
true
100
3
1
100
1
def preview(self, *args, **kwargs): raise ImportError("clip.preview requires importing from moviepy.editor")
28,351
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/__init__.py
show
(self, *args, **kwargs)
NOT AVAILABLE: clip.show requires importing from moviepy.editor
NOT AVAILABLE: clip.show requires importing from moviepy.editor
60
62
def show(self, *args, **kwargs): """NOT AVAILABLE: clip.show requires importing from moviepy.editor""" raise ImportError("clip.show requires importing from moviepy.editor")
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/__init__.py#L60-L62
46
[ 0, 1, 2 ]
100
[]
0
true
100
3
1
100
1
def show(self, *args, **kwargs): raise ImportError("clip.show requires importing from moviepy.editor")
28,352
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.__init__
(self)
45
53
def __init__(self): self.start = 0 self.end = None self.duration = None self.memoize = False self.memoized_t = None self.memoized_frame = None
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L45-L53
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]
100
[]
0
true
100
9
1
100
0
def __init__(self): self.start = 0 self.end = None self.duration = None self.memoize = False self.memoized_t = None self.memoized_frame = None
28,353
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.copy
(self)
return _copy.copy(self)
Allows the usage of ``.copy()`` in clips as chained methods invocation.
Allows the usage of ``.copy()`` in clips as chained methods invocation.
55
57
def copy(self): """Allows the usage of ``.copy()`` in clips as chained methods invocation.""" return _copy.copy(self)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L55-L57
46
[ 0, 1, 2 ]
100
[]
0
true
100
3
1
100
1
def copy(self): return _copy.copy(self)
28,354
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.get_frame
(self, t)
Gets a numpy array representing the RGB picture of the clip, or (mono or stereo) value for a sound clip, at time ``t``. Parameters ---------- t : float or tuple or str Moment of the clip whose frame will be returned.
Gets a numpy array representing the RGB picture of the clip, or (mono or stereo) value for a sound clip, at time ``t``.
60
81
def get_frame(self, t): """Gets a numpy array representing the RGB picture of the clip, or (mono or stereo) value for a sound clip, at time ``t``. Parameters ---------- t : float or tuple or str Moment of the clip whose frame will be returned. """ # Coming soon: smart error handling for debugging at this point if self.memoize: if t == self.memoized_t: return self.memoized_frame else: frame = self.make_frame(t) self.memoized_t = t self.memoized_frame = frame return frame else: # print(t) return self.make_frame(t)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L60-L81
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 ]
100
[]
0
true
100
22
3
100
8
def get_frame(self, t): # Coming soon: smart error handling for debugging at this point if self.memoize: if t == self.memoized_t: return self.memoized_frame else: frame = self.make_frame(t) self.memoized_t = t self.memoized_frame = frame return frame else: # print(t) return self.make_frame(t)
28,355
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.transform
(self, func, apply_to=None, keep_duration=True)
return new_clip
General processing of a clip. Returns a new Clip whose frames are a transformation (through function ``func``) of the frames of the current clip. Parameters ---------- func : function A function with signature (gf,t -> frame) where ``gf`` will represent the current clip's ``get_frame`` method, i.e. ``gf`` is a function (t->image). Parameter `t` is a time in seconds, `frame` is a picture (=Numpy array) which will be returned by the transformed clip (see examples below). apply_to : {"mask", "audio", ["mask", "audio"]}, optional Can be either ``'mask'``, or ``'audio'``, or ``['mask','audio']``. Specifies if the filter should also be applied to the audio or the mask of the clip, if any. keep_duration : bool, optional Set to True if the transformation does not change the ``duration`` of the clip. Examples -------- In the following ``new_clip`` a 100 pixels-high clip whose video content scrolls from the top to the bottom of the frames of ``clip`` at 50 pixels per second. >>> filter = lambda get_frame,t : get_frame(t)[int(t):int(t)+50, :] >>> new_clip = clip.transform(filter, apply_to='mask')
General processing of a clip.
83
141
def transform(self, func, apply_to=None, keep_duration=True): """General processing of a clip. Returns a new Clip whose frames are a transformation (through function ``func``) of the frames of the current clip. Parameters ---------- func : function A function with signature (gf,t -> frame) where ``gf`` will represent the current clip's ``get_frame`` method, i.e. ``gf`` is a function (t->image). Parameter `t` is a time in seconds, `frame` is a picture (=Numpy array) which will be returned by the transformed clip (see examples below). apply_to : {"mask", "audio", ["mask", "audio"]}, optional Can be either ``'mask'``, or ``'audio'``, or ``['mask','audio']``. Specifies if the filter should also be applied to the audio or the mask of the clip, if any. keep_duration : bool, optional Set to True if the transformation does not change the ``duration`` of the clip. Examples -------- In the following ``new_clip`` a 100 pixels-high clip whose video content scrolls from the top to the bottom of the frames of ``clip`` at 50 pixels per second. >>> filter = lambda get_frame,t : get_frame(t)[int(t):int(t)+50, :] >>> new_clip = clip.transform(filter, apply_to='mask') """ if apply_to is None: apply_to = [] # mf = copy(self.make_frame) new_clip = self.with_make_frame(lambda t: func(self.get_frame, t)) if not keep_duration: new_clip.duration = None new_clip.end = None if isinstance(apply_to, str): apply_to = [apply_to] for attribute in apply_to: attribute_value = getattr(new_clip, attribute, None) if attribute_value is not None: new_attribute_value = attribute_value.transform( func, keep_duration=keep_duration ) setattr(new_clip, attribute, new_attribute_value) return new_clip
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L83-L141
46
[ 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 ]
100
[]
0
true
100
59
6
100
34
def transform(self, func, apply_to=None, keep_duration=True): if apply_to is None: apply_to = [] # mf = copy(self.make_frame) new_clip = self.with_make_frame(lambda t: func(self.get_frame, t)) if not keep_duration: new_clip.duration = None new_clip.end = None if isinstance(apply_to, str): apply_to = [apply_to] for attribute in apply_to: attribute_value = getattr(new_clip, attribute, None) if attribute_value is not None: new_attribute_value = attribute_value.transform( func, keep_duration=keep_duration ) setattr(new_clip, attribute, new_attribute_value) return new_clip
28,356
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.time_transform
(self, time_func, apply_to=None, keep_duration=False)
return self.transform( lambda get_frame, t: get_frame(time_func(t)), apply_to, keep_duration=keep_duration, )
Returns a Clip instance playing the content of the current clip but with a modified timeline, time ``t`` being replaced by another time `time_func(t)`. Parameters ---------- time_func : function A function ``t -> new_t``. apply_to : {"mask", "audio", ["mask", "audio"]}, optional Can be either 'mask', or 'audio', or ['mask','audio']. Specifies if the filter ``transform`` should also be applied to the audio or the mask of the clip, if any. keep_duration : bool, optional ``False`` (default) if the transformation modifies the ``duration`` of the clip. Examples -------- >>> # plays the clip (and its mask and sound) twice faster >>> new_clip = clip.time_transform(lambda t: 2*t, apply_to=['mask', 'audio']) >>> >>> # plays the clip starting at t=3, and backwards: >>> new_clip = clip.time_transform(lambda t: 3-t)
Returns a Clip instance playing the content of the current clip but with a modified timeline, time ``t`` being replaced by another time `time_func(t)`.
143
181
def time_transform(self, time_func, apply_to=None, keep_duration=False): """ Returns a Clip instance playing the content of the current clip but with a modified timeline, time ``t`` being replaced by another time `time_func(t)`. Parameters ---------- time_func : function A function ``t -> new_t``. apply_to : {"mask", "audio", ["mask", "audio"]}, optional Can be either 'mask', or 'audio', or ['mask','audio']. Specifies if the filter ``transform`` should also be applied to the audio or the mask of the clip, if any. keep_duration : bool, optional ``False`` (default) if the transformation modifies the ``duration`` of the clip. Examples -------- >>> # plays the clip (and its mask and sound) twice faster >>> new_clip = clip.time_transform(lambda t: 2*t, apply_to=['mask', 'audio']) >>> >>> # plays the clip starting at t=3, and backwards: >>> new_clip = clip.time_transform(lambda t: 3-t) """ if apply_to is None: apply_to = [] return self.transform( lambda get_frame, t: get_frame(time_func(t)), apply_to, keep_duration=keep_duration, )
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L143-L181
46
[ 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 ]
100
[]
0
true
100
39
2
100
27
def time_transform(self, time_func, apply_to=None, keep_duration=False): if apply_to is None: apply_to = [] return self.transform( lambda get_frame, t: get_frame(time_func(t)), apply_to, keep_duration=keep_duration, )
28,357
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.fx
(self, func, *args, **kwargs)
return func(self, *args, **kwargs)
Returns the result of ``func(self, *args, **kwargs)``, for instance >>> new_clip = clip.fx(resize, 0.2, method="bilinear") is equivalent to >>> new_clip = resize(clip, 0.2, method="bilinear") The motivation of fx is to keep the name of the effect near its parameters when the effects are chained: >>> from moviepy.video.fx import multiply_volume, resize, mirrorx >>> clip.fx(multiply_volume, 0.5).fx(resize, 0.3).fx(mirrorx) >>> # Is equivalent, but clearer than >>> mirrorx(resize(multiply_volume(clip, 0.5), 0.3))
Returns the result of ``func(self, *args, **kwargs)``, for instance
183
200
def fx(self, func, *args, **kwargs): """Returns the result of ``func(self, *args, **kwargs)``, for instance >>> new_clip = clip.fx(resize, 0.2, method="bilinear") is equivalent to >>> new_clip = resize(clip, 0.2, method="bilinear") The motivation of fx is to keep the name of the effect near its parameters when the effects are chained: >>> from moviepy.video.fx import multiply_volume, resize, mirrorx >>> clip.fx(multiply_volume, 0.5).fx(resize, 0.3).fx(mirrorx) >>> # Is equivalent, but clearer than >>> mirrorx(resize(multiply_volume(clip, 0.5), 0.3)) """ return func(self, *args, **kwargs)
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L183-L200
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ]
100
[]
0
true
100
18
1
100
15
def fx(self, func, *args, **kwargs): return func(self, *args, **kwargs)
28,358
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.with_start
(self, t, change_end=True)
Returns a copy of the clip, with the ``start`` attribute set to ``t``, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. These changes are also applied to the ``audio`` and ``mask`` clips of the current clip, if they exist. Parameters ---------- t : float or tuple or str New ``start`` attribute value for the clip. change_end : bool optional Indicates if the ``end`` attribute value must be changed accordingly, if possible. If ``change_end=True`` and the clip has a ``duration`` attribute, the ``end`` attribute of the clip will be updated to ``start + duration``. If ``change_end=False`` and the clip has a ``end`` attribute, the ``duration`` attribute of the clip will be updated to ``end - start``.
Returns a copy of the clip, with the ``start`` attribute set to ``t``, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'.
206
232
def with_start(self, t, change_end=True): """Returns a copy of the clip, with the ``start`` attribute set to ``t``, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. These changes are also applied to the ``audio`` and ``mask`` clips of the current clip, if they exist. Parameters ---------- t : float or tuple or str New ``start`` attribute value for the clip. change_end : bool optional Indicates if the ``end`` attribute value must be changed accordingly, if possible. If ``change_end=True`` and the clip has a ``duration`` attribute, the ``end`` attribute of the clip will be updated to ``start + duration``. If ``change_end=False`` and the clip has a ``end`` attribute, the ``duration`` attribute of the clip will be updated to ``end - start``. """ self.start = t if (self.duration is not None) and change_end: self.end = t + self.duration elif self.end is not None: self.duration = self.end - self.start
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L206-L232
46
[ 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 ]
100
[]
0
true
100
27
4
100
20
def with_start(self, t, change_end=True): self.start = t if (self.duration is not None) and change_end: self.end = t + self.duration elif self.end is not None: self.duration = self.end - self.start
28,359
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.with_end
(self, t)
Returns a copy of the clip, with the ``end`` attribute set to ``t``, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. Also sets the duration of the mask and audio, if any, of the returned clip. Parameters ---------- t : float or tuple or str New ``end`` attribute value for the clip.
Returns a copy of the clip, with the ``end`` attribute set to ``t``, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. Also sets the duration of the mask and audio, if any, of the returned clip.
238
257
def with_end(self, t): """Returns a copy of the clip, with the ``end`` attribute set to ``t``, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. Also sets the duration of the mask and audio, if any, of the returned clip. Parameters ---------- t : float or tuple or str New ``end`` attribute value for the clip. """ self.end = t if self.end is None: return if self.start is None: if self.duration is not None: self.start = max(0, t - self.duration) else: self.duration = self.end - self.start
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L238-L257
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
100
[]
0
true
100
20
4
100
10
def with_end(self, t): self.end = t if self.end is None: return if self.start is None: if self.duration is not None: self.start = max(0, t - self.duration) else: self.duration = self.end - self.start
28,360
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.with_duration
(self, duration, change_end=True)
Returns a copy of the clip, with the ``duration`` attribute set to ``t``, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. Also sets the duration of the mask and audio, if any, of the returned clip. If ``change_end is False``, the start attribute of the clip will be modified in function of the duration and the preset end of the clip. Parameters ---------- duration : float New duration attribute value for the clip. change_end : bool, optional If ``True``, the ``end`` attribute value of the clip will be adjusted accordingly to the new duration using ``clip.start + duration``.
Returns a copy of the clip, with the ``duration`` attribute set to ``t``, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. Also sets the duration of the mask and audio, if any, of the returned clip.
263
289
def with_duration(self, duration, change_end=True): """Returns a copy of the clip, with the ``duration`` attribute set to ``t``, which can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. Also sets the duration of the mask and audio, if any, of the returned clip. If ``change_end is False``, the start attribute of the clip will be modified in function of the duration and the preset end of the clip. Parameters ---------- duration : float New duration attribute value for the clip. change_end : bool, optional If ``True``, the ``end`` attribute value of the clip will be adjusted accordingly to the new duration using ``clip.start + duration``. """ self.duration = duration if change_end: self.end = None if (duration is None) else (self.start + duration) else: if self.duration is None: raise ValueError("Cannot change clip start when new duration is None") self.start = self.end - duration
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L263-L289
46
[ 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 ]
100
[]
0
true
100
27
3
100
17
def with_duration(self, duration, change_end=True): self.duration = duration if change_end: self.end = None if (duration is None) else (self.start + duration) else: if self.duration is None: raise ValueError("Cannot change clip start when new duration is None") self.start = self.end - duration
28,361
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.with_make_frame
(self, make_frame)
Sets a ``make_frame`` attribute for the clip. Useful for setting arbitrary/complicated videoclips. Parameters ---------- make_frame : function New frame creator function for the clip.
Sets a ``make_frame`` attribute for the clip. Useful for setting arbitrary/complicated videoclips.
292
302
def with_make_frame(self, make_frame): """Sets a ``make_frame`` attribute for the clip. Useful for setting arbitrary/complicated videoclips. Parameters ---------- make_frame : function New frame creator function for the clip. """ self.make_frame = make_frame
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L292-L302
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
100
[]
0
true
100
11
1
100
8
def with_make_frame(self, make_frame): self.make_frame = make_frame
28,362
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.with_fps
(self, fps, change_duration=False)
return newclip
Returns a copy of the clip with a new default fps for functions like write_videofile, iterframe, etc. Parameters ---------- fps : int New ``fps`` attribute value for the clip. change_duration : bool, optional If ``change_duration=True``, then the video speed will change to match the new fps (conserving all frames 1:1). For example, if the fps is halved in this mode, the duration will be doubled.
Returns a copy of the clip with a new default fps for functions like write_videofile, iterframe, etc.
304
327
def with_fps(self, fps, change_duration=False): """Returns a copy of the clip with a new default fps for functions like write_videofile, iterframe, etc. Parameters ---------- fps : int New ``fps`` attribute value for the clip. change_duration : bool, optional If ``change_duration=True``, then the video speed will change to match the new fps (conserving all frames 1:1). For example, if the fps is halved in this mode, the duration will be doubled. """ if change_duration: from moviepy.video.fx.multiply_speed import multiply_speed newclip = multiply_speed(self, fps / self.fps) else: newclip = self.copy() newclip.fps = fps return newclip
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L304-L327
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 ]
100
[]
0
true
100
24
2
100
13
def with_fps(self, fps, change_duration=False): if change_duration: from moviepy.video.fx.multiply_speed import multiply_speed newclip = multiply_speed(self, fps / self.fps) else: newclip = self.copy() newclip.fps = fps return newclip
28,363
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.with_is_mask
(self, is_mask)
Says whether the clip is a mask or not. Parameters ---------- is_mask : bool New ``is_mask`` attribute value for the clip.
Says whether the clip is a mask or not.
330
339
def with_is_mask(self, is_mask): """Says whether the clip is a mask or not. Parameters ---------- is_mask : bool New ``is_mask`` attribute value for the clip. """ self.is_mask = is_mask
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L330-L339
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
100
10
1
100
7
def with_is_mask(self, is_mask): self.is_mask = is_mask
28,364
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.with_memoize
(self, memoize)
Sets whether the clip should keep the last frame read in memory. Parameters ---------- memoize : bool Indicates if the clip should keep the last frame read in memory.
Sets whether the clip should keep the last frame read in memory.
342
351
def with_memoize(self, memoize): """Sets whether the clip should keep the last frame read in memory. Parameters ---------- memoize : bool Indicates if the clip should keep the last frame read in memory. """ self.memoize = memoize
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L342-L351
46
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
100
[]
0
true
100
10
1
100
7
def with_memoize(self, memoize): self.memoize = memoize
28,365
Zulko/moviepy
858bb81fba7e09f1f562283ed6d1394db883b6c7
moviepy/Clip.py
Clip.is_playing
(self, t)
If ``t`` is a time, returns true if t is between the start and the end of the clip. ``t`` can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. If ``t`` is a numpy array, returns False if none of the ``t`` is in the clip, else returns a vector [b_1, b_2, b_3...] where b_i is true if tti is in the clip.
If ``t`` is a time, returns true if t is between the start and the end of the clip. ``t`` can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. If ``t`` is a numpy array, returns False if none of the ``t`` is in the clip, else returns a vector [b_1, b_2, b_3...] where b_i is true if tti is in the clip.
354
379
def is_playing(self, t): """If ``t`` is a time, returns true if t is between the start and the end of the clip. ``t`` can be expressed in seconds (15.35), in (min, sec), in (hour, min, sec), or as a string: '01:03:05.35'. If ``t`` is a numpy array, returns False if none of the ``t`` is in the clip, else returns a vector [b_1, b_2, b_3...] where b_i is true if tti is in the clip. """ if isinstance(t, np.ndarray): # is the whole list of t outside the clip ? tmin, tmax = t.min(), t.max() if (self.end is not None) and (tmin >= self.end): return False if tmax < self.start: return False # If we arrive here, a part of t falls in the clip result = 1 * (t >= self.start) if self.end is not None: result *= t <= self.end return result else: return (t >= self.start) and ((self.end is None) or (t < self.end))
https://github.com/Zulko/moviepy/blob/858bb81fba7e09f1f562283ed6d1394db883b6c7/project46/moviepy/Clip.py#L354-L379
46
[ 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 ]
100
[]
0
true
100
26
8
100
5
def is_playing(self, t): if isinstance(t, np.ndarray): # is the whole list of t outside the clip ? tmin, tmax = t.min(), t.max() if (self.end is not None) and (tmin >= self.end): return False if tmax < self.start: return False # If we arrive here, a part of t falls in the clip result = 1 * (t >= self.start) if self.end is not None: result *= t <= self.end return result else: return (t >= self.start) and ((self.end is None) or (t < self.end))
28,366