labNo
float64
1
10
taskNo
float64
0
4
questioner
stringclasses
2 values
question
stringlengths
9
201
code
stringlengths
18
30.3k
startLine
float64
0
192
endLine
float64
0
196
questionType
stringclasses
4 values
answer
stringlengths
2
905
src
stringclasses
3 values
code_processed
stringlengths
12
28.3k
id
stringlengths
2
5
raw_code
stringlengths
20
30.3k
raw_comment
stringlengths
10
242
comment
stringlengths
9
207
q_code
stringlengths
66
30.3k
null
null
null
What does this function do?
def absent(dest, username, check_mode): if (StrictVersion(passlib.__version__) >= StrictVersion('1.6')): ht = HtpasswdFile(dest, new=False) else: ht = HtpasswdFile(dest) if (username not in ht.users()): return (('%s not present' % username), False) else: if (not check_mode): ht.delete(username) ht.save() return (('Remove %s' % username), True)
null
null
null
Ensures user is absent Returns (msg, changed)
pcsd
def absent dest username check mode if Strict Version passlib version >= Strict Version '1 6' ht = Htpasswd File dest new=False else ht = Htpasswd File dest if username not in ht users return '%s not present' % username False else if not check mode ht delete username ht save return 'Remove %s' % username True
7607
def absent(dest, username, check_mode): if (StrictVersion(passlib.__version__) >= StrictVersion('1.6')): ht = HtpasswdFile(dest, new=False) else: ht = HtpasswdFile(dest) if (username not in ht.users()): return (('%s not present' % username), False) else: if (not check_mode): ht.delete(username) ht.save() return (('Remove %s' % username), True)
Ensures user is absent Returns (msg, changed)
ensures user is absent
Question: What does this function do? Code: def absent(dest, username, check_mode): if (StrictVersion(passlib.__version__) >= StrictVersion('1.6')): ht = HtpasswdFile(dest, new=False) else: ht = HtpasswdFile(dest) if (username not in ht.users()): return (('%s not present' % username), False) else: if (not check_mode): ht.delete(username) ht.save() return (('Remove %s' % username), True)
null
null
null
What does this function do?
def update_index(sender, instance, created, **kwargs): if (isinstance(instance, Object) and instance.is_searchable()): search_item = instance.get_search_item() ix = index.open_dir(settings.WHOOSH_INDEX) try: writer = ix.writer() try: if created: writer.add_document(id=search_item['id'], name=search_item['name'], type=search_item['type'], content=search_item['content'], url=unicode(search_item['url'])) writer.commit() else: writer.update_document(id=search_item['id'], name=search_item['name'], type=search_item['type'], content=search_item['content'], url=search_item['url']) writer.commit() except: writer.cancel() except: pass
null
null
null
Add Object to search index
pcsd
def update index sender instance created **kwargs if isinstance instance Object and instance is searchable search item = instance get search item ix = index open dir settings WHOOSH INDEX try writer = ix writer try if created writer add document id=search item['id'] name=search item['name'] type=search item['type'] content=search item['content'] url=unicode search item['url'] writer commit else writer update document id=search item['id'] name=search item['name'] type=search item['type'] content=search item['content'] url=search item['url'] writer commit except writer cancel except pass
7610
def update_index(sender, instance, created, **kwargs): if (isinstance(instance, Object) and instance.is_searchable()): search_item = instance.get_search_item() ix = index.open_dir(settings.WHOOSH_INDEX) try: writer = ix.writer() try: if created: writer.add_document(id=search_item['id'], name=search_item['name'], type=search_item['type'], content=search_item['content'], url=unicode(search_item['url'])) writer.commit() else: writer.update_document(id=search_item['id'], name=search_item['name'], type=search_item['type'], content=search_item['content'], url=search_item['url']) writer.commit() except: writer.cancel() except: pass
Add Object to search index
add object to search index
Question: What does this function do? Code: def update_index(sender, instance, created, **kwargs): if (isinstance(instance, Object) and instance.is_searchable()): search_item = instance.get_search_item() ix = index.open_dir(settings.WHOOSH_INDEX) try: writer = ix.writer() try: if created: writer.add_document(id=search_item['id'], name=search_item['name'], type=search_item['type'], content=search_item['content'], url=unicode(search_item['url'])) writer.commit() else: writer.update_document(id=search_item['id'], name=search_item['name'], type=search_item['type'], content=search_item['content'], url=search_item['url']) writer.commit() except: writer.cancel() except: pass
null
null
null
What does this function do?
@utils.arg('snapshot', metavar='<snapshot>', help='ID of the snapshot.') @utils.arg('display_name', nargs='?', metavar='<display-name>', help='New display-name for the snapshot.') @utils.arg('--display-description', metavar='<display-description>', help='Optional snapshot description. (Default=None)', default=None) @utils.service_type('monitor') def do_snapshot_rename(cs, args): kwargs = {} if (args.display_name is not None): kwargs['display_name'] = args.display_name if (args.display_description is not None): kwargs['display_description'] = args.display_description _find_monitor_snapshot(cs, args.snapshot).update(**kwargs)
null
null
null
Rename a snapshot.
pcsd
@utils arg 'snapshot' metavar='<snapshot>' help='ID of the snapshot ' @utils arg 'display name' nargs='?' metavar='<display-name>' help='New display-name for the snapshot ' @utils arg '--display-description' metavar='<display-description>' help='Optional snapshot description Default=None ' default=None @utils service type 'monitor' def do snapshot rename cs args kwargs = {} if args display name is not None kwargs['display name'] = args display name if args display description is not None kwargs['display description'] = args display description find monitor snapshot cs args snapshot update **kwargs
7621
@utils.arg('snapshot', metavar='<snapshot>', help='ID of the snapshot.') @utils.arg('display_name', nargs='?', metavar='<display-name>', help='New display-name for the snapshot.') @utils.arg('--display-description', metavar='<display-description>', help='Optional snapshot description. (Default=None)', default=None) @utils.service_type('monitor') def do_snapshot_rename(cs, args): kwargs = {} if (args.display_name is not None): kwargs['display_name'] = args.display_name if (args.display_description is not None): kwargs['display_description'] = args.display_description _find_monitor_snapshot(cs, args.snapshot).update(**kwargs)
Rename a snapshot.
rename a snapshot .
Question: What does this function do? Code: @utils.arg('snapshot', metavar='<snapshot>', help='ID of the snapshot.') @utils.arg('display_name', nargs='?', metavar='<display-name>', help='New display-name for the snapshot.') @utils.arg('--display-description', metavar='<display-description>', help='Optional snapshot description. (Default=None)', default=None) @utils.service_type('monitor') def do_snapshot_rename(cs, args): kwargs = {} if (args.display_name is not None): kwargs['display_name'] = args.display_name if (args.display_description is not None): kwargs['display_description'] = args.display_description _find_monitor_snapshot(cs, args.snapshot).update(**kwargs)
null
null
null
What does this function do?
def _read_filter(fid): f = dict() f['freq'] = _read_double(fid)[0] f['class'] = _read_int(fid) f['type'] = _read_int(fid) f['npar'] = _read_int2(fid) f['pars'] = _read_double(fid, f['npar']) return f
null
null
null
Read filter information.
pcsd
def read filter fid f = dict f['freq'] = read double fid [0] f['class'] = read int fid f['type'] = read int fid f['npar'] = read int2 fid f['pars'] = read double fid f['npar'] return f
7623
def _read_filter(fid): f = dict() f['freq'] = _read_double(fid)[0] f['class'] = _read_int(fid) f['type'] = _read_int(fid) f['npar'] = _read_int2(fid) f['pars'] = _read_double(fid, f['npar']) return f
Read filter information.
read filter information .
Question: What does this function do? Code: def _read_filter(fid): f = dict() f['freq'] = _read_double(fid)[0] f['class'] = _read_int(fid) f['type'] = _read_int(fid) f['npar'] = _read_int2(fid) f['pars'] = _read_double(fid, f['npar']) return f
null
null
null
What does this function do?
def parse_geometry(geometry, ratio=None): m = geometry_pat.match(geometry) def syntax_error(): return ThumbnailParseError(('Geometry does not have the correct syntax: %s' % geometry)) if (not m): raise syntax_error() x = m.group('x') y = m.group('y') if ((x is None) and (y is None)): raise syntax_error() if (x is not None): x = int(x) if (y is not None): y = int(y) if (ratio is not None): ratio = float(ratio) if (x is None): x = toint((y * ratio)) elif (y is None): y = toint((x / ratio)) return (x, y)
null
null
null
Parses a geometry string syntax and returns a (width, height) tuple
pcsd
def parse geometry geometry ratio=None m = geometry pat match geometry def syntax error return Thumbnail Parse Error 'Geometry does not have the correct syntax %s' % geometry if not m raise syntax error x = m group 'x' y = m group 'y' if x is None and y is None raise syntax error if x is not None x = int x if y is not None y = int y if ratio is not None ratio = float ratio if x is None x = toint y * ratio elif y is None y = toint x / ratio return x y
7624
def parse_geometry(geometry, ratio=None): m = geometry_pat.match(geometry) def syntax_error(): return ThumbnailParseError(('Geometry does not have the correct syntax: %s' % geometry)) if (not m): raise syntax_error() x = m.group('x') y = m.group('y') if ((x is None) and (y is None)): raise syntax_error() if (x is not None): x = int(x) if (y is not None): y = int(y) if (ratio is not None): ratio = float(ratio) if (x is None): x = toint((y * ratio)) elif (y is None): y = toint((x / ratio)) return (x, y)
Parses a geometry string syntax and returns a (width, height) tuple
parses a geometry string syntax and returns a tuple
Question: What does this function do? Code: def parse_geometry(geometry, ratio=None): m = geometry_pat.match(geometry) def syntax_error(): return ThumbnailParseError(('Geometry does not have the correct syntax: %s' % geometry)) if (not m): raise syntax_error() x = m.group('x') y = m.group('y') if ((x is None) and (y is None)): raise syntax_error() if (x is not None): x = int(x) if (y is not None): y = int(y) if (ratio is not None): ratio = float(ratio) if (x is None): x = toint((y * ratio)) elif (y is None): y = toint((x / ratio)) return (x, y)
null
null
null
What does this function do?
def write_chunk(outfile, tag, data=''): outfile.write(struct.pack('!I', len(data))) outfile.write(tag) outfile.write(data) checksum = zlib.crc32(tag) checksum = zlib.crc32(data, checksum) outfile.write(struct.pack('!i', checksum))
null
null
null
Write a PNG chunk to the output file, including length and checksum.
pcsd
def write chunk outfile tag data='' outfile write struct pack '!I' len data outfile write tag outfile write data checksum = zlib crc32 tag checksum = zlib crc32 data checksum outfile write struct pack '!i' checksum
7627
def write_chunk(outfile, tag, data=''): outfile.write(struct.pack('!I', len(data))) outfile.write(tag) outfile.write(data) checksum = zlib.crc32(tag) checksum = zlib.crc32(data, checksum) outfile.write(struct.pack('!i', checksum))
Write a PNG chunk to the output file, including length and checksum.
write a png chunk to the output file , including length and checksum .
Question: What does this function do? Code: def write_chunk(outfile, tag, data=''): outfile.write(struct.pack('!I', len(data))) outfile.write(tag) outfile.write(data) checksum = zlib.crc32(tag) checksum = zlib.crc32(data, checksum) outfile.write(struct.pack('!i', checksum))
null
null
null
What does this function do?
@require_POST @login_required @permission_required('flagit.can_moderate') def update(request, flagged_object_id): flagged = get_object_or_404(FlaggedObject, pk=flagged_object_id) new_status = request.POST.get('status') if new_status: flagged.status = new_status flagged.save() return HttpResponseRedirect(reverse('flagit.queue'))
null
null
null
Update the status of a flagged object.
pcsd
@require POST @login required @permission required 'flagit can moderate' def update request flagged object id flagged = get object or 404 Flagged Object pk=flagged object id new status = request POST get 'status' if new status flagged status = new status flagged save return Http Response Redirect reverse 'flagit queue'
7636
@require_POST @login_required @permission_required('flagit.can_moderate') def update(request, flagged_object_id): flagged = get_object_or_404(FlaggedObject, pk=flagged_object_id) new_status = request.POST.get('status') if new_status: flagged.status = new_status flagged.save() return HttpResponseRedirect(reverse('flagit.queue'))
Update the status of a flagged object.
update the status of a flagged object .
Question: What does this function do? Code: @require_POST @login_required @permission_required('flagit.can_moderate') def update(request, flagged_object_id): flagged = get_object_or_404(FlaggedObject, pk=flagged_object_id) new_status = request.POST.get('status') if new_status: flagged.status = new_status flagged.save() return HttpResponseRedirect(reverse('flagit.queue'))
null
null
null
What does this function do?
@service.jsonrpc def login(): return True
null
null
null
dummy function to test credentials
pcsd
@service jsonrpc def login return True
7642
@service.jsonrpc def login(): return True
dummy function to test credentials
dummy function to test credentials
Question: What does this function do? Code: @service.jsonrpc def login(): return True
null
null
null
What does this function do?
def instance_get_all_by_host(context, host, columns_to_join=None): return IMPL.instance_get_all_by_host(context, host, columns_to_join)
null
null
null
Get all instances belonging to a host.
pcsd
def instance get all by host context host columns to join=None return IMPL instance get all by host context host columns to join
7643
def instance_get_all_by_host(context, host, columns_to_join=None): return IMPL.instance_get_all_by_host(context, host, columns_to_join)
Get all instances belonging to a host.
get all instances belonging to a host .
Question: What does this function do? Code: def instance_get_all_by_host(context, host, columns_to_join=None): return IMPL.instance_get_all_by_host(context, host, columns_to_join)
null
null
null
What does this function do?
def _pack(coefs_, intercepts_): return np.hstack([l.ravel() for l in (coefs_ + intercepts_)])
null
null
null
Pack the parameters into a single vector.
pcsd
def pack coefs intercepts return np hstack [l ravel for l in coefs + intercepts ]
7649
def _pack(coefs_, intercepts_): return np.hstack([l.ravel() for l in (coefs_ + intercepts_)])
Pack the parameters into a single vector.
pack the parameters into a single vector .
Question: What does this function do? Code: def _pack(coefs_, intercepts_): return np.hstack([l.ravel() for l in (coefs_ + intercepts_)])
null
null
null
What does this function do?
def telescopic(L, R, limits): (i, a, b) = limits if (L.is_Add or R.is_Add): return None k = Wild('k') sol = (- R).match(L.subs(i, (i + k))) s = None if (sol and (k in sol)): s = sol[k] if (not (s.is_Integer and (L.subs(i, (i + s)) == (- R)))): s = None if (s is None): m = Dummy('m') try: sol = (solve((L.subs(i, (i + m)) + R), m) or []) except NotImplementedError: return None sol = [si for si in sol if (si.is_Integer and (L.subs(i, (i + si)) + R).expand().is_zero)] if (len(sol) != 1): return None s = sol[0] if (s < 0): return telescopic_direct(R, L, abs(s), (i, a, b)) elif (s > 0): return telescopic_direct(L, R, s, (i, a, b))
null
null
null
Tries to perform the summation using the telescopic property return None if not possible
pcsd
def telescopic L R limits i a b = limits if L is Add or R is Add return None k = Wild 'k' sol = - R match L subs i i + k s = None if sol and k in sol s = sol[k] if not s is Integer and L subs i i + s == - R s = None if s is None m = Dummy 'm' try sol = solve L subs i i + m + R m or [] except Not Implemented Error return None sol = [si for si in sol if si is Integer and L subs i i + si + R expand is zero ] if len sol != 1 return None s = sol[0] if s < 0 return telescopic direct R L abs s i a b elif s > 0 return telescopic direct L R s i a b
7650
def telescopic(L, R, limits): (i, a, b) = limits if (L.is_Add or R.is_Add): return None k = Wild('k') sol = (- R).match(L.subs(i, (i + k))) s = None if (sol and (k in sol)): s = sol[k] if (not (s.is_Integer and (L.subs(i, (i + s)) == (- R)))): s = None if (s is None): m = Dummy('m') try: sol = (solve((L.subs(i, (i + m)) + R), m) or []) except NotImplementedError: return None sol = [si for si in sol if (si.is_Integer and (L.subs(i, (i + si)) + R).expand().is_zero)] if (len(sol) != 1): return None s = sol[0] if (s < 0): return telescopic_direct(R, L, abs(s), (i, a, b)) elif (s > 0): return telescopic_direct(L, R, s, (i, a, b))
Tries to perform the summation using the telescopic property return None if not possible
tries to perform the summation using the telescopic property return none if not possible
Question: What does this function do? Code: def telescopic(L, R, limits): (i, a, b) = limits if (L.is_Add or R.is_Add): return None k = Wild('k') sol = (- R).match(L.subs(i, (i + k))) s = None if (sol and (k in sol)): s = sol[k] if (not (s.is_Integer and (L.subs(i, (i + s)) == (- R)))): s = None if (s is None): m = Dummy('m') try: sol = (solve((L.subs(i, (i + m)) + R), m) or []) except NotImplementedError: return None sol = [si for si in sol if (si.is_Integer and (L.subs(i, (i + si)) + R).expand().is_zero)] if (len(sol) != 1): return None s = sol[0] if (s < 0): return telescopic_direct(R, L, abs(s), (i, a, b)) elif (s > 0): return telescopic_direct(L, R, s, (i, a, b))
null
null
null
What does this function do?
@receiver(post_save, sender=User) def user_post_save_callback(sender, **kwargs): user = kwargs['instance'] emit_field_changed_events(user, user, sender._meta.db_table, excluded_fields=['last_login', 'first_name', 'last_name'], hidden_fields=['password'])
null
null
null
Emit analytics events after saving the User.
pcsd
@receiver post save sender=User def user post save callback sender **kwargs user = kwargs['instance'] emit field changed events user user sender meta db table excluded fields=['last login' 'first name' 'last name'] hidden fields=['password']
7655
@receiver(post_save, sender=User) def user_post_save_callback(sender, **kwargs): user = kwargs['instance'] emit_field_changed_events(user, user, sender._meta.db_table, excluded_fields=['last_login', 'first_name', 'last_name'], hidden_fields=['password'])
Emit analytics events after saving the User.
emit analytics events after saving the user .
Question: What does this function do? Code: @receiver(post_save, sender=User) def user_post_save_callback(sender, **kwargs): user = kwargs['instance'] emit_field_changed_events(user, user, sender._meta.db_table, excluded_fields=['last_login', 'first_name', 'last_name'], hidden_fields=['password'])
null
null
null
What does this function do?
@treeio_login_required def ajax_contact_lookup(request, response_format='html'): contacts = [] if (request.GET and ('term' in request.GET)): user = request.user.profile contacts = Object.filter_permitted(user, Contact.objects, mode='x').filter(Q(name__icontains=request.GET['term']))[:10] return render_to_response('identities/ajax_contact_lookup', {'contacts': contacts}, context_instance=RequestContext(request), response_format=response_format)
null
null
null
Returns a list of matching contacts
pcsd
@treeio login required def ajax contact lookup request response format='html' contacts = [] if request GET and 'term' in request GET user = request user profile contacts = Object filter permitted user Contact objects mode='x' filter Q name icontains=request GET['term'] [ 10] return render to response 'identities/ajax contact lookup' {'contacts' contacts} context instance=Request Context request response format=response format
7662
@treeio_login_required def ajax_contact_lookup(request, response_format='html'): contacts = [] if (request.GET and ('term' in request.GET)): user = request.user.profile contacts = Object.filter_permitted(user, Contact.objects, mode='x').filter(Q(name__icontains=request.GET['term']))[:10] return render_to_response('identities/ajax_contact_lookup', {'contacts': contacts}, context_instance=RequestContext(request), response_format=response_format)
Returns a list of matching contacts
returns a list of matching contacts
Question: What does this function do? Code: @treeio_login_required def ajax_contact_lookup(request, response_format='html'): contacts = [] if (request.GET and ('term' in request.GET)): user = request.user.profile contacts = Object.filter_permitted(user, Contact.objects, mode='x').filter(Q(name__icontains=request.GET['term']))[:10] return render_to_response('identities/ajax_contact_lookup', {'contacts': contacts}, context_instance=RequestContext(request), response_format=response_format)
null
null
null
What does this function do?
def subscription_check(): subscriptions = Subscription.objects.all() for subscription in subscriptions: subscription.check_status()
null
null
null
Automatically depreciate assets as per their depreciation rate
pcsd
def subscription check subscriptions = Subscription objects all for subscription in subscriptions subscription check status
7665
def subscription_check(): subscriptions = Subscription.objects.all() for subscription in subscriptions: subscription.check_status()
Automatically depreciate assets as per their depreciation rate
automatically depreciate assets as per their depreciation rate
Question: What does this function do? Code: def subscription_check(): subscriptions = Subscription.objects.all() for subscription in subscriptions: subscription.check_status()
null
null
null
What does this function do?
def _setwindowsize(folder_alias, (w, h)): finder = _getfinder() args = {} attrs = {} _code = 'core' _subcode = 'setd' aevar00 = [w, h] aeobj_0 = aetypes.ObjectSpecifier(want=aetypes.Type('cfol'), form='alis', seld=folder_alias, fr=None) aeobj_1 = aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form='prop', seld=aetypes.Type('cwnd'), fr=aeobj_0) aeobj_2 = aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form='prop', seld=aetypes.Type('ptsz'), fr=aeobj_1) args['----'] = aeobj_2 args['data'] = aevar00 (_reply, args, attrs) = finder.send(_code, _subcode, args, attrs) if args.has_key('errn'): raise Error, aetools.decodeerror(args) return (w, h)
null
null
null
Set the size of a Finder window for folder to (w, h)
pcsd
def setwindowsize folder alias w h finder = getfinder args = {} attrs = {} code = 'core' subcode = 'setd' aevar00 = [w h] aeobj 0 = aetypes Object Specifier want=aetypes Type 'cfol' form='alis' seld=folder alias fr=None aeobj 1 = aetypes Object Specifier want=aetypes Type 'prop' form='prop' seld=aetypes Type 'cwnd' fr=aeobj 0 aeobj 2 = aetypes Object Specifier want=aetypes Type 'prop' form='prop' seld=aetypes Type 'ptsz' fr=aeobj 1 args['----'] = aeobj 2 args['data'] = aevar00 reply args attrs = finder send code subcode args attrs if args has key 'errn' raise Error aetools decodeerror args return w h
7669
def _setwindowsize(folder_alias, (w, h)): finder = _getfinder() args = {} attrs = {} _code = 'core' _subcode = 'setd' aevar00 = [w, h] aeobj_0 = aetypes.ObjectSpecifier(want=aetypes.Type('cfol'), form='alis', seld=folder_alias, fr=None) aeobj_1 = aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form='prop', seld=aetypes.Type('cwnd'), fr=aeobj_0) aeobj_2 = aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form='prop', seld=aetypes.Type('ptsz'), fr=aeobj_1) args['----'] = aeobj_2 args['data'] = aevar00 (_reply, args, attrs) = finder.send(_code, _subcode, args, attrs) if args.has_key('errn'): raise Error, aetools.decodeerror(args) return (w, h)
Set the size of a Finder window for folder to (w, h)
set the size of a finder window for folder to
Question: What does this function do? Code: def _setwindowsize(folder_alias, (w, h)): finder = _getfinder() args = {} attrs = {} _code = 'core' _subcode = 'setd' aevar00 = [w, h] aeobj_0 = aetypes.ObjectSpecifier(want=aetypes.Type('cfol'), form='alis', seld=folder_alias, fr=None) aeobj_1 = aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form='prop', seld=aetypes.Type('cwnd'), fr=aeobj_0) aeobj_2 = aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form='prop', seld=aetypes.Type('ptsz'), fr=aeobj_1) args['----'] = aeobj_2 args['data'] = aevar00 (_reply, args, attrs) = finder.send(_code, _subcode, args, attrs) if args.has_key('errn'): raise Error, aetools.decodeerror(args) return (w, h)
null
null
null
What does this function do?
def is_nonstring_iterable(obj): return (isinstance(obj, Iterable) and (not isinstance(obj, string_types)))
null
null
null
Returns whether the obj is an iterable, but not a string
pcsd
def is nonstring iterable obj return isinstance obj Iterable and not isinstance obj string types
7677
def is_nonstring_iterable(obj): return (isinstance(obj, Iterable) and (not isinstance(obj, string_types)))
Returns whether the obj is an iterable, but not a string
returns whether the obj is an iterable , but not a string
Question: What does this function do? Code: def is_nonstring_iterable(obj): return (isinstance(obj, Iterable) and (not isinstance(obj, string_types)))
null
null
null
What does this function do?
def mp_icon(filename): try: import pkg_resources name = __name__ if (name == '__main__'): name = 'MAVProxy.modules.mavproxy_map.mp_tile' stream = pkg_resources.resource_stream(name, ('data/%s' % filename)).read() raw = np.fromstring(stream, dtype=np.uint8) except Exception: stream = open(os.path.join(__file__, 'data', filename)).read() raw = np.fromstring(stream, dtype=np.uint8) img = cv2.imdecode(raw, cv2.IMREAD_COLOR) return img
null
null
null
load an icon from the data directory
pcsd
def mp icon filename try import pkg resources name = name if name == ' main ' name = 'MAV Proxy modules mavproxy map mp tile' stream = pkg resources resource stream name 'data/%s' % filename read raw = np fromstring stream dtype=np uint8 except Exception stream = open os path join file 'data' filename read raw = np fromstring stream dtype=np uint8 img = cv2 imdecode raw cv2 IMREAD COLOR return img
7683
def mp_icon(filename): try: import pkg_resources name = __name__ if (name == '__main__'): name = 'MAVProxy.modules.mavproxy_map.mp_tile' stream = pkg_resources.resource_stream(name, ('data/%s' % filename)).read() raw = np.fromstring(stream, dtype=np.uint8) except Exception: stream = open(os.path.join(__file__, 'data', filename)).read() raw = np.fromstring(stream, dtype=np.uint8) img = cv2.imdecode(raw, cv2.IMREAD_COLOR) return img
load an icon from the data directory
load an icon from the data directory
Question: What does this function do? Code: def mp_icon(filename): try: import pkg_resources name = __name__ if (name == '__main__'): name = 'MAVProxy.modules.mavproxy_map.mp_tile' stream = pkg_resources.resource_stream(name, ('data/%s' % filename)).read() raw = np.fromstring(stream, dtype=np.uint8) except Exception: stream = open(os.path.join(__file__, 'data', filename)).read() raw = np.fromstring(stream, dtype=np.uint8) img = cv2.imdecode(raw, cv2.IMREAD_COLOR) return img
null
null
null
What does this function do?
def assignment(): def prep(r): mission_date = s3db.deploy_mission.created_on mission_date.represent = (lambda d: s3base.S3DateTime.date_represent(d, utc=True)) if r.record: table = r.resource.table table.mission_id.writable = False table.human_resource_id.writable = False if (r.representation == 'popup'): r.resource.configure(insertable=False) return True s3.prep = prep def postp(r, output): if (r.id and isinstance(output, dict)): popup = (r.representation == 'popup') record_id = r.id atable = s3db.hrm_appraisal ltable = s3db.deploy_assignment_appraisal query = (((ltable.assignment_id == record_id) & (atable.id == ltable.appraisal_id)) & (atable.deleted != True)) appraisal = db(query).select(atable.id, limitby=(0, 1)).first() permit = auth.s3_has_permission url = None if (appraisal and permit('update', atable, record_id=appraisal.id)): hrtable = db.hrm_human_resource hr = db((hrtable.id == r.record.human_resource_id)).select(hrtable.person_id, limitby=(0, 1)).first() if hr: get_vars = {} if popup: method = 'update.popup' refresh = get_vars.get('refresh', None) if refresh: get_vars['refresh'] = refresh record = get_vars.get('record', None) if record: get_vars['record'] = record else: method = 'update' url = URL(c='deploy', f='person', args=[hr.person_id, 'appraisal', appraisal.id, method], vars=get_vars) elif permit('update', r.table, record_id=record_id): hrtable = db.hrm_human_resource hr = db((hrtable.id == r.record.human_resource_id)).select(hrtable.person_id, limitby=(0, 1)).first() if hr: get_vars = {'mission_id': r.record.mission_id} if popup: method = 'create.popup' refresh = get_vars.get('refresh', None) if refresh: get_vars['refresh'] = refresh record = get_vars.get('record', None) if record: get_vars['record'] = record else: method = 'create' url = URL(c='deploy', f='person', args=[hr.person_id, 'appraisal', method], vars=get_vars) if url: button = s3base.S3CRUD.crud_button(T('Upload Appraisal'), _href=url, _class='action-btn') if popup: output['items'] = button else: s3.rfooter = button return output s3.postp = postp return s3_rest_controller()
null
null
null
RESTful CRUD Controller
pcsd
def assignment def prep r mission date = s3db deploy mission created on mission date represent = lambda d s3base S3Date Time date represent d utc=True if r record table = r resource table table mission id writable = False table human resource id writable = False if r representation == 'popup' r resource configure insertable=False return True s3 prep = prep def postp r output if r id and isinstance output dict popup = r representation == 'popup' record id = r id atable = s3db hrm appraisal ltable = s3db deploy assignment appraisal query = ltable assignment id == record id & atable id == ltable appraisal id & atable deleted != True appraisal = db query select atable id limitby= 0 1 first permit = auth s3 has permission url = None if appraisal and permit 'update' atable record id=appraisal id hrtable = db hrm human resource hr = db hrtable id == r record human resource id select hrtable person id limitby= 0 1 first if hr get vars = {} if popup method = 'update popup' refresh = get vars get 'refresh' None if refresh get vars['refresh'] = refresh record = get vars get 'record' None if record get vars['record'] = record else method = 'update' url = URL c='deploy' f='person' args=[hr person id 'appraisal' appraisal id method] vars=get vars elif permit 'update' r table record id=record id hrtable = db hrm human resource hr = db hrtable id == r record human resource id select hrtable person id limitby= 0 1 first if hr get vars = {'mission id' r record mission id} if popup method = 'create popup' refresh = get vars get 'refresh' None if refresh get vars['refresh'] = refresh record = get vars get 'record' None if record get vars['record'] = record else method = 'create' url = URL c='deploy' f='person' args=[hr person id 'appraisal' method] vars=get vars if url button = s3base S3CRUD crud button T 'Upload Appraisal' href=url class='action-btn' if popup output['items'] = button else s3 rfooter = button return output s3 postp = postp return s3 rest controller
7692
def assignment(): def prep(r): mission_date = s3db.deploy_mission.created_on mission_date.represent = (lambda d: s3base.S3DateTime.date_represent(d, utc=True)) if r.record: table = r.resource.table table.mission_id.writable = False table.human_resource_id.writable = False if (r.representation == 'popup'): r.resource.configure(insertable=False) return True s3.prep = prep def postp(r, output): if (r.id and isinstance(output, dict)): popup = (r.representation == 'popup') record_id = r.id atable = s3db.hrm_appraisal ltable = s3db.deploy_assignment_appraisal query = (((ltable.assignment_id == record_id) & (atable.id == ltable.appraisal_id)) & (atable.deleted != True)) appraisal = db(query).select(atable.id, limitby=(0, 1)).first() permit = auth.s3_has_permission url = None if (appraisal and permit('update', atable, record_id=appraisal.id)): hrtable = db.hrm_human_resource hr = db((hrtable.id == r.record.human_resource_id)).select(hrtable.person_id, limitby=(0, 1)).first() if hr: get_vars = {} if popup: method = 'update.popup' refresh = get_vars.get('refresh', None) if refresh: get_vars['refresh'] = refresh record = get_vars.get('record', None) if record: get_vars['record'] = record else: method = 'update' url = URL(c='deploy', f='person', args=[hr.person_id, 'appraisal', appraisal.id, method], vars=get_vars) elif permit('update', r.table, record_id=record_id): hrtable = db.hrm_human_resource hr = db((hrtable.id == r.record.human_resource_id)).select(hrtable.person_id, limitby=(0, 1)).first() if hr: get_vars = {'mission_id': r.record.mission_id} if popup: method = 'create.popup' refresh = get_vars.get('refresh', None) if refresh: get_vars['refresh'] = refresh record = get_vars.get('record', None) if record: get_vars['record'] = record else: method = 'create' url = URL(c='deploy', f='person', args=[hr.person_id, 'appraisal', method], vars=get_vars) if url: button = s3base.S3CRUD.crud_button(T('Upload Appraisal'), _href=url, _class='action-btn') if popup: output['items'] = button else: s3.rfooter = button return output s3.postp = postp return s3_rest_controller()
RESTful CRUD Controller
restful crud controller
Question: What does this function do? Code: def assignment(): def prep(r): mission_date = s3db.deploy_mission.created_on mission_date.represent = (lambda d: s3base.S3DateTime.date_represent(d, utc=True)) if r.record: table = r.resource.table table.mission_id.writable = False table.human_resource_id.writable = False if (r.representation == 'popup'): r.resource.configure(insertable=False) return True s3.prep = prep def postp(r, output): if (r.id and isinstance(output, dict)): popup = (r.representation == 'popup') record_id = r.id atable = s3db.hrm_appraisal ltable = s3db.deploy_assignment_appraisal query = (((ltable.assignment_id == record_id) & (atable.id == ltable.appraisal_id)) & (atable.deleted != True)) appraisal = db(query).select(atable.id, limitby=(0, 1)).first() permit = auth.s3_has_permission url = None if (appraisal and permit('update', atable, record_id=appraisal.id)): hrtable = db.hrm_human_resource hr = db((hrtable.id == r.record.human_resource_id)).select(hrtable.person_id, limitby=(0, 1)).first() if hr: get_vars = {} if popup: method = 'update.popup' refresh = get_vars.get('refresh', None) if refresh: get_vars['refresh'] = refresh record = get_vars.get('record', None) if record: get_vars['record'] = record else: method = 'update' url = URL(c='deploy', f='person', args=[hr.person_id, 'appraisal', appraisal.id, method], vars=get_vars) elif permit('update', r.table, record_id=record_id): hrtable = db.hrm_human_resource hr = db((hrtable.id == r.record.human_resource_id)).select(hrtable.person_id, limitby=(0, 1)).first() if hr: get_vars = {'mission_id': r.record.mission_id} if popup: method = 'create.popup' refresh = get_vars.get('refresh', None) if refresh: get_vars['refresh'] = refresh record = get_vars.get('record', None) if record: get_vars['record'] = record else: method = 'create' url = URL(c='deploy', f='person', args=[hr.person_id, 'appraisal', method], vars=get_vars) if url: button = s3base.S3CRUD.crud_button(T('Upload Appraisal'), _href=url, _class='action-btn') if popup: output['items'] = button else: s3.rfooter = button return output s3.postp = postp return s3_rest_controller()
null
null
null
What does this function do?
def res_json(res, jsontype='JSON', exception=PluginError): try: jsondata = res.json() except ValueError as err: if (len(res.text) > 35): snippet = (res.text[:35] + '...') else: snippet = res.text raise exception('Unable to parse {0}: {1} ({2})'.format(jsontype, err, snippet)) return jsondata
null
null
null
This function is deprecated.
pcsd
def res json res jsontype='JSON' exception=Plugin Error try jsondata = res json except Value Error as err if len res text > 35 snippet = res text[ 35] + ' ' else snippet = res text raise exception 'Unable to parse {0} {1} {2} ' format jsontype err snippet return jsondata
7712
def res_json(res, jsontype='JSON', exception=PluginError): try: jsondata = res.json() except ValueError as err: if (len(res.text) > 35): snippet = (res.text[:35] + '...') else: snippet = res.text raise exception('Unable to parse {0}: {1} ({2})'.format(jsontype, err, snippet)) return jsondata
This function is deprecated.
this function is deprecated .
Question: What does this function do? Code: def res_json(res, jsontype='JSON', exception=PluginError): try: jsondata = res.json() except ValueError as err: if (len(res.text) > 35): snippet = (res.text[:35] + '...') else: snippet = res.text raise exception('Unable to parse {0}: {1} ({2})'.format(jsontype, err, snippet)) return jsondata
null
null
null
What does this function do?
def lookup_needs_distinct(opts, lookup_path): field_name = lookup_path.split('__', 1)[0] field = opts.get_field_by_name(field_name)[0] if ((hasattr(field, 'rel') and isinstance(field.rel, models.ManyToManyRel)) or (isinstance(field, models.related.RelatedObject) and (not field.field.unique))): return True return False
null
null
null
Returns True if \'distinct()\' should be used to query the given lookup path.
pcsd
def lookup needs distinct opts lookup path field name = lookup path split ' ' 1 [0] field = opts get field by name field name [0] if hasattr field 'rel' and isinstance field rel models Many To Many Rel or isinstance field models related Related Object and not field field unique return True return False
7722
def lookup_needs_distinct(opts, lookup_path): field_name = lookup_path.split('__', 1)[0] field = opts.get_field_by_name(field_name)[0] if ((hasattr(field, 'rel') and isinstance(field.rel, models.ManyToManyRel)) or (isinstance(field, models.related.RelatedObject) and (not field.field.unique))): return True return False
Returns True if \'distinct()\' should be used to query the given lookup path.
returns true if distinct ( ) should be used to query the given lookup path .
Question: What does this function do? Code: def lookup_needs_distinct(opts, lookup_path): field_name = lookup_path.split('__', 1)[0] field = opts.get_field_by_name(field_name)[0] if ((hasattr(field, 'rel') and isinstance(field.rel, models.ManyToManyRel)) or (isinstance(field, models.related.RelatedObject) and (not field.field.unique))): return True return False
null
null
null
What does this function do?
def s3_endpoint_for_region(region): region = _fix_region(region) if ((not region) or (region == _S3_REGION_WITH_NO_LOCATION_CONSTRAINT)): return _S3_REGIONLESS_ENDPOINT else: return (_S3_REGION_ENDPOINT % {'region': region})
null
null
null
Get the host for S3 in the given AWS region. This will accept ``\'\'`` for region as well, so it\'s fine to use location constraint in place of region.
pcsd
def s3 endpoint for region region region = fix region region if not region or region == S3 REGION WITH NO LOCATION CONSTRAINT return S3 REGIONLESS ENDPOINT else return S3 REGION ENDPOINT % {'region' region}
7723
def s3_endpoint_for_region(region): region = _fix_region(region) if ((not region) or (region == _S3_REGION_WITH_NO_LOCATION_CONSTRAINT)): return _S3_REGIONLESS_ENDPOINT else: return (_S3_REGION_ENDPOINT % {'region': region})
Get the host for S3 in the given AWS region. This will accept ``\'\'`` for region as well, so it\'s fine to use location constraint in place of region.
get the host for s3 in the given aws region .
Question: What does this function do? Code: def s3_endpoint_for_region(region): region = _fix_region(region) if ((not region) or (region == _S3_REGION_WITH_NO_LOCATION_CONSTRAINT)): return _S3_REGIONLESS_ENDPOINT else: return (_S3_REGION_ENDPOINT % {'region': region})
null
null
null
What does this function do?
def DefineFlags(flag_values=FLAGS): module_bar.DefineFlags(flag_values=flag_values) gflags.DEFINE_boolean('tmod_foo_bool', True, 'Boolean flag from module foo.', flag_values=flag_values) gflags.DEFINE_string('tmod_foo_str', 'default', 'String flag.', flag_values=flag_values) gflags.DEFINE_integer('tmod_foo_int', 3, 'Sample int flag.', flag_values=flag_values)
null
null
null
Defines a few flags.
pcsd
def Define Flags flag values=FLAGS module bar Define Flags flag values=flag values gflags DEFINE boolean 'tmod foo bool' True 'Boolean flag from module foo ' flag values=flag values gflags DEFINE string 'tmod foo str' 'default' 'String flag ' flag values=flag values gflags DEFINE integer 'tmod foo int' 3 'Sample int flag ' flag values=flag values
7731
def DefineFlags(flag_values=FLAGS): module_bar.DefineFlags(flag_values=flag_values) gflags.DEFINE_boolean('tmod_foo_bool', True, 'Boolean flag from module foo.', flag_values=flag_values) gflags.DEFINE_string('tmod_foo_str', 'default', 'String flag.', flag_values=flag_values) gflags.DEFINE_integer('tmod_foo_int', 3, 'Sample int flag.', flag_values=flag_values)
Defines a few flags.
defines a few flags .
Question: What does this function do? Code: def DefineFlags(flag_values=FLAGS): module_bar.DefineFlags(flag_values=flag_values) gflags.DEFINE_boolean('tmod_foo_bool', True, 'Boolean flag from module foo.', flag_values=flag_values) gflags.DEFINE_string('tmod_foo_str', 'default', 'String flag.', flag_values=flag_values) gflags.DEFINE_integer('tmod_foo_int', 3, 'Sample int flag.', flag_values=flag_values)
null
null
null
What does this function do?
def make_wiki(): from simplewiki import SimpleWiki database_uri = os.environ.get('SIMPLEWIKI_DATABASE_URI') return SimpleWiki((database_uri or 'sqlite:////tmp/simplewiki.db'))
null
null
null
Helper function that creates a new wiki instance.
pcsd
def make wiki from simplewiki import Simple Wiki database uri = os environ get 'SIMPLEWIKI DATABASE URI' return Simple Wiki database uri or 'sqlite ////tmp/simplewiki db'
7732
def make_wiki(): from simplewiki import SimpleWiki database_uri = os.environ.get('SIMPLEWIKI_DATABASE_URI') return SimpleWiki((database_uri or 'sqlite:////tmp/simplewiki.db'))
Helper function that creates a new wiki instance.
helper function that creates a new wiki instance .
Question: What does this function do? Code: def make_wiki(): from simplewiki import SimpleWiki database_uri = os.environ.get('SIMPLEWIKI_DATABASE_URI') return SimpleWiki((database_uri or 'sqlite:////tmp/simplewiki.db'))
null
null
null
What does this function do?
def get_namespace(tag): m = re.match('^{(.*?)}', tag) namespace = (m.group(1) if m else '') if (not namespace.startswith('http://www.mediawiki.org/xml/export-')): raise ValueError(('%s not recognized as MediaWiki dump namespace' % namespace)) return namespace
null
null
null
Returns the namespace of tag.
pcsd
def get namespace tag m = re match '^{ *? }' tag namespace = m group 1 if m else '' if not namespace startswith 'http //www mediawiki org/xml/export-' raise Value Error '%s not recognized as Media Wiki dump namespace' % namespace return namespace
7739
def get_namespace(tag): m = re.match('^{(.*?)}', tag) namespace = (m.group(1) if m else '') if (not namespace.startswith('http://www.mediawiki.org/xml/export-')): raise ValueError(('%s not recognized as MediaWiki dump namespace' % namespace)) return namespace
Returns the namespace of tag.
returns the namespace of tag .
Question: What does this function do? Code: def get_namespace(tag): m = re.match('^{(.*?)}', tag) namespace = (m.group(1) if m else '') if (not namespace.startswith('http://www.mediawiki.org/xml/export-')): raise ValueError(('%s not recognized as MediaWiki dump namespace' % namespace)) return namespace
null
null
null
What does this function do?
def scan(opts): ret = {} for (root, dirs, files) in os.walk(opts['root']): for fn_ in files: full = os.path.join(root, fn_) if full.endswith('.py'): ret.update(mod_data(opts, full)) return ret
null
null
null
Scan the provided root for python source files
pcsd
def scan opts ret = {} for root dirs files in os walk opts['root'] for fn in files full = os path join root fn if full endswith ' py' ret update mod data opts full return ret
7745
def scan(opts): ret = {} for (root, dirs, files) in os.walk(opts['root']): for fn_ in files: full = os.path.join(root, fn_) if full.endswith('.py'): ret.update(mod_data(opts, full)) return ret
Scan the provided root for python source files
scan the provided root for python source files
Question: What does this function do? Code: def scan(opts): ret = {} for (root, dirs, files) in os.walk(opts['root']): for fn_ in files: full = os.path.join(root, fn_) if full.endswith('.py'): ret.update(mod_data(opts, full)) return ret
null
null
null
What does this function do?
@domain_constructor(loss_target=0) def quadratic1(): return {'loss': ((hp.uniform('x', (-5), 5) - 3) ** 2), 'status': base.STATUS_OK}
null
null
null
About the simplest problem you could ask for: optimize a one-variable quadratic function.
pcsd
@domain constructor loss target=0 def quadratic1 return {'loss' hp uniform 'x' -5 5 - 3 ** 2 'status' base STATUS OK}
7747
@domain_constructor(loss_target=0) def quadratic1(): return {'loss': ((hp.uniform('x', (-5), 5) - 3) ** 2), 'status': base.STATUS_OK}
About the simplest problem you could ask for: optimize a one-variable quadratic function.
about the simplest problem you could ask for : optimize a one - variable quadratic function .
Question: What does this function do? Code: @domain_constructor(loss_target=0) def quadratic1(): return {'loss': ((hp.uniform('x', (-5), 5) - 3) ** 2), 'status': base.STATUS_OK}
null
null
null
What does this function do?
def get_module_by_usage_id(request, course_id, usage_id, disable_staff_debug_info=False, course=None): user = request.user try: course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id) usage_key = course_id.make_usage_key_from_deprecated_string(unquote_slashes(usage_id)) except InvalidKeyError: raise Http404('Invalid location') try: descriptor = modulestore().get_item(usage_key) (descriptor_orig_usage_key, descriptor_orig_version) = modulestore().get_block_original_usage(usage_key) except ItemNotFoundError: log.warn('Invalid location for course id %s: %s', usage_key.course_key, usage_key) raise Http404 tracking_context = {'module': {'display_name': descriptor.display_name_with_default_escaped, 'usage_key': unicode(descriptor.location)}} if (descriptor_orig_usage_key is not None): tracking_context['module']['original_usage_key'] = unicode(descriptor_orig_usage_key) tracking_context['module']['original_usage_version'] = unicode(descriptor_orig_version) (unused_masquerade, user) = setup_masquerade(request, course_id, has_access(user, 'staff', descriptor, course_id)) field_data_cache = FieldDataCache.cache_for_descriptor_descendents(course_id, user, descriptor) instance = get_module_for_descriptor(user, request, descriptor, field_data_cache, usage_key.course_key, disable_staff_debug_info=disable_staff_debug_info, course=course) if (instance is None): log.debug('No module %s for user %s -- access denied?', usage_key, user) raise Http404 return (instance, tracking_context)
null
null
null
Gets a module instance based on its `usage_id` in a course, for a given request/user Returns (instance, tracking_context)
pcsd
def get module by usage id request course id usage id disable staff debug info=False course=None user = request user try course id = Slash Separated Course Key from deprecated string course id usage key = course id make usage key from deprecated string unquote slashes usage id except Invalid Key Error raise Http404 'Invalid location' try descriptor = modulestore get item usage key descriptor orig usage key descriptor orig version = modulestore get block original usage usage key except Item Not Found Error log warn 'Invalid location for course id %s %s' usage key course key usage key raise Http404 tracking context = {'module' {'display name' descriptor display name with default escaped 'usage key' unicode descriptor location }} if descriptor orig usage key is not None tracking context['module']['original usage key'] = unicode descriptor orig usage key tracking context['module']['original usage version'] = unicode descriptor orig version unused masquerade user = setup masquerade request course id has access user 'staff' descriptor course id field data cache = Field Data Cache cache for descriptor descendents course id user descriptor instance = get module for descriptor user request descriptor field data cache usage key course key disable staff debug info=disable staff debug info course=course if instance is None log debug 'No module %s for user %s -- access denied?' usage key user raise Http404 return instance tracking context
7750
def get_module_by_usage_id(request, course_id, usage_id, disable_staff_debug_info=False, course=None): user = request.user try: course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id) usage_key = course_id.make_usage_key_from_deprecated_string(unquote_slashes(usage_id)) except InvalidKeyError: raise Http404('Invalid location') try: descriptor = modulestore().get_item(usage_key) (descriptor_orig_usage_key, descriptor_orig_version) = modulestore().get_block_original_usage(usage_key) except ItemNotFoundError: log.warn('Invalid location for course id %s: %s', usage_key.course_key, usage_key) raise Http404 tracking_context = {'module': {'display_name': descriptor.display_name_with_default_escaped, 'usage_key': unicode(descriptor.location)}} if (descriptor_orig_usage_key is not None): tracking_context['module']['original_usage_key'] = unicode(descriptor_orig_usage_key) tracking_context['module']['original_usage_version'] = unicode(descriptor_orig_version) (unused_masquerade, user) = setup_masquerade(request, course_id, has_access(user, 'staff', descriptor, course_id)) field_data_cache = FieldDataCache.cache_for_descriptor_descendents(course_id, user, descriptor) instance = get_module_for_descriptor(user, request, descriptor, field_data_cache, usage_key.course_key, disable_staff_debug_info=disable_staff_debug_info, course=course) if (instance is None): log.debug('No module %s for user %s -- access denied?', usage_key, user) raise Http404 return (instance, tracking_context)
Gets a module instance based on its `usage_id` in a course, for a given request/user Returns (instance, tracking_context)
gets a module instance based on its usage _ id in a course , for a given request / user
Question: What does this function do? Code: def get_module_by_usage_id(request, course_id, usage_id, disable_staff_debug_info=False, course=None): user = request.user try: course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id) usage_key = course_id.make_usage_key_from_deprecated_string(unquote_slashes(usage_id)) except InvalidKeyError: raise Http404('Invalid location') try: descriptor = modulestore().get_item(usage_key) (descriptor_orig_usage_key, descriptor_orig_version) = modulestore().get_block_original_usage(usage_key) except ItemNotFoundError: log.warn('Invalid location for course id %s: %s', usage_key.course_key, usage_key) raise Http404 tracking_context = {'module': {'display_name': descriptor.display_name_with_default_escaped, 'usage_key': unicode(descriptor.location)}} if (descriptor_orig_usage_key is not None): tracking_context['module']['original_usage_key'] = unicode(descriptor_orig_usage_key) tracking_context['module']['original_usage_version'] = unicode(descriptor_orig_version) (unused_masquerade, user) = setup_masquerade(request, course_id, has_access(user, 'staff', descriptor, course_id)) field_data_cache = FieldDataCache.cache_for_descriptor_descendents(course_id, user, descriptor) instance = get_module_for_descriptor(user, request, descriptor, field_data_cache, usage_key.course_key, disable_staff_debug_info=disable_staff_debug_info, course=course) if (instance is None): log.debug('No module %s for user %s -- access denied?', usage_key, user) raise Http404 return (instance, tracking_context)
null
null
null
What does this function do?
def is_valid_dot_atom(value): return (isinstance(value, six.string_types) and (not (value[0] == '.')) and (not (value[(-1)] == '.')) and set(value).issubset(valid_dot_atom_characters))
null
null
null
Validate an input string as an RFC 2822 dot-atom-text value.
pcsd
def is valid dot atom value return isinstance value six string types and not value[0] == ' ' and not value[ -1 ] == ' ' and set value issubset valid dot atom characters
7756
def is_valid_dot_atom(value): return (isinstance(value, six.string_types) and (not (value[0] == '.')) and (not (value[(-1)] == '.')) and set(value).issubset(valid_dot_atom_characters))
Validate an input string as an RFC 2822 dot-atom-text value.
validate an input string as an rfc 2822 dot - atom - text value .
Question: What does this function do? Code: def is_valid_dot_atom(value): return (isinstance(value, six.string_types) and (not (value[0] == '.')) and (not (value[(-1)] == '.')) and set(value).issubset(valid_dot_atom_characters))
null
null
null
What does this function do?
def _num_cpus_windows(): return os.environ.get('NUMBER_OF_PROCESSORS')
null
null
null
Return the number of active CPUs on a Windows system.
pcsd
def num cpus windows return os environ get 'NUMBER OF PROCESSORS'
7762
def _num_cpus_windows(): return os.environ.get('NUMBER_OF_PROCESSORS')
Return the number of active CPUs on a Windows system.
return the number of active cpus on a windows system .
Question: What does this function do? Code: def _num_cpus_windows(): return os.environ.get('NUMBER_OF_PROCESSORS')
null
null
null
What does this function do?
def wrap_socket(socket, domain, ca_crt, ca_key, ca_pass, certs_folder, success=None, failure=None, io=None, **options): options.setdefault('do_handshake_on_connect', False) options.setdefault('ssl_version', ssl.PROTOCOL_SSLv23) options.setdefault('server_side', True) if (domain.count('.') >= 3): (key, cert) = gen_signed_cert(('*.' + '.'.join(domain.split('.')[(-3):])), ca_crt, ca_key, ca_pass, certs_folder) else: (key, cert) = gen_signed_cert(domain, ca_crt, ca_key, ca_pass, certs_folder) options.setdefault('certfile', cert) options.setdefault('keyfile', key) def done(): 'Handshake finished successfully.' io.remove_handler(wrapped.fileno()) (success and success(wrapped)) def error(): 'The handshake failed.' if failure: return failure(wrapped) io.remove_handler(wrapped.fileno()) wrapped.close() def handshake(fd, events): "Handler fGetting the same error here... also looking for answers....\n TheHippo Dec 19 '12 at 20:29or SSL handshake negotiation.\n See Python docs for ssl.do_handshake()." if (events & io.ERROR): error() return try: new_state = io.ERROR wrapped.do_handshake() return done() except ssl.SSLError as exc: if (exc.args[0] == ssl.SSL_ERROR_WANT_READ): new_state |= io.READ elif (exc.args[0] == ssl.SSL_ERROR_WANT_WRITE): new_state |= io.WRITE else: raise if (new_state != state[0]): state[0] = new_state io.update_handler(fd, new_state) io = (io or ioloop.IOLoop.instance()) state = [io.ERROR] io.remove_handler(socket.fileno()) wrapped = ssl.SSLSocket(socket, **options) wrapped.setblocking(0) io.add_handler(wrapped.fileno(), handshake, state[0]) handshake(wrapped.fileno(), 0) return wrapped
null
null
null
Wrap an active socket in an SSL socket.
pcsd
def wrap socket socket domain ca crt ca key ca pass certs folder success=None failure=None io=None **options options setdefault 'do handshake on connect' False options setdefault 'ssl version' ssl PROTOCOL SS Lv23 options setdefault 'server side' True if domain count ' ' >= 3 key cert = gen signed cert '* ' + ' ' join domain split ' ' [ -3 ] ca crt ca key ca pass certs folder else key cert = gen signed cert domain ca crt ca key ca pass certs folder options setdefault 'certfile' cert options setdefault 'keyfile' key def done 'Handshake finished successfully ' io remove handler wrapped fileno success and success wrapped def error 'The handshake failed ' if failure return failure wrapped io remove handler wrapped fileno wrapped close def handshake fd events "Handler f Getting the same error here also looking for answers The Hippo Dec 19 '12 at 20 29or SSL handshake negotiation See Python docs for ssl do handshake " if events & io ERROR error return try new state = io ERROR wrapped do handshake return done except ssl SSL Error as exc if exc args[0] == ssl SSL ERROR WANT READ new state |= io READ elif exc args[0] == ssl SSL ERROR WANT WRITE new state |= io WRITE else raise if new state != state[0] state[0] = new state io update handler fd new state io = io or ioloop IO Loop instance state = [io ERROR] io remove handler socket fileno wrapped = ssl SSL Socket socket **options wrapped setblocking 0 io add handler wrapped fileno handshake state[0] handshake wrapped fileno 0 return wrapped
7778
def wrap_socket(socket, domain, ca_crt, ca_key, ca_pass, certs_folder, success=None, failure=None, io=None, **options): options.setdefault('do_handshake_on_connect', False) options.setdefault('ssl_version', ssl.PROTOCOL_SSLv23) options.setdefault('server_side', True) if (domain.count('.') >= 3): (key, cert) = gen_signed_cert(('*.' + '.'.join(domain.split('.')[(-3):])), ca_crt, ca_key, ca_pass, certs_folder) else: (key, cert) = gen_signed_cert(domain, ca_crt, ca_key, ca_pass, certs_folder) options.setdefault('certfile', cert) options.setdefault('keyfile', key) def done(): 'Handshake finished successfully.' io.remove_handler(wrapped.fileno()) (success and success(wrapped)) def error(): 'The handshake failed.' if failure: return failure(wrapped) io.remove_handler(wrapped.fileno()) wrapped.close() def handshake(fd, events): "Handler fGetting the same error here... also looking for answers....\n TheHippo Dec 19 '12 at 20:29or SSL handshake negotiation.\n See Python docs for ssl.do_handshake()." if (events & io.ERROR): error() return try: new_state = io.ERROR wrapped.do_handshake() return done() except ssl.SSLError as exc: if (exc.args[0] == ssl.SSL_ERROR_WANT_READ): new_state |= io.READ elif (exc.args[0] == ssl.SSL_ERROR_WANT_WRITE): new_state |= io.WRITE else: raise if (new_state != state[0]): state[0] = new_state io.update_handler(fd, new_state) io = (io or ioloop.IOLoop.instance()) state = [io.ERROR] io.remove_handler(socket.fileno()) wrapped = ssl.SSLSocket(socket, **options) wrapped.setblocking(0) io.add_handler(wrapped.fileno(), handshake, state[0]) handshake(wrapped.fileno(), 0) return wrapped
Wrap an active socket in an SSL socket.
wrap an active socket in an ssl socket .
Question: What does this function do? Code: def wrap_socket(socket, domain, ca_crt, ca_key, ca_pass, certs_folder, success=None, failure=None, io=None, **options): options.setdefault('do_handshake_on_connect', False) options.setdefault('ssl_version', ssl.PROTOCOL_SSLv23) options.setdefault('server_side', True) if (domain.count('.') >= 3): (key, cert) = gen_signed_cert(('*.' + '.'.join(domain.split('.')[(-3):])), ca_crt, ca_key, ca_pass, certs_folder) else: (key, cert) = gen_signed_cert(domain, ca_crt, ca_key, ca_pass, certs_folder) options.setdefault('certfile', cert) options.setdefault('keyfile', key) def done(): 'Handshake finished successfully.' io.remove_handler(wrapped.fileno()) (success and success(wrapped)) def error(): 'The handshake failed.' if failure: return failure(wrapped) io.remove_handler(wrapped.fileno()) wrapped.close() def handshake(fd, events): "Handler fGetting the same error here... also looking for answers....\n TheHippo Dec 19 '12 at 20:29or SSL handshake negotiation.\n See Python docs for ssl.do_handshake()." if (events & io.ERROR): error() return try: new_state = io.ERROR wrapped.do_handshake() return done() except ssl.SSLError as exc: if (exc.args[0] == ssl.SSL_ERROR_WANT_READ): new_state |= io.READ elif (exc.args[0] == ssl.SSL_ERROR_WANT_WRITE): new_state |= io.WRITE else: raise if (new_state != state[0]): state[0] = new_state io.update_handler(fd, new_state) io = (io or ioloop.IOLoop.instance()) state = [io.ERROR] io.remove_handler(socket.fileno()) wrapped = ssl.SSLSocket(socket, **options) wrapped.setblocking(0) io.add_handler(wrapped.fileno(), handshake, state[0]) handshake(wrapped.fileno(), 0) return wrapped
null
null
null
What does this function do?
def drain_consumer(consumer, limit=1, timeout=None, callbacks=None): acc = deque() def on_message(body, message): acc.append((body, message)) consumer.callbacks = ([on_message] + (callbacks or [])) with consumer: for _ in eventloop(consumer.channel.connection.client, limit=limit, timeout=timeout, ignore_timeouts=True): try: (yield acc.popleft()) except IndexError: pass
null
null
null
Drain messages from consumer instance.
pcsd
def drain consumer consumer limit=1 timeout=None callbacks=None acc = deque def on message body message acc append body message consumer callbacks = [on message] + callbacks or [] with consumer for in eventloop consumer channel connection client limit=limit timeout=timeout ignore timeouts=True try yield acc popleft except Index Error pass
7781
def drain_consumer(consumer, limit=1, timeout=None, callbacks=None): acc = deque() def on_message(body, message): acc.append((body, message)) consumer.callbacks = ([on_message] + (callbacks or [])) with consumer: for _ in eventloop(consumer.channel.connection.client, limit=limit, timeout=timeout, ignore_timeouts=True): try: (yield acc.popleft()) except IndexError: pass
Drain messages from consumer instance.
drain messages from consumer instance .
Question: What does this function do? Code: def drain_consumer(consumer, limit=1, timeout=None, callbacks=None): acc = deque() def on_message(body, message): acc.append((body, message)) consumer.callbacks = ([on_message] + (callbacks or [])) with consumer: for _ in eventloop(consumer.channel.connection.client, limit=limit, timeout=timeout, ignore_timeouts=True): try: (yield acc.popleft()) except IndexError: pass
null
null
null
What does this function do?
@contextfilter def group_by_letter(context, object_list): res = {} for x in object_list: r = re.search('^[a-zA-Z]', x.name) if r: key = r.group().lower() if (key not in res): res[key] = [x] else: res[key].append(x) n = re.search('^[0-9_]', x.name) if n: if ('#' not in res): res['#'] = [x] else: res['#'].append(x) if ((not n) and (not r)): if ('#' not in res): res['#'] = [x] else: res['#'].append(x) l = [] for (k, v) in res.items(): l.append((k, v)) l.sort(cmp=(lambda x, y: cmp(x, y))) return l
null
null
null
Group contacts by letter
pcsd
@contextfilter def group by letter context object list res = {} for x in object list r = re search '^[a-z A-Z]' x name if r key = r group lower if key not in res res[key] = [x] else res[key] append x n = re search '^[0-9 ]' x name if n if '#' not in res res['#'] = [x] else res['#'] append x if not n and not r if '#' not in res res['#'] = [x] else res['#'] append x l = [] for k v in res items l append k v l sort cmp= lambda x y cmp x y return l
7782
@contextfilter def group_by_letter(context, object_list): res = {} for x in object_list: r = re.search('^[a-zA-Z]', x.name) if r: key = r.group().lower() if (key not in res): res[key] = [x] else: res[key].append(x) n = re.search('^[0-9_]', x.name) if n: if ('#' not in res): res['#'] = [x] else: res['#'].append(x) if ((not n) and (not r)): if ('#' not in res): res['#'] = [x] else: res['#'].append(x) l = [] for (k, v) in res.items(): l.append((k, v)) l.sort(cmp=(lambda x, y: cmp(x, y))) return l
Group contacts by letter
group contacts by letter
Question: What does this function do? Code: @contextfilter def group_by_letter(context, object_list): res = {} for x in object_list: r = re.search('^[a-zA-Z]', x.name) if r: key = r.group().lower() if (key not in res): res[key] = [x] else: res[key].append(x) n = re.search('^[0-9_]', x.name) if n: if ('#' not in res): res['#'] = [x] else: res['#'].append(x) if ((not n) and (not r)): if ('#' not in res): res['#'] = [x] else: res['#'].append(x) l = [] for (k, v) in res.items(): l.append((k, v)) l.sort(cmp=(lambda x, y: cmp(x, y))) return l
null
null
null
What does this function do?
def read_forward_solution_eeg(*args, **kwargs): fwd = read_forward_solution(*args, **kwargs) fwd = pick_types_forward(fwd, meg=False, eeg=True) return fwd
null
null
null
Read EEG forward.
pcsd
def read forward solution eeg *args **kwargs fwd = read forward solution *args **kwargs fwd = pick types forward fwd meg=False eeg=True return fwd
7790
def read_forward_solution_eeg(*args, **kwargs): fwd = read_forward_solution(*args, **kwargs) fwd = pick_types_forward(fwd, meg=False, eeg=True) return fwd
Read EEG forward.
read eeg forward .
Question: What does this function do? Code: def read_forward_solution_eeg(*args, **kwargs): fwd = read_forward_solution(*args, **kwargs) fwd = pick_types_forward(fwd, meg=False, eeg=True) return fwd
null
null
null
What does this function do?
def append_period(text): if (text[(-1)] == '"'): return (text[0:(-1)] + '."') return text
null
null
null
Append a period at the end of the sentence
pcsd
def append period text if text[ -1 ] == '"' return text[0 -1 ] + ' "' return text
7803
def append_period(text): if (text[(-1)] == '"'): return (text[0:(-1)] + '."') return text
Append a period at the end of the sentence
append a period at the end of the sentence
Question: What does this function do? Code: def append_period(text): if (text[(-1)] == '"'): return (text[0:(-1)] + '."') return text
null
null
null
What does this function do?
def parse(tmpl_str): validate_template_limit(six.text_type(tmpl_str)) tpl = simple_parse(tmpl_str) if (not (('HeatTemplateFormatVersion' in tpl) or ('heat_template_version' in tpl) or ('AWSTemplateFormatVersion' in tpl))): raise ValueError(_('Template format version not found.')) return tpl
null
null
null
Takes a string and returns a dict containing the parsed structure. This includes determination of whether the string is using the JSON or YAML format.
pcsd
def parse tmpl str validate template limit six text type tmpl str tpl = simple parse tmpl str if not 'Heat Template Format Version' in tpl or 'heat template version' in tpl or 'AWS Template Format Version' in tpl raise Value Error 'Template format version not found ' return tpl
7808
def parse(tmpl_str): validate_template_limit(six.text_type(tmpl_str)) tpl = simple_parse(tmpl_str) if (not (('HeatTemplateFormatVersion' in tpl) or ('heat_template_version' in tpl) or ('AWSTemplateFormatVersion' in tpl))): raise ValueError(_('Template format version not found.')) return tpl
Takes a string and returns a dict containing the parsed structure. This includes determination of whether the string is using the JSON or YAML format.
takes a string and returns a dict containing the parsed structure .
Question: What does this function do? Code: def parse(tmpl_str): validate_template_limit(six.text_type(tmpl_str)) tpl = simple_parse(tmpl_str) if (not (('HeatTemplateFormatVersion' in tpl) or ('heat_template_version' in tpl) or ('AWSTemplateFormatVersion' in tpl))): raise ValueError(_('Template format version not found.')) return tpl
null
null
null
What does this function do?
def filter(names, pat): import os, posixpath result = [] pat = os.path.normcase(pat) try: re_pat = _cache[pat] except KeyError: res = translate(pat) if (len(_cache) >= _MAXCACHE): _cache.clear() _cache[pat] = re_pat = re.compile(res) match = re_pat.match if (os.path is posixpath): for name in names: if match(name): result.append(name) else: for name in names: if match(os.path.normcase(name)): result.append(name) return result
null
null
null
Return the subset of the list NAMES that match PAT
pcsd
def filter names pat import os posixpath result = [] pat = os path normcase pat try re pat = cache[pat] except Key Error res = translate pat if len cache >= MAXCACHE cache clear cache[pat] = re pat = re compile res match = re pat match if os path is posixpath for name in names if match name result append name else for name in names if match os path normcase name result append name return result
7818
def filter(names, pat): import os, posixpath result = [] pat = os.path.normcase(pat) try: re_pat = _cache[pat] except KeyError: res = translate(pat) if (len(_cache) >= _MAXCACHE): _cache.clear() _cache[pat] = re_pat = re.compile(res) match = re_pat.match if (os.path is posixpath): for name in names: if match(name): result.append(name) else: for name in names: if match(os.path.normcase(name)): result.append(name) return result
Return the subset of the list NAMES that match PAT
return the subset of the list names that match pat
Question: What does this function do? Code: def filter(names, pat): import os, posixpath result = [] pat = os.path.normcase(pat) try: re_pat = _cache[pat] except KeyError: res = translate(pat) if (len(_cache) >= _MAXCACHE): _cache.clear() _cache[pat] = re_pat = re.compile(res) match = re_pat.match if (os.path is posixpath): for name in names: if match(name): result.append(name) else: for name in names: if match(os.path.normcase(name)): result.append(name) return result
null
null
null
What does this function do?
def md5sum(filename, use_sudo=False): func = ((use_sudo and run_as_root) or run) with settings(hide('running', 'stdout', 'stderr', 'warnings'), warn_only=True): if exists(u'/usr/bin/md5sum'): res = func((u'/usr/bin/md5sum %(filename)s' % locals())) elif exists(u'/sbin/md5'): res = func((u'/sbin/md5 -r %(filename)s' % locals())) elif exists(u'/opt/local/gnu/bin/md5sum'): res = func((u'/opt/local/gnu/bin/md5sum %(filename)s' % locals())) elif exists(u'/opt/local/bin/md5sum'): res = func((u'/opt/local/bin/md5sum %(filename)s' % locals())) else: md5sum = func(u'which md5sum') md5 = func(u'which md5') if exists(md5sum): res = func(('%(md5sum)s %(filename)s' % locals())) elif exists(md5): res = func(('%(md5)s %(filename)s' % locals())) else: abort('No MD5 utility was found on this system.') if res.succeeded: parts = res.split() _md5sum = (((len(parts) > 0) and parts[0]) or None) else: warn(res) _md5sum = None return _md5sum
null
null
null
Compute the MD5 sum of a file.
pcsd
def md5sum filename use sudo=False func = use sudo and run as root or run with settings hide 'running' 'stdout' 'stderr' 'warnings' warn only=True if exists u'/usr/bin/md5sum' res = func u'/usr/bin/md5sum % filename s' % locals elif exists u'/sbin/md5' res = func u'/sbin/md5 -r % filename s' % locals elif exists u'/opt/local/gnu/bin/md5sum' res = func u'/opt/local/gnu/bin/md5sum % filename s' % locals elif exists u'/opt/local/bin/md5sum' res = func u'/opt/local/bin/md5sum % filename s' % locals else md5sum = func u'which md5sum' md5 = func u'which md5' if exists md5sum res = func '% md5sum s % filename s' % locals elif exists md5 res = func '% md5 s % filename s' % locals else abort 'No MD5 utility was found on this system ' if res succeeded parts = res split md5sum = len parts > 0 and parts[0] or None else warn res md5sum = None return md5sum
7820
def md5sum(filename, use_sudo=False): func = ((use_sudo and run_as_root) or run) with settings(hide('running', 'stdout', 'stderr', 'warnings'), warn_only=True): if exists(u'/usr/bin/md5sum'): res = func((u'/usr/bin/md5sum %(filename)s' % locals())) elif exists(u'/sbin/md5'): res = func((u'/sbin/md5 -r %(filename)s' % locals())) elif exists(u'/opt/local/gnu/bin/md5sum'): res = func((u'/opt/local/gnu/bin/md5sum %(filename)s' % locals())) elif exists(u'/opt/local/bin/md5sum'): res = func((u'/opt/local/bin/md5sum %(filename)s' % locals())) else: md5sum = func(u'which md5sum') md5 = func(u'which md5') if exists(md5sum): res = func(('%(md5sum)s %(filename)s' % locals())) elif exists(md5): res = func(('%(md5)s %(filename)s' % locals())) else: abort('No MD5 utility was found on this system.') if res.succeeded: parts = res.split() _md5sum = (((len(parts) > 0) and parts[0]) or None) else: warn(res) _md5sum = None return _md5sum
Compute the MD5 sum of a file.
compute the md5 sum of a file .
Question: What does this function do? Code: def md5sum(filename, use_sudo=False): func = ((use_sudo and run_as_root) or run) with settings(hide('running', 'stdout', 'stderr', 'warnings'), warn_only=True): if exists(u'/usr/bin/md5sum'): res = func((u'/usr/bin/md5sum %(filename)s' % locals())) elif exists(u'/sbin/md5'): res = func((u'/sbin/md5 -r %(filename)s' % locals())) elif exists(u'/opt/local/gnu/bin/md5sum'): res = func((u'/opt/local/gnu/bin/md5sum %(filename)s' % locals())) elif exists(u'/opt/local/bin/md5sum'): res = func((u'/opt/local/bin/md5sum %(filename)s' % locals())) else: md5sum = func(u'which md5sum') md5 = func(u'which md5') if exists(md5sum): res = func(('%(md5sum)s %(filename)s' % locals())) elif exists(md5): res = func(('%(md5)s %(filename)s' % locals())) else: abort('No MD5 utility was found on this system.') if res.succeeded: parts = res.split() _md5sum = (((len(parts) > 0) and parts[0]) or None) else: warn(res) _md5sum = None return _md5sum
null
null
null
What does this function do?
def check_token(code, tokens): lx = XonshLexer() tks = list(lx.get_tokens(code)) for tk in tokens: while tks: if (tk == tks[0]): break tks = tks[1:] else: msg = 'Token {!r} missing: {!r}'.format(tk, list(lx.get_tokens(code))) pytest.fail(msg) break
null
null
null
Make sure that all tokens appears in code in order
pcsd
def check token code tokens lx = Xonsh Lexer tks = list lx get tokens code for tk in tokens while tks if tk == tks[0] break tks = tks[1 ] else msg = 'Token {!r} missing {!r}' format tk list lx get tokens code pytest fail msg break
7825
def check_token(code, tokens): lx = XonshLexer() tks = list(lx.get_tokens(code)) for tk in tokens: while tks: if (tk == tks[0]): break tks = tks[1:] else: msg = 'Token {!r} missing: {!r}'.format(tk, list(lx.get_tokens(code))) pytest.fail(msg) break
Make sure that all tokens appears in code in order
make sure that all tokens appears in code in order
Question: What does this function do? Code: def check_token(code, tokens): lx = XonshLexer() tks = list(lx.get_tokens(code)) for tk in tokens: while tks: if (tk == tks[0]): break tks = tks[1:] else: msg = 'Token {!r} missing: {!r}'.format(tk, list(lx.get_tokens(code))) pytest.fail(msg) break
null
null
null
What does this function do?
def get_vm_size(vm_): vm_size = config.get_cloud_config_value('size', vm_, __opts__) ram = avail_sizes()[vm_size]['RAM'] if vm_size.startswith('Linode'): vm_size = vm_size.replace('Linode ', '') if (ram == int(vm_size)): return ram else: raise SaltCloudNotFound('The specified size, {0}, could not be found.'.format(vm_size))
null
null
null
Returns the VM\'s size. vm\_ The VM to get the size for.
pcsd
def get vm size vm vm size = config get cloud config value 'size' vm opts ram = avail sizes [vm size]['RAM'] if vm size startswith 'Linode' vm size = vm size replace 'Linode ' '' if ram == int vm size return ram else raise Salt Cloud Not Found 'The specified size {0} could not be found ' format vm size
7832
def get_vm_size(vm_): vm_size = config.get_cloud_config_value('size', vm_, __opts__) ram = avail_sizes()[vm_size]['RAM'] if vm_size.startswith('Linode'): vm_size = vm_size.replace('Linode ', '') if (ram == int(vm_size)): return ram else: raise SaltCloudNotFound('The specified size, {0}, could not be found.'.format(vm_size))
Returns the VM\'s size. vm\_ The VM to get the size for.
returns the vms size .
Question: What does this function do? Code: def get_vm_size(vm_): vm_size = config.get_cloud_config_value('size', vm_, __opts__) ram = avail_sizes()[vm_size]['RAM'] if vm_size.startswith('Linode'): vm_size = vm_size.replace('Linode ', '') if (ram == int(vm_size)): return ram else: raise SaltCloudNotFound('The specified size, {0}, could not be found.'.format(vm_size))
null
null
null
What does this function do?
def get_format(format_type): format_type = smart_str(format_type) if settings.USE_L10N: cache_key = (format_type, get_language()) try: return (_format_cache[cache_key] or getattr(settings, format_type)) except KeyError: for module in get_format_modules(): try: val = getattr(module, format_type) _format_cache[cache_key] = val return val except AttributeError: pass _format_cache[cache_key] = None return getattr(settings, format_type)
null
null
null
For a specific format type, returns the format for the current language (locale), defaults to the format in the settings. format_type is the name of the format, e.g. \'DATE_FORMAT\'
pcsd
def get format format type format type = smart str format type if settings USE L10N cache key = format type get language try return format cache[cache key] or getattr settings format type except Key Error for module in get format modules try val = getattr module format type format cache[cache key] = val return val except Attribute Error pass format cache[cache key] = None return getattr settings format type
7839
def get_format(format_type): format_type = smart_str(format_type) if settings.USE_L10N: cache_key = (format_type, get_language()) try: return (_format_cache[cache_key] or getattr(settings, format_type)) except KeyError: for module in get_format_modules(): try: val = getattr(module, format_type) _format_cache[cache_key] = val return val except AttributeError: pass _format_cache[cache_key] = None return getattr(settings, format_type)
For a specific format type, returns the format for the current language (locale), defaults to the format in the settings. format_type is the name of the format, e.g. \'DATE_FORMAT\'
for a specific format type , returns the format for the current language , defaults to the format in the settings .
Question: What does this function do? Code: def get_format(format_type): format_type = smart_str(format_type) if settings.USE_L10N: cache_key = (format_type, get_language()) try: return (_format_cache[cache_key] or getattr(settings, format_type)) except KeyError: for module in get_format_modules(): try: val = getattr(module, format_type) _format_cache[cache_key] = val return val except AttributeError: pass _format_cache[cache_key] = None return getattr(settings, format_type)
null
null
null
What does this function do?
def _partition_estimators(n_estimators, n_jobs): n_jobs = min(_get_n_jobs(n_jobs), n_estimators) n_estimators_per_job = ((n_estimators // n_jobs) * np.ones(n_jobs, dtype=np.int)) n_estimators_per_job[:(n_estimators % n_jobs)] += 1 starts = np.cumsum(n_estimators_per_job) return (n_jobs, n_estimators_per_job.tolist(), ([0] + starts.tolist()))
null
null
null
Private function used to partition estimators between jobs.
pcsd
def partition estimators n estimators n jobs n jobs = min get n jobs n jobs n estimators n estimators per job = n estimators // n jobs * np ones n jobs dtype=np int n estimators per job[ n estimators % n jobs ] += 1 starts = np cumsum n estimators per job return n jobs n estimators per job tolist [0] + starts tolist
7840
def _partition_estimators(n_estimators, n_jobs): n_jobs = min(_get_n_jobs(n_jobs), n_estimators) n_estimators_per_job = ((n_estimators // n_jobs) * np.ones(n_jobs, dtype=np.int)) n_estimators_per_job[:(n_estimators % n_jobs)] += 1 starts = np.cumsum(n_estimators_per_job) return (n_jobs, n_estimators_per_job.tolist(), ([0] + starts.tolist()))
Private function used to partition estimators between jobs.
private function used to partition estimators between jobs .
Question: What does this function do? Code: def _partition_estimators(n_estimators, n_jobs): n_jobs = min(_get_n_jobs(n_jobs), n_estimators) n_estimators_per_job = ((n_estimators // n_jobs) * np.ones(n_jobs, dtype=np.int)) n_estimators_per_job[:(n_estimators % n_jobs)] += 1 starts = np.cumsum(n_estimators_per_job) return (n_jobs, n_estimators_per_job.tolist(), ([0] + starts.tolist()))
null
null
null
What does this function do?
def get_user_password(): return ('root', '')
null
null
null
Returns a tuple (user, password).
pcsd
def get user password return 'root' ''
7844
def get_user_password(): return ('root', '')
Returns a tuple (user, password).
returns a tuple .
Question: What does this function do? Code: def get_user_password(): return ('root', '')
null
null
null
What does this function do?
def add_advanced_component(page, menu_index, name): page.wait_for_component_menu() click_css(page, 'button>span.large-advanced-icon', menu_index, require_notification=False) page.wait_for_element_visibility('.new-component-advanced', 'Advanced component menu is visible') component_css = 'button[data-category={}]'.format(name) page.wait_for_element_visibility(component_css, 'Advanced component {} is visible'.format(name)) click_css(page, component_css, 0)
null
null
null
Adds an instance of the advanced component with the specified name. menu_index specifies which instance of the menus should be used (based on vertical placement within the page).
pcsd
def add advanced component page menu index name page wait for component menu click css page 'button>span large-advanced-icon' menu index require notification=False page wait for element visibility ' new-component-advanced' 'Advanced component menu is visible' component css = 'button[data-category={}]' format name page wait for element visibility component css 'Advanced component {} is visible' format name click css page component css 0
7854
def add_advanced_component(page, menu_index, name): page.wait_for_component_menu() click_css(page, 'button>span.large-advanced-icon', menu_index, require_notification=False) page.wait_for_element_visibility('.new-component-advanced', 'Advanced component menu is visible') component_css = 'button[data-category={}]'.format(name) page.wait_for_element_visibility(component_css, 'Advanced component {} is visible'.format(name)) click_css(page, component_css, 0)
Adds an instance of the advanced component with the specified name. menu_index specifies which instance of the menus should be used (based on vertical placement within the page).
adds an instance of the advanced component with the specified name .
Question: What does this function do? Code: def add_advanced_component(page, menu_index, name): page.wait_for_component_menu() click_css(page, 'button>span.large-advanced-icon', menu_index, require_notification=False) page.wait_for_element_visibility('.new-component-advanced', 'Advanced component menu is visible') component_css = 'button[data-category={}]'.format(name) page.wait_for_element_visibility(component_css, 'Advanced component {} is visible'.format(name)) click_css(page, component_css, 0)
null
null
null
What does this function do?
def _add_object(obj_type, image, image2, xpos, ypos): obj_size = random.randint(8, 10) channel = random.randint(0, 2) move = random.randint(6, 10) obj = np.zeros([obj_size, obj_size, 3]) if (obj_type == 'rectangle'): xpos2 = (xpos + move) ypos2 = ypos for i in xrange(obj_size): obj[i, 0:(i + 1), channel] = [1.0 for _ in xrange((i + 1))] elif (obj_type == 'square'): xpos2 = xpos ypos2 = (ypos + move) obj[:, :, channel] = 1.0 for x in xrange(obj_size): for y in xrange(obj_size): if (obj[(x, y, channel)] == 1.0): image[((xpos + x), (ypos + y), channel)] = 1.0 image2[((xpos2 + x), (ypos2 + y), channel)] = 1.0
null
null
null
Add a moving obj to two consecutive images.
pcsd
def add object obj type image image2 xpos ypos obj size = random randint 8 10 channel = random randint 0 2 move = random randint 6 10 obj = np zeros [obj size obj size 3] if obj type == 'rectangle' xpos2 = xpos + move ypos2 = ypos for i in xrange obj size obj[i 0 i + 1 channel] = [1 0 for in xrange i + 1 ] elif obj type == 'square' xpos2 = xpos ypos2 = ypos + move obj[ channel] = 1 0 for x in xrange obj size for y in xrange obj size if obj[ x y channel ] == 1 0 image[ xpos + x ypos + y channel ] = 1 0 image2[ xpos2 + x ypos2 + y channel ] = 1 0
7858
def _add_object(obj_type, image, image2, xpos, ypos): obj_size = random.randint(8, 10) channel = random.randint(0, 2) move = random.randint(6, 10) obj = np.zeros([obj_size, obj_size, 3]) if (obj_type == 'rectangle'): xpos2 = (xpos + move) ypos2 = ypos for i in xrange(obj_size): obj[i, 0:(i + 1), channel] = [1.0 for _ in xrange((i + 1))] elif (obj_type == 'square'): xpos2 = xpos ypos2 = (ypos + move) obj[:, :, channel] = 1.0 for x in xrange(obj_size): for y in xrange(obj_size): if (obj[(x, y, channel)] == 1.0): image[((xpos + x), (ypos + y), channel)] = 1.0 image2[((xpos2 + x), (ypos2 + y), channel)] = 1.0
Add a moving obj to two consecutive images.
add a moving obj to two consecutive images .
Question: What does this function do? Code: def _add_object(obj_type, image, image2, xpos, ypos): obj_size = random.randint(8, 10) channel = random.randint(0, 2) move = random.randint(6, 10) obj = np.zeros([obj_size, obj_size, 3]) if (obj_type == 'rectangle'): xpos2 = (xpos + move) ypos2 = ypos for i in xrange(obj_size): obj[i, 0:(i + 1), channel] = [1.0 for _ in xrange((i + 1))] elif (obj_type == 'square'): xpos2 = xpos ypos2 = (ypos + move) obj[:, :, channel] = 1.0 for x in xrange(obj_size): for y in xrange(obj_size): if (obj[(x, y, channel)] == 1.0): image[((xpos + x), (ypos + y), channel)] = 1.0 image2[((xpos2 + x), (ypos2 + y), channel)] = 1.0
null
null
null
What does this function do?
def _AppendOrReturn(append, element): if ((append is not None) and (element is not None)): if (isinstance(element, list) or isinstance(element, tuple)): append.extend(element) else: append.append(element) else: return element
null
null
null
If |append| is None, simply return |element|. If |append| is not None, then add |element| to it, adding each item in |element| if it\'s a list or tuple.
pcsd
def Append Or Return append element if append is not None and element is not None if isinstance element list or isinstance element tuple append extend element else append append element else return element
7871
def _AppendOrReturn(append, element): if ((append is not None) and (element is not None)): if (isinstance(element, list) or isinstance(element, tuple)): append.extend(element) else: append.append(element) else: return element
If |append| is None, simply return |element|. If |append| is not None, then add |element| to it, adding each item in |element| if it\'s a list or tuple.
if | append | is none , simply return | element | .
Question: What does this function do? Code: def _AppendOrReturn(append, element): if ((append is not None) and (element is not None)): if (isinstance(element, list) or isinstance(element, tuple)): append.extend(element) else: append.append(element) else: return element
null
null
null
What does this function do?
@pytest.mark.parametrize(u'text,expected_tokens', [(u"l'avion", [u"l'", u'avion']), (u"j'ai", [u"j'", u'ai'])]) def test_issue768(fr_tokenizer_w_infix, text, expected_tokens): tokens = fr_tokenizer_w_infix(text) assert (len(tokens) == 2) assert ([t.text for t in tokens] == expected_tokens)
null
null
null
Allow zero-width \'infix\' token during the tokenization process.
pcsd
@pytest mark parametrize u'text expected tokens' [ u"l'avion" [u"l'" u'avion'] u"j'ai" [u"j'" u'ai'] ] def test issue768 fr tokenizer w infix text expected tokens tokens = fr tokenizer w infix text assert len tokens == 2 assert [t text for t in tokens] == expected tokens
7877
@pytest.mark.parametrize(u'text,expected_tokens', [(u"l'avion", [u"l'", u'avion']), (u"j'ai", [u"j'", u'ai'])]) def test_issue768(fr_tokenizer_w_infix, text, expected_tokens): tokens = fr_tokenizer_w_infix(text) assert (len(tokens) == 2) assert ([t.text for t in tokens] == expected_tokens)
Allow zero-width \'infix\' token during the tokenization process.
allow zero - width infix token during the tokenization process .
Question: What does this function do? Code: @pytest.mark.parametrize(u'text,expected_tokens', [(u"l'avion", [u"l'", u'avion']), (u"j'ai", [u"j'", u'ai'])]) def test_issue768(fr_tokenizer_w_infix, text, expected_tokens): tokens = fr_tokenizer_w_infix(text) assert (len(tokens) == 2) assert ([t.text for t in tokens] == expected_tokens)
null
null
null
What does this function do?
def morsel_to_cookie(morsel): c = create_cookie(name=morsel.key, value=morsel.value, version=(morsel['version'] or 0), port=None, port_specified=False, domain=morsel['domain'], domain_specified=bool(morsel['domain']), domain_initial_dot=morsel['domain'].startswith('.'), path=morsel['path'], path_specified=bool(morsel['path']), secure=bool(morsel['secure']), expires=(morsel['max-age'] or morsel['expires']), discard=False, comment=morsel['comment'], comment_url=bool(morsel['comment']), rest={'HttpOnly': morsel['httponly']}, rfc2109=False) return c
null
null
null
Convert a Morsel object into a Cookie containing the one k/v pair.
pcsd
def morsel to cookie morsel c = create cookie name=morsel key value=morsel value version= morsel['version'] or 0 port=None port specified=False domain=morsel['domain'] domain specified=bool morsel['domain'] domain initial dot=morsel['domain'] startswith ' ' path=morsel['path'] path specified=bool morsel['path'] secure=bool morsel['secure'] expires= morsel['max-age'] or morsel['expires'] discard=False comment=morsel['comment'] comment url=bool morsel['comment'] rest={'Http Only' morsel['httponly']} rfc2109=False return c
7880
def morsel_to_cookie(morsel): c = create_cookie(name=morsel.key, value=morsel.value, version=(morsel['version'] or 0), port=None, port_specified=False, domain=morsel['domain'], domain_specified=bool(morsel['domain']), domain_initial_dot=morsel['domain'].startswith('.'), path=morsel['path'], path_specified=bool(morsel['path']), secure=bool(morsel['secure']), expires=(morsel['max-age'] or morsel['expires']), discard=False, comment=morsel['comment'], comment_url=bool(morsel['comment']), rest={'HttpOnly': morsel['httponly']}, rfc2109=False) return c
Convert a Morsel object into a Cookie containing the one k/v pair.
convert a morsel object into a cookie containing the one k / v pair .
Question: What does this function do? Code: def morsel_to_cookie(morsel): c = create_cookie(name=morsel.key, value=morsel.value, version=(morsel['version'] or 0), port=None, port_specified=False, domain=morsel['domain'], domain_specified=bool(morsel['domain']), domain_initial_dot=morsel['domain'].startswith('.'), path=morsel['path'], path_specified=bool(morsel['path']), secure=bool(morsel['secure']), expires=(morsel['max-age'] or morsel['expires']), discard=False, comment=morsel['comment'], comment_url=bool(morsel['comment']), rest={'HttpOnly': morsel['httponly']}, rfc2109=False) return c
null
null
null
What does this function do?
def __virtual__(): if (not salt.utils.is_windows()): return (False, 'WUA: Only available on Window systems') if (not salt.utils.win_update.HAS_PYWIN32): return (False, 'WUA: Requires PyWin32 libraries') return __virtualname__
null
null
null
Only valid on Windows machines
pcsd
def virtual if not salt utils is windows return False 'WUA Only available on Window systems' if not salt utils win update HAS PYWIN32 return False 'WUA Requires Py Win32 libraries' return virtualname
7890
def __virtual__(): if (not salt.utils.is_windows()): return (False, 'WUA: Only available on Window systems') if (not salt.utils.win_update.HAS_PYWIN32): return (False, 'WUA: Requires PyWin32 libraries') return __virtualname__
Only valid on Windows machines
only valid on windows machines
Question: What does this function do? Code: def __virtual__(): if (not salt.utils.is_windows()): return (False, 'WUA: Only available on Window systems') if (not salt.utils.win_update.HAS_PYWIN32): return (False, 'WUA: Requires PyWin32 libraries') return __virtualname__
null
null
null
What does this function do?
def _check_second_range(sec): if np.any((sec == 60.0)): warn(IllegalSecondWarning(sec, u'Treating as 0 sec, +1 min')) elif (sec is None): pass elif (np.any((sec < (-60.0))) or np.any((sec > 60.0))): raise IllegalSecondError(sec)
null
null
null
Checks that the given value is in the range [0,60]. If the value is equal to 60, then a warning is raised.
pcsd
def check second range sec if np any sec == 60 0 warn Illegal Second Warning sec u'Treating as 0 sec +1 min' elif sec is None pass elif np any sec < -60 0 or np any sec > 60 0 raise Illegal Second Error sec
7892
def _check_second_range(sec): if np.any((sec == 60.0)): warn(IllegalSecondWarning(sec, u'Treating as 0 sec, +1 min')) elif (sec is None): pass elif (np.any((sec < (-60.0))) or np.any((sec > 60.0))): raise IllegalSecondError(sec)
Checks that the given value is in the range [0,60]. If the value is equal to 60, then a warning is raised.
checks that the given value is in the range [ 0 , 60 ] .
Question: What does this function do? Code: def _check_second_range(sec): if np.any((sec == 60.0)): warn(IllegalSecondWarning(sec, u'Treating as 0 sec, +1 min')) elif (sec is None): pass elif (np.any((sec < (-60.0))) or np.any((sec > 60.0))): raise IllegalSecondError(sec)
null
null
null
What does this function do?
@pytest.fixture def guest(): return Guest()
null
null
null
Return a guest (not logged in) user.
pcsd
@pytest fixture def guest return Guest
7898
@pytest.fixture def guest(): return Guest()
Return a guest (not logged in) user.
return a guest user .
Question: What does this function do? Code: @pytest.fixture def guest(): return Guest()
null
null
null
What does this function do?
def expect_failure_with_message(message): def test_decorator(func): def test_decorated(self, *args, **kwargs): self.assertRaisesRegexp(segmentio.EventValidationError, message, func, self, *args, **kwargs) self.assert_no_events_emitted() return test_decorated return test_decorator
null
null
null
Ensure the test raises an exception and does not emit an event
pcsd
def expect failure with message message def test decorator func def test decorated self *args **kwargs self assert Raises Regexp segmentio Event Validation Error message func self *args **kwargs self assert no events emitted return test decorated return test decorator
7902
def expect_failure_with_message(message): def test_decorator(func): def test_decorated(self, *args, **kwargs): self.assertRaisesRegexp(segmentio.EventValidationError, message, func, self, *args, **kwargs) self.assert_no_events_emitted() return test_decorated return test_decorator
Ensure the test raises an exception and does not emit an event
ensure the test raises an exception and does not emit an event
Question: What does this function do? Code: def expect_failure_with_message(message): def test_decorator(func): def test_decorated(self, *args, **kwargs): self.assertRaisesRegexp(segmentio.EventValidationError, message, func, self, *args, **kwargs) self.assert_no_events_emitted() return test_decorated return test_decorator
null
null
null
What does this function do?
def energy(H, q, p): return (H.pot.energy(p) - H.logp(q))
null
null
null
Compute the total energy for the Hamiltonian at a given position/momentum
pcsd
def energy H q p return H pot energy p - H logp q
7904
def energy(H, q, p): return (H.pot.energy(p) - H.logp(q))
Compute the total energy for the Hamiltonian at a given position/momentum
compute the total energy for the hamiltonian at a given position / momentum
Question: What does this function do? Code: def energy(H, q, p): return (H.pot.energy(p) - H.logp(q))
null
null
null
What does this function do?
def escape(s): return urllib.quote(s, safe='~')
null
null
null
Escape a URL including any /.
pcsd
def escape s return urllib quote s safe='~'
7908
def escape(s): return urllib.quote(s, safe='~')
Escape a URL including any /.
escape a url including any / .
Question: What does this function do? Code: def escape(s): return urllib.quote(s, safe='~')
null
null
null
What does this function do?
def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None, symlinks=False, ignore_patterns=[]): from google.appengine._internal.django.conf import settings if settings.configured: settings.USE_I18N = True else: settings.configure(USE_I18N=True) from google.appengine._internal.django.utils.translation import templatize invoked_for_django = False if os.path.isdir(os.path.join('conf', 'locale')): localedir = os.path.abspath(os.path.join('conf', 'locale')) invoked_for_django = True elif os.path.isdir('locale'): localedir = os.path.abspath('locale') else: raise CommandError('This script should be run from the Django SVN tree or your project or app tree. If you did indeed run it from the SVN checkout or your project or application, maybe you are just missing the conf/locale (in the django tree) or locale (for project and application) directory? It is not created automatically, you have to create it by hand if you want to enable i18n for your project or application.') if (domain not in ('django', 'djangojs')): raise CommandError("currently makemessages only supports domains 'django' and 'djangojs'") if (((locale is None) and (not all)) or (domain is None)): if (not sys.argv[0].endswith('make-messages.py')): message = ("Type '%s help %s' for usage.\n" % (os.path.basename(sys.argv[0]), sys.argv[1])) else: message = 'usage: make-messages.py -l <language>\n or: make-messages.py -a\n' raise CommandError(message) output = _popen('xgettext --version')[0] match = re.search('(?P<major>\\d+)\\.(?P<minor>\\d+)', output) if match: xversion = (int(match.group('major')), int(match.group('minor'))) if (xversion < (0, 15)): raise CommandError(('Django internationalization requires GNU gettext 0.15 or newer. You are using version %s, please upgrade your gettext toolset.' % match.group())) languages = [] if (locale is not None): languages.append(locale) elif all: locale_dirs = filter(os.path.isdir, glob.glob(('%s/*' % localedir))) languages = [os.path.basename(l) for l in locale_dirs] for locale in languages: if (verbosity > 0): print 'processing language', locale basedir = os.path.join(localedir, locale, 'LC_MESSAGES') if (not os.path.isdir(basedir)): os.makedirs(basedir) pofile = os.path.join(basedir, ('%s.po' % domain)) potfile = os.path.join(basedir, ('%s.pot' % domain)) if os.path.exists(potfile): os.unlink(potfile) for (dirpath, file) in find_files('.', ignore_patterns, verbosity, symlinks=symlinks): (file_base, file_ext) = os.path.splitext(file) if ((domain == 'djangojs') and (file_ext in extensions)): if (verbosity > 1): sys.stdout.write(('processing file %s in %s\n' % (file, dirpath))) src = open(os.path.join(dirpath, file), 'rU').read() src = pythonize_re.sub('\n#', src) thefile = ('%s.py' % file) f = open(os.path.join(dirpath, thefile), 'w') try: f.write(src) finally: f.close() cmd = ('xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))) (msgs, errors) = _popen(cmd) if errors: raise CommandError(('errors happened while running xgettext on %s\n%s' % (file, errors))) old = ('#: ' + os.path.join(dirpath, thefile)[2:]) new = ('#: ' + os.path.join(dirpath, file)[2:]) msgs = msgs.replace(old, new) if os.path.exists(potfile): msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) else: msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') if msgs: f = open(potfile, 'ab') try: f.write(msgs) finally: f.close() os.unlink(os.path.join(dirpath, thefile)) elif ((domain == 'django') and ((file_ext == '.py') or (file_ext in extensions))): thefile = file if (file_ext in extensions): src = open(os.path.join(dirpath, file), 'rU').read() thefile = ('%s.py' % file) try: f = open(os.path.join(dirpath, thefile), 'w') try: f.write(templatize(src)) finally: f.close() except SyntaxError as msg: msg = ('%s (file: %s)' % (msg, os.path.join(dirpath, file))) raise SyntaxError(msg) if (verbosity > 1): sys.stdout.write(('processing file %s in %s\n' % (file, dirpath))) cmd = ('xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))) (msgs, errors) = _popen(cmd) if errors: raise CommandError(('errors happened while running xgettext on %s\n%s' % (file, errors))) if (thefile != file): old = ('#: ' + os.path.join(dirpath, thefile)[2:]) new = ('#: ' + os.path.join(dirpath, file)[2:]) msgs = msgs.replace(old, new) if os.path.exists(potfile): msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) else: msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') if msgs: f = open(potfile, 'ab') try: f.write(msgs) finally: f.close() if (thefile != file): os.unlink(os.path.join(dirpath, thefile)) if os.path.exists(potfile): (msgs, errors) = _popen(('msguniq --to-code=utf-8 "%s"' % potfile)) if errors: raise CommandError(('errors happened while running msguniq\n%s' % errors)) f = open(potfile, 'w') try: f.write(msgs) finally: f.close() if os.path.exists(pofile): (msgs, errors) = _popen(('msgmerge -q "%s" "%s"' % (pofile, potfile))) if errors: raise CommandError(('errors happened while running msgmerge\n%s' % errors)) elif (not invoked_for_django): msgs = copy_plural_forms(msgs, locale, domain, verbosity) f = open(pofile, 'wb') try: f.write(msgs) finally: f.close() os.unlink(potfile)
null
null
null
Uses the locale directory from the Django SVN tree or an application/ project to process all
pcsd
def make messages locale=None domain='django' verbosity='1' all=False extensions=None symlinks=False ignore patterns=[] from google appengine internal django conf import settings if settings configured settings USE I18N = True else settings configure USE I18N=True from google appengine internal django utils translation import templatize invoked for django = False if os path isdir os path join 'conf' 'locale' localedir = os path abspath os path join 'conf' 'locale' invoked for django = True elif os path isdir 'locale' localedir = os path abspath 'locale' else raise Command Error 'This script should be run from the Django SVN tree or your project or app tree If you did indeed run it from the SVN checkout or your project or application maybe you are just missing the conf/locale in the django tree or locale for project and application directory? It is not created automatically you have to create it by hand if you want to enable i18n for your project or application ' if domain not in 'django' 'djangojs' raise Command Error "currently makemessages only supports domains 'django' and 'djangojs'" if locale is None and not all or domain is None if not sys argv[0] endswith 'make-messages py' message = "Type '%s help %s' for usage " % os path basename sys argv[0] sys argv[1] else message = 'usage make-messages py -l <language> or make-messages py -a ' raise Command Error message output = popen 'xgettext --version' [0] match = re search ' ?P<major>\\d+ \\ ?P<minor>\\d+ ' output if match xversion = int match group 'major' int match group 'minor' if xversion < 0 15 raise Command Error 'Django internationalization requires GNU gettext 0 15 or newer You are using version %s please upgrade your gettext toolset ' % match group languages = [] if locale is not None languages append locale elif all locale dirs = filter os path isdir glob glob '%s/*' % localedir languages = [os path basename l for l in locale dirs] for locale in languages if verbosity > 0 print 'processing language' locale basedir = os path join localedir locale 'LC MESSAGES' if not os path isdir basedir os makedirs basedir pofile = os path join basedir '%s po' % domain potfile = os path join basedir '%s pot' % domain if os path exists potfile os unlink potfile for dirpath file in find files ' ' ignore patterns verbosity symlinks=symlinks file base file ext = os path splitext file if domain == 'djangojs' and file ext in extensions if verbosity > 1 sys stdout write 'processing file %s in %s ' % file dirpath src = open os path join dirpath file 'r U' read src = pythonize re sub ' #' src thefile = '%s py' % file f = open os path join dirpath thefile 'w' try f write src finally f close cmd = 'xgettext -d %s -L Perl --keyword=gettext noop --keyword=gettext lazy --keyword=ngettext lazy 1 2 --from-code UTF-8 -o - "%s"' % domain os path join dirpath thefile msgs errors = popen cmd if errors raise Command Error 'errors happened while running xgettext on %s %s' % file errors old = '# ' + os path join dirpath thefile [2 ] new = '# ' + os path join dirpath file [2 ] msgs = msgs replace old new if os path exists potfile msgs = ' ' join dropwhile len msgs split ' ' else msgs = msgs replace 'charset=CHARSET' 'charset=UTF-8' if msgs f = open potfile 'ab' try f write msgs finally f close os unlink os path join dirpath thefile elif domain == 'django' and file ext == ' py' or file ext in extensions thefile = file if file ext in extensions src = open os path join dirpath file 'r U' read thefile = '%s py' % file try f = open os path join dirpath thefile 'w' try f write templatize src finally f close except Syntax Error as msg msg = '%s file %s ' % msg os path join dirpath file raise Syntax Error msg if verbosity > 1 sys stdout write 'processing file %s in %s ' % file dirpath cmd = 'xgettext -d %s -L Python --keyword=gettext noop --keyword=gettext lazy --keyword=ngettext lazy 1 2 --keyword=ugettext noop --keyword=ugettext lazy --keyword=ungettext lazy 1 2 --from-code UTF-8 -o - "%s"' % domain os path join dirpath thefile msgs errors = popen cmd if errors raise Command Error 'errors happened while running xgettext on %s %s' % file errors if thefile != file old = '# ' + os path join dirpath thefile [2 ] new = '# ' + os path join dirpath file [2 ] msgs = msgs replace old new if os path exists potfile msgs = ' ' join dropwhile len msgs split ' ' else msgs = msgs replace 'charset=CHARSET' 'charset=UTF-8' if msgs f = open potfile 'ab' try f write msgs finally f close if thefile != file os unlink os path join dirpath thefile if os path exists potfile msgs errors = popen 'msguniq --to-code=utf-8 "%s"' % potfile if errors raise Command Error 'errors happened while running msguniq %s' % errors f = open potfile 'w' try f write msgs finally f close if os path exists pofile msgs errors = popen 'msgmerge -q "%s" "%s"' % pofile potfile if errors raise Command Error 'errors happened while running msgmerge %s' % errors elif not invoked for django msgs = copy plural forms msgs locale domain verbosity f = open pofile 'wb' try f write msgs finally f close os unlink potfile
7910
def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None, symlinks=False, ignore_patterns=[]): from google.appengine._internal.django.conf import settings if settings.configured: settings.USE_I18N = True else: settings.configure(USE_I18N=True) from google.appengine._internal.django.utils.translation import templatize invoked_for_django = False if os.path.isdir(os.path.join('conf', 'locale')): localedir = os.path.abspath(os.path.join('conf', 'locale')) invoked_for_django = True elif os.path.isdir('locale'): localedir = os.path.abspath('locale') else: raise CommandError('This script should be run from the Django SVN tree or your project or app tree. If you did indeed run it from the SVN checkout or your project or application, maybe you are just missing the conf/locale (in the django tree) or locale (for project and application) directory? It is not created automatically, you have to create it by hand if you want to enable i18n for your project or application.') if (domain not in ('django', 'djangojs')): raise CommandError("currently makemessages only supports domains 'django' and 'djangojs'") if (((locale is None) and (not all)) or (domain is None)): if (not sys.argv[0].endswith('make-messages.py')): message = ("Type '%s help %s' for usage.\n" % (os.path.basename(sys.argv[0]), sys.argv[1])) else: message = 'usage: make-messages.py -l <language>\n or: make-messages.py -a\n' raise CommandError(message) output = _popen('xgettext --version')[0] match = re.search('(?P<major>\\d+)\\.(?P<minor>\\d+)', output) if match: xversion = (int(match.group('major')), int(match.group('minor'))) if (xversion < (0, 15)): raise CommandError(('Django internationalization requires GNU gettext 0.15 or newer. You are using version %s, please upgrade your gettext toolset.' % match.group())) languages = [] if (locale is not None): languages.append(locale) elif all: locale_dirs = filter(os.path.isdir, glob.glob(('%s/*' % localedir))) languages = [os.path.basename(l) for l in locale_dirs] for locale in languages: if (verbosity > 0): print 'processing language', locale basedir = os.path.join(localedir, locale, 'LC_MESSAGES') if (not os.path.isdir(basedir)): os.makedirs(basedir) pofile = os.path.join(basedir, ('%s.po' % domain)) potfile = os.path.join(basedir, ('%s.pot' % domain)) if os.path.exists(potfile): os.unlink(potfile) for (dirpath, file) in find_files('.', ignore_patterns, verbosity, symlinks=symlinks): (file_base, file_ext) = os.path.splitext(file) if ((domain == 'djangojs') and (file_ext in extensions)): if (verbosity > 1): sys.stdout.write(('processing file %s in %s\n' % (file, dirpath))) src = open(os.path.join(dirpath, file), 'rU').read() src = pythonize_re.sub('\n#', src) thefile = ('%s.py' % file) f = open(os.path.join(dirpath, thefile), 'w') try: f.write(src) finally: f.close() cmd = ('xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))) (msgs, errors) = _popen(cmd) if errors: raise CommandError(('errors happened while running xgettext on %s\n%s' % (file, errors))) old = ('#: ' + os.path.join(dirpath, thefile)[2:]) new = ('#: ' + os.path.join(dirpath, file)[2:]) msgs = msgs.replace(old, new) if os.path.exists(potfile): msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) else: msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') if msgs: f = open(potfile, 'ab') try: f.write(msgs) finally: f.close() os.unlink(os.path.join(dirpath, thefile)) elif ((domain == 'django') and ((file_ext == '.py') or (file_ext in extensions))): thefile = file if (file_ext in extensions): src = open(os.path.join(dirpath, file), 'rU').read() thefile = ('%s.py' % file) try: f = open(os.path.join(dirpath, thefile), 'w') try: f.write(templatize(src)) finally: f.close() except SyntaxError as msg: msg = ('%s (file: %s)' % (msg, os.path.join(dirpath, file))) raise SyntaxError(msg) if (verbosity > 1): sys.stdout.write(('processing file %s in %s\n' % (file, dirpath))) cmd = ('xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))) (msgs, errors) = _popen(cmd) if errors: raise CommandError(('errors happened while running xgettext on %s\n%s' % (file, errors))) if (thefile != file): old = ('#: ' + os.path.join(dirpath, thefile)[2:]) new = ('#: ' + os.path.join(dirpath, file)[2:]) msgs = msgs.replace(old, new) if os.path.exists(potfile): msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) else: msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') if msgs: f = open(potfile, 'ab') try: f.write(msgs) finally: f.close() if (thefile != file): os.unlink(os.path.join(dirpath, thefile)) if os.path.exists(potfile): (msgs, errors) = _popen(('msguniq --to-code=utf-8 "%s"' % potfile)) if errors: raise CommandError(('errors happened while running msguniq\n%s' % errors)) f = open(potfile, 'w') try: f.write(msgs) finally: f.close() if os.path.exists(pofile): (msgs, errors) = _popen(('msgmerge -q "%s" "%s"' % (pofile, potfile))) if errors: raise CommandError(('errors happened while running msgmerge\n%s' % errors)) elif (not invoked_for_django): msgs = copy_plural_forms(msgs, locale, domain, verbosity) f = open(pofile, 'wb') try: f.write(msgs) finally: f.close() os.unlink(potfile)
Uses the locale directory from the Django SVN tree or an application/ project to process all
uses the locale directory from the django svn tree or an application / project to process all
Question: What does this function do? Code: def make_messages(locale=None, domain='django', verbosity='1', all=False, extensions=None, symlinks=False, ignore_patterns=[]): from google.appengine._internal.django.conf import settings if settings.configured: settings.USE_I18N = True else: settings.configure(USE_I18N=True) from google.appengine._internal.django.utils.translation import templatize invoked_for_django = False if os.path.isdir(os.path.join('conf', 'locale')): localedir = os.path.abspath(os.path.join('conf', 'locale')) invoked_for_django = True elif os.path.isdir('locale'): localedir = os.path.abspath('locale') else: raise CommandError('This script should be run from the Django SVN tree or your project or app tree. If you did indeed run it from the SVN checkout or your project or application, maybe you are just missing the conf/locale (in the django tree) or locale (for project and application) directory? It is not created automatically, you have to create it by hand if you want to enable i18n for your project or application.') if (domain not in ('django', 'djangojs')): raise CommandError("currently makemessages only supports domains 'django' and 'djangojs'") if (((locale is None) and (not all)) or (domain is None)): if (not sys.argv[0].endswith('make-messages.py')): message = ("Type '%s help %s' for usage.\n" % (os.path.basename(sys.argv[0]), sys.argv[1])) else: message = 'usage: make-messages.py -l <language>\n or: make-messages.py -a\n' raise CommandError(message) output = _popen('xgettext --version')[0] match = re.search('(?P<major>\\d+)\\.(?P<minor>\\d+)', output) if match: xversion = (int(match.group('major')), int(match.group('minor'))) if (xversion < (0, 15)): raise CommandError(('Django internationalization requires GNU gettext 0.15 or newer. You are using version %s, please upgrade your gettext toolset.' % match.group())) languages = [] if (locale is not None): languages.append(locale) elif all: locale_dirs = filter(os.path.isdir, glob.glob(('%s/*' % localedir))) languages = [os.path.basename(l) for l in locale_dirs] for locale in languages: if (verbosity > 0): print 'processing language', locale basedir = os.path.join(localedir, locale, 'LC_MESSAGES') if (not os.path.isdir(basedir)): os.makedirs(basedir) pofile = os.path.join(basedir, ('%s.po' % domain)) potfile = os.path.join(basedir, ('%s.pot' % domain)) if os.path.exists(potfile): os.unlink(potfile) for (dirpath, file) in find_files('.', ignore_patterns, verbosity, symlinks=symlinks): (file_base, file_ext) = os.path.splitext(file) if ((domain == 'djangojs') and (file_ext in extensions)): if (verbosity > 1): sys.stdout.write(('processing file %s in %s\n' % (file, dirpath))) src = open(os.path.join(dirpath, file), 'rU').read() src = pythonize_re.sub('\n#', src) thefile = ('%s.py' % file) f = open(os.path.join(dirpath, thefile), 'w') try: f.write(src) finally: f.close() cmd = ('xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))) (msgs, errors) = _popen(cmd) if errors: raise CommandError(('errors happened while running xgettext on %s\n%s' % (file, errors))) old = ('#: ' + os.path.join(dirpath, thefile)[2:]) new = ('#: ' + os.path.join(dirpath, file)[2:]) msgs = msgs.replace(old, new) if os.path.exists(potfile): msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) else: msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') if msgs: f = open(potfile, 'ab') try: f.write(msgs) finally: f.close() os.unlink(os.path.join(dirpath, thefile)) elif ((domain == 'django') and ((file_ext == '.py') or (file_ext in extensions))): thefile = file if (file_ext in extensions): src = open(os.path.join(dirpath, file), 'rU').read() thefile = ('%s.py' % file) try: f = open(os.path.join(dirpath, thefile), 'w') try: f.write(templatize(src)) finally: f.close() except SyntaxError as msg: msg = ('%s (file: %s)' % (msg, os.path.join(dirpath, file))) raise SyntaxError(msg) if (verbosity > 1): sys.stdout.write(('processing file %s in %s\n' % (file, dirpath))) cmd = ('xgettext -d %s -L Python --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --keyword=ugettext_noop --keyword=ugettext_lazy --keyword=ungettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))) (msgs, errors) = _popen(cmd) if errors: raise CommandError(('errors happened while running xgettext on %s\n%s' % (file, errors))) if (thefile != file): old = ('#: ' + os.path.join(dirpath, thefile)[2:]) new = ('#: ' + os.path.join(dirpath, file)[2:]) msgs = msgs.replace(old, new) if os.path.exists(potfile): msgs = '\n'.join(dropwhile(len, msgs.split('\n'))) else: msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') if msgs: f = open(potfile, 'ab') try: f.write(msgs) finally: f.close() if (thefile != file): os.unlink(os.path.join(dirpath, thefile)) if os.path.exists(potfile): (msgs, errors) = _popen(('msguniq --to-code=utf-8 "%s"' % potfile)) if errors: raise CommandError(('errors happened while running msguniq\n%s' % errors)) f = open(potfile, 'w') try: f.write(msgs) finally: f.close() if os.path.exists(pofile): (msgs, errors) = _popen(('msgmerge -q "%s" "%s"' % (pofile, potfile))) if errors: raise CommandError(('errors happened while running msgmerge\n%s' % errors)) elif (not invoked_for_django): msgs = copy_plural_forms(msgs, locale, domain, verbosity) f = open(pofile, 'wb') try: f.write(msgs) finally: f.close() os.unlink(potfile)
null
null
null
What does this function do?
def find_free_port(host, currentport): n = 0 while ((n < 10) and (currentport <= 49151)): try: cherrypy.process.servers.check_port(host, currentport, timeout=0.025) return currentport except: currentport += 5 n += 1 return 0
null
null
null
Return a free port, 0 when nothing is free
pcsd
def find free port host currentport n = 0 while n < 10 and currentport <= 49151 try cherrypy process servers check port host currentport timeout=0 025 return currentport except currentport += 5 n += 1 return 0
7921
def find_free_port(host, currentport): n = 0 while ((n < 10) and (currentport <= 49151)): try: cherrypy.process.servers.check_port(host, currentport, timeout=0.025) return currentport except: currentport += 5 n += 1 return 0
Return a free port, 0 when nothing is free
return a free port , 0 when nothing is free
Question: What does this function do? Code: def find_free_port(host, currentport): n = 0 while ((n < 10) and (currentport <= 49151)): try: cherrypy.process.servers.check_port(host, currentport, timeout=0.025) return currentport except: currentport += 5 n += 1 return 0
null
null
null
What does this function do?
def bisection(payload, expression, length=None, charsetType=None, firstChar=None, lastChar=None, dump=False): abortedFlag = False showEta = False partialValue = u'' finalValue = None retrievedLength = 0 asciiTbl = getCharset(charsetType) threadData = getCurrentThreadData() timeBasedCompare = (kb.technique in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) retVal = hashDBRetrieve(expression, checkConf=True) if retVal: if (PARTIAL_HEX_VALUE_MARKER in retVal): retVal = retVal.replace(PARTIAL_HEX_VALUE_MARKER, '') if (retVal and conf.hexConvert): partialValue = retVal infoMsg = ('resuming partial value: %s' % safecharencode(partialValue)) logger.info(infoMsg) elif (PARTIAL_VALUE_MARKER in retVal): retVal = retVal.replace(PARTIAL_VALUE_MARKER, '') if (retVal and (not conf.hexConvert)): partialValue = retVal infoMsg = ('resuming partial value: %s' % safecharencode(partialValue)) logger.info(infoMsg) else: infoMsg = ('resumed: %s' % safecharencode(retVal)) logger.info(infoMsg) return (0, retVal) try: if conf.predictOutput: kb.partRun = getPartRun() elif hasattr(conf, 'api'): kb.partRun = getPartRun(alias=False) else: kb.partRun = None if partialValue: firstChar = len(partialValue) elif (('LENGTH(' in expression.upper()) or ('LEN(' in expression.upper())): firstChar = 0 elif ((kb.fileReadMode or dump) and (conf.firstChar is not None) and (isinstance(conf.firstChar, int) or (isinstance(conf.firstChar, basestring) and conf.firstChar.isdigit()))): firstChar = (int(conf.firstChar) - 1) if kb.fileReadMode: firstChar *= 2 elif ((isinstance(firstChar, basestring) and firstChar.isdigit()) or isinstance(firstChar, int)): firstChar = (int(firstChar) - 1) else: firstChar = 0 if (('LENGTH(' in expression.upper()) or ('LEN(' in expression.upper())): lastChar = 0 elif (dump and (conf.lastChar is not None) and (isinstance(conf.lastChar, int) or (isinstance(conf.lastChar, basestring) and conf.lastChar.isdigit()))): lastChar = int(conf.lastChar) elif ((isinstance(lastChar, basestring) and lastChar.isdigit()) or isinstance(lastChar, int)): lastChar = int(lastChar) else: lastChar = 0 if Backend.getDbms(): (_, _, _, _, _, _, fieldToCastStr, _) = agent.getFields(expression) nulledCastedField = agent.nullAndCastField(fieldToCastStr) expressionReplaced = expression.replace(fieldToCastStr, nulledCastedField, 1) expressionUnescaped = unescaper.escape(expressionReplaced) else: expressionUnescaped = unescaper.escape(expression) if ((isinstance(length, basestring) and length.isdigit()) or isinstance(length, int)): length = int(length) else: length = None if (length == 0): return (0, '') if (length and ((lastChar > 0) or (firstChar > 0))): length = (min(length, (lastChar or length)) - firstChar) if (length and (length > MAX_BISECTION_LENGTH)): length = None showEta = (conf.eta and isinstance(length, int)) numThreads = (min(conf.threads, length) or 1) if showEta: progress = ProgressBar(maxValue=length) if (timeBasedCompare and (conf.threads > 1) and (not conf.forceThreads)): warnMsg = 'multi-threading is considered unsafe in time-based data retrieval. Going to switch it off automatically' singleTimeWarnMessage(warnMsg) if (numThreads > 1): if ((not timeBasedCompare) or conf.forceThreads): debugMsg = ('starting %d thread%s' % (numThreads, ('s' if (numThreads > 1) else ''))) logger.debug(debugMsg) else: numThreads = 1 if ((conf.threads == 1) and (not timeBasedCompare) and (not conf.predictOutput)): warnMsg = 'running in a single-thread mode. Please consider ' warnMsg += "usage of option '--threads' for faster data retrieval" singleTimeWarnMessage(warnMsg) if ((conf.verbose in (1, 2)) and (not showEta) and (not hasattr(conf, 'api'))): if (isinstance(length, int) and (conf.threads > 1)): dataToStdout(('[%s] [INFO] retrieved: %s' % (time.strftime('%X'), ('_' * min(length, conf.progressWidth))))) dataToStdout(('\r[%s] [INFO] retrieved: ' % time.strftime('%X'))) else: dataToStdout(('\r[%s] [INFO] retrieved: ' % time.strftime('%X'))) hintlock = threading.Lock() def tryHint(idx): with hintlock: hintValue = kb.hintValue if ((hintValue is not None) and (len(hintValue) >= idx)): if (Backend.getIdentifiedDbms() in (DBMS.SQLITE, DBMS.ACCESS, DBMS.MAXDB, DBMS.DB2)): posValue = hintValue[(idx - 1)] else: posValue = ord(hintValue[(idx - 1)]) forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, posValue)) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: return hintValue[(idx - 1)] with hintlock: kb.hintValue = None return None def validateChar(idx, value): '\n Used in inference - in time-based SQLi if original and retrieved value are not equal there will be a deliberate delay\n ' validationPayload = re.sub(('(%s.*?)%s(.*?%s)' % (PAYLOAD_DELIMITER, INFERENCE_GREATER_CHAR, PAYLOAD_DELIMITER)), ('\\g<1>%s\\g<2>' % INFERENCE_NOT_EQUALS_CHAR), payload) if (("'%s'" % CHAR_INFERENCE_MARK) not in payload): forgedPayload = safeStringFormat(validationPayload, (expressionUnescaped, idx, value)) else: markingValue = ("'%s'" % CHAR_INFERENCE_MARK) unescapedCharValue = unescaper.escape(("'%s'" % decodeIntToUnicode(value))) forgedPayload = safeStringFormat(validationPayload, (expressionUnescaped, idx)).replace(markingValue, unescapedCharValue) result = (not Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False)) if (result and timeBasedCompare): result = (threadData.lastCode == kb.injection.data[kb.technique].trueCode) if (not result): warnMsg = ("detected HTTP code '%s' in validation phase is differing from expected '%s'" % (threadData.lastCode, kb.injection.data[kb.technique].trueCode)) singleTimeWarnMessage(warnMsg) incrementCounter(kb.technique) return result def getChar(idx, charTbl=None, continuousOrder=True, expand=(charsetType is None), shiftTable=None, retried=None): "\n continuousOrder means that distance between each two neighbour's\n numerical values is exactly 1\n " result = tryHint(idx) if result: return result if (charTbl is None): charTbl = type(asciiTbl)(asciiTbl) originalTbl = type(charTbl)(charTbl) if (continuousOrder and (shiftTable is None)): shiftTable = [2, 2, 3, 3, 5, 4] if (("'%s'" % CHAR_INFERENCE_MARK) in payload): for char in ('\n', '\r'): if (ord(char) in charTbl): charTbl.remove(ord(char)) if (not charTbl): return None elif (len(charTbl) == 1): forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, charTbl[0])) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: return decodeIntToUnicode(charTbl[0]) else: return None maxChar = maxValue = charTbl[(-1)] minChar = minValue = charTbl[0] firstCheck = False lastCheck = False unexpectedCode = False while (len(charTbl) != 1): position = None if (charsetType is None): if (not firstCheck): try: try: lastChar = [_ for _ in threadData.shared.value if (_ is not None)][(-1)] except IndexError: lastChar = None if ('a' <= lastChar <= 'z'): position = charTbl.index((ord('a') - 1)) elif ('A' <= lastChar <= 'Z'): position = charTbl.index((ord('A') - 1)) elif ('0' <= lastChar <= '9'): position = charTbl.index((ord('0') - 1)) except ValueError: pass finally: firstCheck = True elif ((not lastCheck) and (numThreads == 1)): if (charTbl[(len(charTbl) >> 1)] < ord(' ')): try: position = charTbl.index(1) except ValueError: pass finally: lastCheck = True if (position is None): position = (len(charTbl) >> 1) posValue = charTbl[position] falsePayload = None if (("'%s'" % CHAR_INFERENCE_MARK) not in payload): forgedPayload = safeStringFormat(payload, (expressionUnescaped, idx, posValue)) falsePayload = safeStringFormat(payload, (expressionUnescaped, idx, RANDOM_INTEGER_MARKER)) else: markingValue = ("'%s'" % CHAR_INFERENCE_MARK) unescapedCharValue = unescaper.escape(("'%s'" % decodeIntToUnicode(posValue))) forgedPayload = safeStringFormat(payload, (expressionUnescaped, idx)).replace(markingValue, unescapedCharValue) falsePayload = safeStringFormat(payload, (expressionUnescaped, idx)).replace(markingValue, NULL) if timeBasedCompare: if kb.responseTimeMode: kb.responseTimePayload = falsePayload else: kb.responseTimePayload = None result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if (not timeBasedCompare): unexpectedCode |= (threadData.lastCode not in (kb.injection.data[kb.technique].falseCode, kb.injection.data[kb.technique].trueCode)) if unexpectedCode: warnMsg = ("unexpected HTTP code '%s' detected. Will use (extra) validation step in similar cases" % threadData.lastCode) singleTimeWarnMessage(warnMsg) if result: minValue = posValue if (type(charTbl) != xrange): charTbl = charTbl[position:] else: charTbl = xrange(charTbl[position], (charTbl[(-1)] + 1)) else: maxValue = posValue if (type(charTbl) != xrange): charTbl = charTbl[:position] else: charTbl = xrange(charTbl[0], charTbl[position]) if (len(charTbl) == 1): if continuousOrder: if (maxValue == 1): return None elif (minValue == maxChar): if (expand and shiftTable): charTbl = xrange((maxChar + 1), ((maxChar + 1) << shiftTable.pop())) originalTbl = xrange(charTbl) maxChar = maxValue = charTbl[(-1)] minChar = minValue = charTbl[0] else: return None else: retVal = (minValue + 1) if ((retVal in originalTbl) or ((retVal == ord('\n')) and (CHAR_INFERENCE_MARK in payload))): if ((timeBasedCompare or unexpectedCode) and (not validateChar(idx, retVal))): if (not kb.originalTimeDelay): kb.originalTimeDelay = conf.timeSec threadData.validationRun = 0 if (retried < MAX_REVALIDATION_STEPS): errMsg = 'invalid character detected. retrying..' logger.error(errMsg) if timeBasedCompare: if (kb.adjustTimeDelay is not ADJUST_TIME_DELAY.DISABLE): conf.timeSec += 1 warnMsg = ('increasing time delay to %d second%s ' % (conf.timeSec, ('s' if (conf.timeSec > 1) else ''))) logger.warn(warnMsg) if (kb.adjustTimeDelay is ADJUST_TIME_DELAY.YES): dbgMsg = 'turning off time auto-adjustment mechanism' logger.debug(dbgMsg) kb.adjustTimeDelay = ADJUST_TIME_DELAY.NO return getChar(idx, originalTbl, continuousOrder, expand, shiftTable, ((retried or 0) + 1)) else: errMsg = ("unable to properly validate last character value ('%s').." % decodeIntToUnicode(retVal)) logger.error(errMsg) conf.timeSec = kb.originalTimeDelay return decodeIntToUnicode(retVal) else: if timeBasedCompare: threadData.validationRun += 1 if ((kb.adjustTimeDelay is ADJUST_TIME_DELAY.NO) and (threadData.validationRun > VALID_TIME_CHARS_RUN_THRESHOLD)): dbgMsg = 'turning back on time auto-adjustment mechanism' logger.debug(dbgMsg) kb.adjustTimeDelay = ADJUST_TIME_DELAY.YES return decodeIntToUnicode(retVal) else: return None else: if ((minValue == maxChar) or (maxValue == minChar)): return None for index in xrange(len(originalTbl)): if (originalTbl[index] == minValue): break for retVal in (originalTbl[index], originalTbl[(index + 1)]): forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, retVal)) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: return decodeIntToUnicode(retVal) return None if ((conf.threads > 1) and isinstance(length, int) and (length > 1)): threadData.shared.value = ([None] * length) threadData.shared.index = [firstChar] threadData.shared.start = firstChar try: def blindThread(): threadData = getCurrentThreadData() while kb.threadContinue: kb.locks.index.acquire() if ((threadData.shared.index[0] - firstChar) >= length): kb.locks.index.release() return threadData.shared.index[0] += 1 curidx = threadData.shared.index[0] kb.locks.index.release() if kb.threadContinue: charStart = time.time() val = getChar(curidx) if (val is None): val = INFERENCE_UNKNOWN_CHAR else: break with kb.locks.value: threadData.shared.value[((curidx - 1) - firstChar)] = val currentValue = list(threadData.shared.value) if kb.threadContinue: if showEta: progress.progress((time.time() - charStart), threadData.shared.index[0]) elif (conf.verbose >= 1): startCharIndex = 0 endCharIndex = 0 for i in xrange(length): if (currentValue[i] is not None): endCharIndex = max(endCharIndex, i) output = '' if (endCharIndex > conf.progressWidth): startCharIndex = (endCharIndex - conf.progressWidth) count = threadData.shared.start for i in xrange(startCharIndex, (endCharIndex + 1)): output += ('_' if (currentValue[i] is None) else currentValue[i]) for i in xrange(length): count += (1 if (currentValue[i] is not None) else 0) if (startCharIndex > 0): output = ('..' + output[2:]) if (((endCharIndex - startCharIndex) == conf.progressWidth) and (endCharIndex < (length - 1))): output = (output[:(-2)] + '..') if ((conf.verbose in (1, 2)) and (not showEta) and (not hasattr(conf, 'api'))): _ = (count - firstChar) output += ('_' * (min(length, conf.progressWidth) - len(output))) status = (' %d/%d (%d%%)' % (_, length, round(((100.0 * _) / length)))) output += (status if (_ != length) else (' ' * len(status))) dataToStdout(('\r[%s] [INFO] retrieved: %s' % (time.strftime('%X'), filterControlChars(output)))) runThreads(numThreads, blindThread, startThreadMsg=False) except KeyboardInterrupt: abortedFlag = True finally: value = [_ for _ in partialValue] value.extend((_ for _ in threadData.shared.value)) infoMsg = None if (None in value): partialValue = ''.join(value[:value.index(None)]) if partialValue: infoMsg = ('\r[%s] [INFO] partially retrieved: %s' % (time.strftime('%X'), filterControlChars(partialValue))) else: finalValue = ''.join(value) infoMsg = ('\r[%s] [INFO] retrieved: %s' % (time.strftime('%X'), filterControlChars(finalValue))) if ((conf.verbose in (1, 2)) and (not showEta) and infoMsg and (not hasattr(conf, 'api'))): dataToStdout(infoMsg) else: index = firstChar threadData.shared.value = '' while True: index += 1 charStart = time.time() if (conf.predictOutput and (len(partialValue) > 0) and (kb.partRun is not None)): val = None (commonValue, commonPattern, commonCharset, otherCharset) = goGoodSamaritan(partialValue, asciiTbl) if (commonValue is not None): testValue = (unescaper.escape(("'%s'" % commonValue)) if ("'" not in commonValue) else unescaper.escape(('%s' % commonValue), quote=False)) query = kb.injection.data[kb.technique].vector query = agent.prefixQuery(query.replace('[INFERENCE]', ('(%s)=%s' % (expressionUnescaped, testValue)))) query = agent.suffixQuery(query) result = Request.queryPage(agent.payload(newValue=query), timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: if showEta: progress.progress((time.time() - charStart), len(commonValue)) elif ((conf.verbose in (1, 2)) or hasattr(conf, 'api')): dataToStdout(filterControlChars(commonValue[(index - 1):])) finalValue = commonValue break if (commonPattern is not None): subquery = (queries[Backend.getIdentifiedDbms()].substring.query % (expressionUnescaped, 1, len(commonPattern))) testValue = (unescaper.escape(("'%s'" % commonPattern)) if ("'" not in commonPattern) else unescaper.escape(('%s' % commonPattern), quote=False)) query = kb.injection.data[kb.technique].vector query = agent.prefixQuery(query.replace('[INFERENCE]', ('(%s)=%s' % (subquery, testValue)))) query = agent.suffixQuery(query) result = Request.queryPage(agent.payload(newValue=query), timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: val = commonPattern[(index - 1):] index += (len(val) - 1) if ((not val) and commonCharset): val = getChar(index, commonCharset, False) if (not val): val = getChar(index, otherCharset, (otherCharset == asciiTbl)) else: val = getChar(index, asciiTbl) if (val is None): finalValue = partialValue break if kb.data.processChar: val = kb.data.processChar(val) threadData.shared.value = partialValue = (partialValue + val) if showEta: progress.progress((time.time() - charStart), index) elif ((conf.verbose in (1, 2)) or hasattr(conf, 'api')): dataToStdout(filterControlChars(val)) if ((len(partialValue) > INFERENCE_BLANK_BREAK) and partialValue[(- INFERENCE_BLANK_BREAK):].isspace() and (partialValue.strip(' ')[(-1):] != '\n')): finalValue = partialValue[:(- INFERENCE_BLANK_BREAK)] break if ((lastChar > 0) and (index >= lastChar)): finalValue = ('' if (length == 0) else partialValue) finalValue = (finalValue.rstrip() if (len(finalValue) > 1) else finalValue) partialValue = None break except KeyboardInterrupt: abortedFlag = True finally: kb.prependFlag = False kb.stickyLevel = None retrievedLength = len((finalValue or '')) if (finalValue is not None): finalValue = (decodeHexValue(finalValue) if conf.hexConvert else finalValue) hashDBWrite(expression, finalValue) elif partialValue: hashDBWrite(expression, ('%s%s' % ((PARTIAL_VALUE_MARKER if (not conf.hexConvert) else PARTIAL_HEX_VALUE_MARKER), partialValue))) if (conf.hexConvert and (not abortedFlag) and (not hasattr(conf, 'api'))): infoMsg = ('\r[%s] [INFO] retrieved: %s %s\n' % (time.strftime('%X'), filterControlChars(finalValue), (' ' * retrievedLength))) dataToStdout(infoMsg) else: if ((conf.verbose in (1, 2)) and (not showEta) and (not hasattr(conf, 'api'))): dataToStdout('\n') if (((conf.verbose in (1, 2)) and showEta) or (conf.verbose >= 3)): infoMsg = ('retrieved: %s' % filterControlChars(finalValue)) logger.info(infoMsg) if kb.threadException: raise SqlmapThreadException('something unexpected happened inside the threads') if abortedFlag: raise KeyboardInterrupt _ = (finalValue or partialValue) return (getCounter(kb.technique), (safecharencode(_) if kb.safeCharEncode else _))
null
null
null
Bisection algorithm that can be used to perform blind SQL injection on an affected host
pcsd
def bisection payload expression length=None charset Type=None first Char=None last Char=None dump=False aborted Flag = False show Eta = False partial Value = u'' final Value = None retrieved Length = 0 ascii Tbl = get Charset charset Type thread Data = get Current Thread Data time Based Compare = kb technique in PAYLOAD TECHNIQUE TIME PAYLOAD TECHNIQUE STACKED ret Val = hash DB Retrieve expression check Conf=True if ret Val if PARTIAL HEX VALUE MARKER in ret Val ret Val = ret Val replace PARTIAL HEX VALUE MARKER '' if ret Val and conf hex Convert partial Value = ret Val info Msg = 'resuming partial value %s' % safecharencode partial Value logger info info Msg elif PARTIAL VALUE MARKER in ret Val ret Val = ret Val replace PARTIAL VALUE MARKER '' if ret Val and not conf hex Convert partial Value = ret Val info Msg = 'resuming partial value %s' % safecharencode partial Value logger info info Msg else info Msg = 'resumed %s' % safecharencode ret Val logger info info Msg return 0 ret Val try if conf predict Output kb part Run = get Part Run elif hasattr conf 'api' kb part Run = get Part Run alias=False else kb part Run = None if partial Value first Char = len partial Value elif 'LENGTH ' in expression upper or 'LEN ' in expression upper first Char = 0 elif kb file Read Mode or dump and conf first Char is not None and isinstance conf first Char int or isinstance conf first Char basestring and conf first Char isdigit first Char = int conf first Char - 1 if kb file Read Mode first Char *= 2 elif isinstance first Char basestring and first Char isdigit or isinstance first Char int first Char = int first Char - 1 else first Char = 0 if 'LENGTH ' in expression upper or 'LEN ' in expression upper last Char = 0 elif dump and conf last Char is not None and isinstance conf last Char int or isinstance conf last Char basestring and conf last Char isdigit last Char = int conf last Char elif isinstance last Char basestring and last Char isdigit or isinstance last Char int last Char = int last Char else last Char = 0 if Backend get Dbms field To Cast Str = agent get Fields expression nulled Casted Field = agent null And Cast Field field To Cast Str expression Replaced = expression replace field To Cast Str nulled Casted Field 1 expression Unescaped = unescaper escape expression Replaced else expression Unescaped = unescaper escape expression if isinstance length basestring and length isdigit or isinstance length int length = int length else length = None if length == 0 return 0 '' if length and last Char > 0 or first Char > 0 length = min length last Char or length - first Char if length and length > MAX BISECTION LENGTH length = None show Eta = conf eta and isinstance length int num Threads = min conf threads length or 1 if show Eta progress = Progress Bar max Value=length if time Based Compare and conf threads > 1 and not conf force Threads warn Msg = 'multi-threading is considered unsafe in time-based data retrieval Going to switch it off automatically' single Time Warn Message warn Msg if num Threads > 1 if not time Based Compare or conf force Threads debug Msg = 'starting %d thread%s' % num Threads 's' if num Threads > 1 else '' logger debug debug Msg else num Threads = 1 if conf threads == 1 and not time Based Compare and not conf predict Output warn Msg = 'running in a single-thread mode Please consider ' warn Msg += "usage of option '--threads' for faster data retrieval" single Time Warn Message warn Msg if conf verbose in 1 2 and not show Eta and not hasattr conf 'api' if isinstance length int and conf threads > 1 data To Stdout '[%s] [INFO] retrieved %s' % time strftime '%X' ' ' * min length conf progress Width data To Stdout '\r[%s] [INFO] retrieved ' % time strftime '%X' else data To Stdout '\r[%s] [INFO] retrieved ' % time strftime '%X' hintlock = threading Lock def try Hint idx with hintlock hint Value = kb hint Value if hint Value is not None and len hint Value >= idx if Backend get Identified Dbms in DBMS SQLITE DBMS ACCESS DBMS MAXDB DBMS DB2 pos Value = hint Value[ idx - 1 ] else pos Value = ord hint Value[ idx - 1 ] forged Payload = safe String Format payload replace INFERENCE GREATER CHAR INFERENCE EQUALS CHAR expression Unescaped idx pos Value result = Request query Page forged Payload time Based Compare=time Based Compare raise404=False increment Counter kb technique if result return hint Value[ idx - 1 ] with hintlock kb hint Value = None return None def validate Char idx value ' Used in inference - in time-based SQ Li if original and retrieved value are not equal there will be a deliberate delay ' validation Payload = re sub ' %s *? %s *?%s ' % PAYLOAD DELIMITER INFERENCE GREATER CHAR PAYLOAD DELIMITER '\\g<1>%s\\g<2>' % INFERENCE NOT EQUALS CHAR payload if "'%s'" % CHAR INFERENCE MARK not in payload forged Payload = safe String Format validation Payload expression Unescaped idx value else marking Value = "'%s'" % CHAR INFERENCE MARK unescaped Char Value = unescaper escape "'%s'" % decode Int To Unicode value forged Payload = safe String Format validation Payload expression Unescaped idx replace marking Value unescaped Char Value result = not Request query Page forged Payload time Based Compare=time Based Compare raise404=False if result and time Based Compare result = thread Data last Code == kb injection data[kb technique] true Code if not result warn Msg = "detected HTTP code '%s' in validation phase is differing from expected '%s'" % thread Data last Code kb injection data[kb technique] true Code single Time Warn Message warn Msg increment Counter kb technique return result def get Char idx char Tbl=None continuous Order=True expand= charset Type is None shift Table=None retried=None " continuous Order means that distance between each two neighbour's numerical values is exactly 1 " result = try Hint idx if result return result if char Tbl is None char Tbl = type ascii Tbl ascii Tbl original Tbl = type char Tbl char Tbl if continuous Order and shift Table is None shift Table = [2 2 3 3 5 4] if "'%s'" % CHAR INFERENCE MARK in payload for char in ' ' '\r' if ord char in char Tbl char Tbl remove ord char if not char Tbl return None elif len char Tbl == 1 forged Payload = safe String Format payload replace INFERENCE GREATER CHAR INFERENCE EQUALS CHAR expression Unescaped idx char Tbl[0] result = Request query Page forged Payload time Based Compare=time Based Compare raise404=False increment Counter kb technique if result return decode Int To Unicode char Tbl[0] else return None max Char = max Value = char Tbl[ -1 ] min Char = min Value = char Tbl[0] first Check = False last Check = False unexpected Code = False while len char Tbl != 1 position = None if charset Type is None if not first Check try try last Char = [ for in thread Data shared value if is not None ][ -1 ] except Index Error last Char = None if 'a' <= last Char <= 'z' position = char Tbl index ord 'a' - 1 elif 'A' <= last Char <= 'Z' position = char Tbl index ord 'A' - 1 elif '0' <= last Char <= '9' position = char Tbl index ord '0' - 1 except Value Error pass finally first Check = True elif not last Check and num Threads == 1 if char Tbl[ len char Tbl >> 1 ] < ord ' ' try position = char Tbl index 1 except Value Error pass finally last Check = True if position is None position = len char Tbl >> 1 pos Value = char Tbl[position] false Payload = None if "'%s'" % CHAR INFERENCE MARK not in payload forged Payload = safe String Format payload expression Unescaped idx pos Value false Payload = safe String Format payload expression Unescaped idx RANDOM INTEGER MARKER else marking Value = "'%s'" % CHAR INFERENCE MARK unescaped Char Value = unescaper escape "'%s'" % decode Int To Unicode pos Value forged Payload = safe String Format payload expression Unescaped idx replace marking Value unescaped Char Value false Payload = safe String Format payload expression Unescaped idx replace marking Value NULL if time Based Compare if kb response Time Mode kb response Time Payload = false Payload else kb response Time Payload = None result = Request query Page forged Payload time Based Compare=time Based Compare raise404=False increment Counter kb technique if not time Based Compare unexpected Code |= thread Data last Code not in kb injection data[kb technique] false Code kb injection data[kb technique] true Code if unexpected Code warn Msg = "unexpected HTTP code '%s' detected Will use extra validation step in similar cases" % thread Data last Code single Time Warn Message warn Msg if result min Value = pos Value if type char Tbl != xrange char Tbl = char Tbl[position ] else char Tbl = xrange char Tbl[position] char Tbl[ -1 ] + 1 else max Value = pos Value if type char Tbl != xrange char Tbl = char Tbl[ position] else char Tbl = xrange char Tbl[0] char Tbl[position] if len char Tbl == 1 if continuous Order if max Value == 1 return None elif min Value == max Char if expand and shift Table char Tbl = xrange max Char + 1 max Char + 1 << shift Table pop original Tbl = xrange char Tbl max Char = max Value = char Tbl[ -1 ] min Char = min Value = char Tbl[0] else return None else ret Val = min Value + 1 if ret Val in original Tbl or ret Val == ord ' ' and CHAR INFERENCE MARK in payload if time Based Compare or unexpected Code and not validate Char idx ret Val if not kb original Time Delay kb original Time Delay = conf time Sec thread Data validation Run = 0 if retried < MAX REVALIDATION STEPS err Msg = 'invalid character detected retrying ' logger error err Msg if time Based Compare if kb adjust Time Delay is not ADJUST TIME DELAY DISABLE conf time Sec += 1 warn Msg = 'increasing time delay to %d second%s ' % conf time Sec 's' if conf time Sec > 1 else '' logger warn warn Msg if kb adjust Time Delay is ADJUST TIME DELAY YES dbg Msg = 'turning off time auto-adjustment mechanism' logger debug dbg Msg kb adjust Time Delay = ADJUST TIME DELAY NO return get Char idx original Tbl continuous Order expand shift Table retried or 0 + 1 else err Msg = "unable to properly validate last character value '%s' " % decode Int To Unicode ret Val logger error err Msg conf time Sec = kb original Time Delay return decode Int To Unicode ret Val else if time Based Compare thread Data validation Run += 1 if kb adjust Time Delay is ADJUST TIME DELAY NO and thread Data validation Run > VALID TIME CHARS RUN THRESHOLD dbg Msg = 'turning back on time auto-adjustment mechanism' logger debug dbg Msg kb adjust Time Delay = ADJUST TIME DELAY YES return decode Int To Unicode ret Val else return None else if min Value == max Char or max Value == min Char return None for index in xrange len original Tbl if original Tbl[index] == min Value break for ret Val in original Tbl[index] original Tbl[ index + 1 ] forged Payload = safe String Format payload replace INFERENCE GREATER CHAR INFERENCE EQUALS CHAR expression Unescaped idx ret Val result = Request query Page forged Payload time Based Compare=time Based Compare raise404=False increment Counter kb technique if result return decode Int To Unicode ret Val return None if conf threads > 1 and isinstance length int and length > 1 thread Data shared value = [None] * length thread Data shared index = [first Char] thread Data shared start = first Char try def blind Thread thread Data = get Current Thread Data while kb thread Continue kb locks index acquire if thread Data shared index[0] - first Char >= length kb locks index release return thread Data shared index[0] += 1 curidx = thread Data shared index[0] kb locks index release if kb thread Continue char Start = time time val = get Char curidx if val is None val = INFERENCE UNKNOWN CHAR else break with kb locks value thread Data shared value[ curidx - 1 - first Char ] = val current Value = list thread Data shared value if kb thread Continue if show Eta progress progress time time - char Start thread Data shared index[0] elif conf verbose >= 1 start Char Index = 0 end Char Index = 0 for i in xrange length if current Value[i] is not None end Char Index = max end Char Index i output = '' if end Char Index > conf progress Width start Char Index = end Char Index - conf progress Width count = thread Data shared start for i in xrange start Char Index end Char Index + 1 output += ' ' if current Value[i] is None else current Value[i] for i in xrange length count += 1 if current Value[i] is not None else 0 if start Char Index > 0 output = ' ' + output[2 ] if end Char Index - start Char Index == conf progress Width and end Char Index < length - 1 output = output[ -2 ] + ' ' if conf verbose in 1 2 and not show Eta and not hasattr conf 'api' = count - first Char output += ' ' * min length conf progress Width - len output status = ' %d/%d %d%% ' % length round 100 0 * / length output += status if != length else ' ' * len status data To Stdout '\r[%s] [INFO] retrieved %s' % time strftime '%X' filter Control Chars output run Threads num Threads blind Thread start Thread Msg=False except Keyboard Interrupt aborted Flag = True finally value = [ for in partial Value] value extend for in thread Data shared value info Msg = None if None in value partial Value = '' join value[ value index None ] if partial Value info Msg = '\r[%s] [INFO] partially retrieved %s' % time strftime '%X' filter Control Chars partial Value else final Value = '' join value info Msg = '\r[%s] [INFO] retrieved %s' % time strftime '%X' filter Control Chars final Value if conf verbose in 1 2 and not show Eta and info Msg and not hasattr conf 'api' data To Stdout info Msg else index = first Char thread Data shared value = '' while True index += 1 char Start = time time if conf predict Output and len partial Value > 0 and kb part Run is not None val = None common Value common Pattern common Charset other Charset = go Good Samaritan partial Value ascii Tbl if common Value is not None test Value = unescaper escape "'%s'" % common Value if "'" not in common Value else unescaper escape '%s' % common Value quote=False query = kb injection data[kb technique] vector query = agent prefix Query query replace '[INFERENCE]' ' %s =%s' % expression Unescaped test Value query = agent suffix Query query result = Request query Page agent payload new Value=query time Based Compare=time Based Compare raise404=False increment Counter kb technique if result if show Eta progress progress time time - char Start len common Value elif conf verbose in 1 2 or hasattr conf 'api' data To Stdout filter Control Chars common Value[ index - 1 ] final Value = common Value break if common Pattern is not None subquery = queries[Backend get Identified Dbms ] substring query % expression Unescaped 1 len common Pattern test Value = unescaper escape "'%s'" % common Pattern if "'" not in common Pattern else unescaper escape '%s' % common Pattern quote=False query = kb injection data[kb technique] vector query = agent prefix Query query replace '[INFERENCE]' ' %s =%s' % subquery test Value query = agent suffix Query query result = Request query Page agent payload new Value=query time Based Compare=time Based Compare raise404=False increment Counter kb technique if result val = common Pattern[ index - 1 ] index += len val - 1 if not val and common Charset val = get Char index common Charset False if not val val = get Char index other Charset other Charset == ascii Tbl else val = get Char index ascii Tbl if val is None final Value = partial Value break if kb data process Char val = kb data process Char val thread Data shared value = partial Value = partial Value + val if show Eta progress progress time time - char Start index elif conf verbose in 1 2 or hasattr conf 'api' data To Stdout filter Control Chars val if len partial Value > INFERENCE BLANK BREAK and partial Value[ - INFERENCE BLANK BREAK ] isspace and partial Value strip ' ' [ -1 ] != ' ' final Value = partial Value[ - INFERENCE BLANK BREAK ] break if last Char > 0 and index >= last Char final Value = '' if length == 0 else partial Value final Value = final Value rstrip if len final Value > 1 else final Value partial Value = None break except Keyboard Interrupt aborted Flag = True finally kb prepend Flag = False kb sticky Level = None retrieved Length = len final Value or '' if final Value is not None final Value = decode Hex Value final Value if conf hex Convert else final Value hash DB Write expression final Value elif partial Value hash DB Write expression '%s%s' % PARTIAL VALUE MARKER if not conf hex Convert else PARTIAL HEX VALUE MARKER partial Value if conf hex Convert and not aborted Flag and not hasattr conf 'api' info Msg = '\r[%s] [INFO] retrieved %s %s ' % time strftime '%X' filter Control Chars final Value ' ' * retrieved Length data To Stdout info Msg else if conf verbose in 1 2 and not show Eta and not hasattr conf 'api' data To Stdout ' ' if conf verbose in 1 2 and show Eta or conf verbose >= 3 info Msg = 'retrieved %s' % filter Control Chars final Value logger info info Msg if kb thread Exception raise Sqlmap Thread Exception 'something unexpected happened inside the threads' if aborted Flag raise Keyboard Interrupt = final Value or partial Value return get Counter kb technique safecharencode if kb safe Char Encode else
7924
def bisection(payload, expression, length=None, charsetType=None, firstChar=None, lastChar=None, dump=False): abortedFlag = False showEta = False partialValue = u'' finalValue = None retrievedLength = 0 asciiTbl = getCharset(charsetType) threadData = getCurrentThreadData() timeBasedCompare = (kb.technique in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) retVal = hashDBRetrieve(expression, checkConf=True) if retVal: if (PARTIAL_HEX_VALUE_MARKER in retVal): retVal = retVal.replace(PARTIAL_HEX_VALUE_MARKER, '') if (retVal and conf.hexConvert): partialValue = retVal infoMsg = ('resuming partial value: %s' % safecharencode(partialValue)) logger.info(infoMsg) elif (PARTIAL_VALUE_MARKER in retVal): retVal = retVal.replace(PARTIAL_VALUE_MARKER, '') if (retVal and (not conf.hexConvert)): partialValue = retVal infoMsg = ('resuming partial value: %s' % safecharencode(partialValue)) logger.info(infoMsg) else: infoMsg = ('resumed: %s' % safecharencode(retVal)) logger.info(infoMsg) return (0, retVal) try: if conf.predictOutput: kb.partRun = getPartRun() elif hasattr(conf, 'api'): kb.partRun = getPartRun(alias=False) else: kb.partRun = None if partialValue: firstChar = len(partialValue) elif (('LENGTH(' in expression.upper()) or ('LEN(' in expression.upper())): firstChar = 0 elif ((kb.fileReadMode or dump) and (conf.firstChar is not None) and (isinstance(conf.firstChar, int) or (isinstance(conf.firstChar, basestring) and conf.firstChar.isdigit()))): firstChar = (int(conf.firstChar) - 1) if kb.fileReadMode: firstChar *= 2 elif ((isinstance(firstChar, basestring) and firstChar.isdigit()) or isinstance(firstChar, int)): firstChar = (int(firstChar) - 1) else: firstChar = 0 if (('LENGTH(' in expression.upper()) or ('LEN(' in expression.upper())): lastChar = 0 elif (dump and (conf.lastChar is not None) and (isinstance(conf.lastChar, int) or (isinstance(conf.lastChar, basestring) and conf.lastChar.isdigit()))): lastChar = int(conf.lastChar) elif ((isinstance(lastChar, basestring) and lastChar.isdigit()) or isinstance(lastChar, int)): lastChar = int(lastChar) else: lastChar = 0 if Backend.getDbms(): (_, _, _, _, _, _, fieldToCastStr, _) = agent.getFields(expression) nulledCastedField = agent.nullAndCastField(fieldToCastStr) expressionReplaced = expression.replace(fieldToCastStr, nulledCastedField, 1) expressionUnescaped = unescaper.escape(expressionReplaced) else: expressionUnescaped = unescaper.escape(expression) if ((isinstance(length, basestring) and length.isdigit()) or isinstance(length, int)): length = int(length) else: length = None if (length == 0): return (0, '') if (length and ((lastChar > 0) or (firstChar > 0))): length = (min(length, (lastChar or length)) - firstChar) if (length and (length > MAX_BISECTION_LENGTH)): length = None showEta = (conf.eta and isinstance(length, int)) numThreads = (min(conf.threads, length) or 1) if showEta: progress = ProgressBar(maxValue=length) if (timeBasedCompare and (conf.threads > 1) and (not conf.forceThreads)): warnMsg = 'multi-threading is considered unsafe in time-based data retrieval. Going to switch it off automatically' singleTimeWarnMessage(warnMsg) if (numThreads > 1): if ((not timeBasedCompare) or conf.forceThreads): debugMsg = ('starting %d thread%s' % (numThreads, ('s' if (numThreads > 1) else ''))) logger.debug(debugMsg) else: numThreads = 1 if ((conf.threads == 1) and (not timeBasedCompare) and (not conf.predictOutput)): warnMsg = 'running in a single-thread mode. Please consider ' warnMsg += "usage of option '--threads' for faster data retrieval" singleTimeWarnMessage(warnMsg) if ((conf.verbose in (1, 2)) and (not showEta) and (not hasattr(conf, 'api'))): if (isinstance(length, int) and (conf.threads > 1)): dataToStdout(('[%s] [INFO] retrieved: %s' % (time.strftime('%X'), ('_' * min(length, conf.progressWidth))))) dataToStdout(('\r[%s] [INFO] retrieved: ' % time.strftime('%X'))) else: dataToStdout(('\r[%s] [INFO] retrieved: ' % time.strftime('%X'))) hintlock = threading.Lock() def tryHint(idx): with hintlock: hintValue = kb.hintValue if ((hintValue is not None) and (len(hintValue) >= idx)): if (Backend.getIdentifiedDbms() in (DBMS.SQLITE, DBMS.ACCESS, DBMS.MAXDB, DBMS.DB2)): posValue = hintValue[(idx - 1)] else: posValue = ord(hintValue[(idx - 1)]) forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, posValue)) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: return hintValue[(idx - 1)] with hintlock: kb.hintValue = None return None def validateChar(idx, value): '\n Used in inference - in time-based SQLi if original and retrieved value are not equal there will be a deliberate delay\n ' validationPayload = re.sub(('(%s.*?)%s(.*?%s)' % (PAYLOAD_DELIMITER, INFERENCE_GREATER_CHAR, PAYLOAD_DELIMITER)), ('\\g<1>%s\\g<2>' % INFERENCE_NOT_EQUALS_CHAR), payload) if (("'%s'" % CHAR_INFERENCE_MARK) not in payload): forgedPayload = safeStringFormat(validationPayload, (expressionUnescaped, idx, value)) else: markingValue = ("'%s'" % CHAR_INFERENCE_MARK) unescapedCharValue = unescaper.escape(("'%s'" % decodeIntToUnicode(value))) forgedPayload = safeStringFormat(validationPayload, (expressionUnescaped, idx)).replace(markingValue, unescapedCharValue) result = (not Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False)) if (result and timeBasedCompare): result = (threadData.lastCode == kb.injection.data[kb.technique].trueCode) if (not result): warnMsg = ("detected HTTP code '%s' in validation phase is differing from expected '%s'" % (threadData.lastCode, kb.injection.data[kb.technique].trueCode)) singleTimeWarnMessage(warnMsg) incrementCounter(kb.technique) return result def getChar(idx, charTbl=None, continuousOrder=True, expand=(charsetType is None), shiftTable=None, retried=None): "\n continuousOrder means that distance between each two neighbour's\n numerical values is exactly 1\n " result = tryHint(idx) if result: return result if (charTbl is None): charTbl = type(asciiTbl)(asciiTbl) originalTbl = type(charTbl)(charTbl) if (continuousOrder and (shiftTable is None)): shiftTable = [2, 2, 3, 3, 5, 4] if (("'%s'" % CHAR_INFERENCE_MARK) in payload): for char in ('\n', '\r'): if (ord(char) in charTbl): charTbl.remove(ord(char)) if (not charTbl): return None elif (len(charTbl) == 1): forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, charTbl[0])) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: return decodeIntToUnicode(charTbl[0]) else: return None maxChar = maxValue = charTbl[(-1)] minChar = minValue = charTbl[0] firstCheck = False lastCheck = False unexpectedCode = False while (len(charTbl) != 1): position = None if (charsetType is None): if (not firstCheck): try: try: lastChar = [_ for _ in threadData.shared.value if (_ is not None)][(-1)] except IndexError: lastChar = None if ('a' <= lastChar <= 'z'): position = charTbl.index((ord('a') - 1)) elif ('A' <= lastChar <= 'Z'): position = charTbl.index((ord('A') - 1)) elif ('0' <= lastChar <= '9'): position = charTbl.index((ord('0') - 1)) except ValueError: pass finally: firstCheck = True elif ((not lastCheck) and (numThreads == 1)): if (charTbl[(len(charTbl) >> 1)] < ord(' ')): try: position = charTbl.index(1) except ValueError: pass finally: lastCheck = True if (position is None): position = (len(charTbl) >> 1) posValue = charTbl[position] falsePayload = None if (("'%s'" % CHAR_INFERENCE_MARK) not in payload): forgedPayload = safeStringFormat(payload, (expressionUnescaped, idx, posValue)) falsePayload = safeStringFormat(payload, (expressionUnescaped, idx, RANDOM_INTEGER_MARKER)) else: markingValue = ("'%s'" % CHAR_INFERENCE_MARK) unescapedCharValue = unescaper.escape(("'%s'" % decodeIntToUnicode(posValue))) forgedPayload = safeStringFormat(payload, (expressionUnescaped, idx)).replace(markingValue, unescapedCharValue) falsePayload = safeStringFormat(payload, (expressionUnescaped, idx)).replace(markingValue, NULL) if timeBasedCompare: if kb.responseTimeMode: kb.responseTimePayload = falsePayload else: kb.responseTimePayload = None result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if (not timeBasedCompare): unexpectedCode |= (threadData.lastCode not in (kb.injection.data[kb.technique].falseCode, kb.injection.data[kb.technique].trueCode)) if unexpectedCode: warnMsg = ("unexpected HTTP code '%s' detected. Will use (extra) validation step in similar cases" % threadData.lastCode) singleTimeWarnMessage(warnMsg) if result: minValue = posValue if (type(charTbl) != xrange): charTbl = charTbl[position:] else: charTbl = xrange(charTbl[position], (charTbl[(-1)] + 1)) else: maxValue = posValue if (type(charTbl) != xrange): charTbl = charTbl[:position] else: charTbl = xrange(charTbl[0], charTbl[position]) if (len(charTbl) == 1): if continuousOrder: if (maxValue == 1): return None elif (minValue == maxChar): if (expand and shiftTable): charTbl = xrange((maxChar + 1), ((maxChar + 1) << shiftTable.pop())) originalTbl = xrange(charTbl) maxChar = maxValue = charTbl[(-1)] minChar = minValue = charTbl[0] else: return None else: retVal = (minValue + 1) if ((retVal in originalTbl) or ((retVal == ord('\n')) and (CHAR_INFERENCE_MARK in payload))): if ((timeBasedCompare or unexpectedCode) and (not validateChar(idx, retVal))): if (not kb.originalTimeDelay): kb.originalTimeDelay = conf.timeSec threadData.validationRun = 0 if (retried < MAX_REVALIDATION_STEPS): errMsg = 'invalid character detected. retrying..' logger.error(errMsg) if timeBasedCompare: if (kb.adjustTimeDelay is not ADJUST_TIME_DELAY.DISABLE): conf.timeSec += 1 warnMsg = ('increasing time delay to %d second%s ' % (conf.timeSec, ('s' if (conf.timeSec > 1) else ''))) logger.warn(warnMsg) if (kb.adjustTimeDelay is ADJUST_TIME_DELAY.YES): dbgMsg = 'turning off time auto-adjustment mechanism' logger.debug(dbgMsg) kb.adjustTimeDelay = ADJUST_TIME_DELAY.NO return getChar(idx, originalTbl, continuousOrder, expand, shiftTable, ((retried or 0) + 1)) else: errMsg = ("unable to properly validate last character value ('%s').." % decodeIntToUnicode(retVal)) logger.error(errMsg) conf.timeSec = kb.originalTimeDelay return decodeIntToUnicode(retVal) else: if timeBasedCompare: threadData.validationRun += 1 if ((kb.adjustTimeDelay is ADJUST_TIME_DELAY.NO) and (threadData.validationRun > VALID_TIME_CHARS_RUN_THRESHOLD)): dbgMsg = 'turning back on time auto-adjustment mechanism' logger.debug(dbgMsg) kb.adjustTimeDelay = ADJUST_TIME_DELAY.YES return decodeIntToUnicode(retVal) else: return None else: if ((minValue == maxChar) or (maxValue == minChar)): return None for index in xrange(len(originalTbl)): if (originalTbl[index] == minValue): break for retVal in (originalTbl[index], originalTbl[(index + 1)]): forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, retVal)) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: return decodeIntToUnicode(retVal) return None if ((conf.threads > 1) and isinstance(length, int) and (length > 1)): threadData.shared.value = ([None] * length) threadData.shared.index = [firstChar] threadData.shared.start = firstChar try: def blindThread(): threadData = getCurrentThreadData() while kb.threadContinue: kb.locks.index.acquire() if ((threadData.shared.index[0] - firstChar) >= length): kb.locks.index.release() return threadData.shared.index[0] += 1 curidx = threadData.shared.index[0] kb.locks.index.release() if kb.threadContinue: charStart = time.time() val = getChar(curidx) if (val is None): val = INFERENCE_UNKNOWN_CHAR else: break with kb.locks.value: threadData.shared.value[((curidx - 1) - firstChar)] = val currentValue = list(threadData.shared.value) if kb.threadContinue: if showEta: progress.progress((time.time() - charStart), threadData.shared.index[0]) elif (conf.verbose >= 1): startCharIndex = 0 endCharIndex = 0 for i in xrange(length): if (currentValue[i] is not None): endCharIndex = max(endCharIndex, i) output = '' if (endCharIndex > conf.progressWidth): startCharIndex = (endCharIndex - conf.progressWidth) count = threadData.shared.start for i in xrange(startCharIndex, (endCharIndex + 1)): output += ('_' if (currentValue[i] is None) else currentValue[i]) for i in xrange(length): count += (1 if (currentValue[i] is not None) else 0) if (startCharIndex > 0): output = ('..' + output[2:]) if (((endCharIndex - startCharIndex) == conf.progressWidth) and (endCharIndex < (length - 1))): output = (output[:(-2)] + '..') if ((conf.verbose in (1, 2)) and (not showEta) and (not hasattr(conf, 'api'))): _ = (count - firstChar) output += ('_' * (min(length, conf.progressWidth) - len(output))) status = (' %d/%d (%d%%)' % (_, length, round(((100.0 * _) / length)))) output += (status if (_ != length) else (' ' * len(status))) dataToStdout(('\r[%s] [INFO] retrieved: %s' % (time.strftime('%X'), filterControlChars(output)))) runThreads(numThreads, blindThread, startThreadMsg=False) except KeyboardInterrupt: abortedFlag = True finally: value = [_ for _ in partialValue] value.extend((_ for _ in threadData.shared.value)) infoMsg = None if (None in value): partialValue = ''.join(value[:value.index(None)]) if partialValue: infoMsg = ('\r[%s] [INFO] partially retrieved: %s' % (time.strftime('%X'), filterControlChars(partialValue))) else: finalValue = ''.join(value) infoMsg = ('\r[%s] [INFO] retrieved: %s' % (time.strftime('%X'), filterControlChars(finalValue))) if ((conf.verbose in (1, 2)) and (not showEta) and infoMsg and (not hasattr(conf, 'api'))): dataToStdout(infoMsg) else: index = firstChar threadData.shared.value = '' while True: index += 1 charStart = time.time() if (conf.predictOutput and (len(partialValue) > 0) and (kb.partRun is not None)): val = None (commonValue, commonPattern, commonCharset, otherCharset) = goGoodSamaritan(partialValue, asciiTbl) if (commonValue is not None): testValue = (unescaper.escape(("'%s'" % commonValue)) if ("'" not in commonValue) else unescaper.escape(('%s' % commonValue), quote=False)) query = kb.injection.data[kb.technique].vector query = agent.prefixQuery(query.replace('[INFERENCE]', ('(%s)=%s' % (expressionUnescaped, testValue)))) query = agent.suffixQuery(query) result = Request.queryPage(agent.payload(newValue=query), timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: if showEta: progress.progress((time.time() - charStart), len(commonValue)) elif ((conf.verbose in (1, 2)) or hasattr(conf, 'api')): dataToStdout(filterControlChars(commonValue[(index - 1):])) finalValue = commonValue break if (commonPattern is not None): subquery = (queries[Backend.getIdentifiedDbms()].substring.query % (expressionUnescaped, 1, len(commonPattern))) testValue = (unescaper.escape(("'%s'" % commonPattern)) if ("'" not in commonPattern) else unescaper.escape(('%s' % commonPattern), quote=False)) query = kb.injection.data[kb.technique].vector query = agent.prefixQuery(query.replace('[INFERENCE]', ('(%s)=%s' % (subquery, testValue)))) query = agent.suffixQuery(query) result = Request.queryPage(agent.payload(newValue=query), timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: val = commonPattern[(index - 1):] index += (len(val) - 1) if ((not val) and commonCharset): val = getChar(index, commonCharset, False) if (not val): val = getChar(index, otherCharset, (otherCharset == asciiTbl)) else: val = getChar(index, asciiTbl) if (val is None): finalValue = partialValue break if kb.data.processChar: val = kb.data.processChar(val) threadData.shared.value = partialValue = (partialValue + val) if showEta: progress.progress((time.time() - charStart), index) elif ((conf.verbose in (1, 2)) or hasattr(conf, 'api')): dataToStdout(filterControlChars(val)) if ((len(partialValue) > INFERENCE_BLANK_BREAK) and partialValue[(- INFERENCE_BLANK_BREAK):].isspace() and (partialValue.strip(' ')[(-1):] != '\n')): finalValue = partialValue[:(- INFERENCE_BLANK_BREAK)] break if ((lastChar > 0) and (index >= lastChar)): finalValue = ('' if (length == 0) else partialValue) finalValue = (finalValue.rstrip() if (len(finalValue) > 1) else finalValue) partialValue = None break except KeyboardInterrupt: abortedFlag = True finally: kb.prependFlag = False kb.stickyLevel = None retrievedLength = len((finalValue or '')) if (finalValue is not None): finalValue = (decodeHexValue(finalValue) if conf.hexConvert else finalValue) hashDBWrite(expression, finalValue) elif partialValue: hashDBWrite(expression, ('%s%s' % ((PARTIAL_VALUE_MARKER if (not conf.hexConvert) else PARTIAL_HEX_VALUE_MARKER), partialValue))) if (conf.hexConvert and (not abortedFlag) and (not hasattr(conf, 'api'))): infoMsg = ('\r[%s] [INFO] retrieved: %s %s\n' % (time.strftime('%X'), filterControlChars(finalValue), (' ' * retrievedLength))) dataToStdout(infoMsg) else: if ((conf.verbose in (1, 2)) and (not showEta) and (not hasattr(conf, 'api'))): dataToStdout('\n') if (((conf.verbose in (1, 2)) and showEta) or (conf.verbose >= 3)): infoMsg = ('retrieved: %s' % filterControlChars(finalValue)) logger.info(infoMsg) if kb.threadException: raise SqlmapThreadException('something unexpected happened inside the threads') if abortedFlag: raise KeyboardInterrupt _ = (finalValue or partialValue) return (getCounter(kb.technique), (safecharencode(_) if kb.safeCharEncode else _))
Bisection algorithm that can be used to perform blind SQL injection on an affected host
bisection algorithm that can be used to perform blind sql injection on an affected host
Question: What does this function do? Code: def bisection(payload, expression, length=None, charsetType=None, firstChar=None, lastChar=None, dump=False): abortedFlag = False showEta = False partialValue = u'' finalValue = None retrievedLength = 0 asciiTbl = getCharset(charsetType) threadData = getCurrentThreadData() timeBasedCompare = (kb.technique in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED)) retVal = hashDBRetrieve(expression, checkConf=True) if retVal: if (PARTIAL_HEX_VALUE_MARKER in retVal): retVal = retVal.replace(PARTIAL_HEX_VALUE_MARKER, '') if (retVal and conf.hexConvert): partialValue = retVal infoMsg = ('resuming partial value: %s' % safecharencode(partialValue)) logger.info(infoMsg) elif (PARTIAL_VALUE_MARKER in retVal): retVal = retVal.replace(PARTIAL_VALUE_MARKER, '') if (retVal and (not conf.hexConvert)): partialValue = retVal infoMsg = ('resuming partial value: %s' % safecharencode(partialValue)) logger.info(infoMsg) else: infoMsg = ('resumed: %s' % safecharencode(retVal)) logger.info(infoMsg) return (0, retVal) try: if conf.predictOutput: kb.partRun = getPartRun() elif hasattr(conf, 'api'): kb.partRun = getPartRun(alias=False) else: kb.partRun = None if partialValue: firstChar = len(partialValue) elif (('LENGTH(' in expression.upper()) or ('LEN(' in expression.upper())): firstChar = 0 elif ((kb.fileReadMode or dump) and (conf.firstChar is not None) and (isinstance(conf.firstChar, int) or (isinstance(conf.firstChar, basestring) and conf.firstChar.isdigit()))): firstChar = (int(conf.firstChar) - 1) if kb.fileReadMode: firstChar *= 2 elif ((isinstance(firstChar, basestring) and firstChar.isdigit()) or isinstance(firstChar, int)): firstChar = (int(firstChar) - 1) else: firstChar = 0 if (('LENGTH(' in expression.upper()) or ('LEN(' in expression.upper())): lastChar = 0 elif (dump and (conf.lastChar is not None) and (isinstance(conf.lastChar, int) or (isinstance(conf.lastChar, basestring) and conf.lastChar.isdigit()))): lastChar = int(conf.lastChar) elif ((isinstance(lastChar, basestring) and lastChar.isdigit()) or isinstance(lastChar, int)): lastChar = int(lastChar) else: lastChar = 0 if Backend.getDbms(): (_, _, _, _, _, _, fieldToCastStr, _) = agent.getFields(expression) nulledCastedField = agent.nullAndCastField(fieldToCastStr) expressionReplaced = expression.replace(fieldToCastStr, nulledCastedField, 1) expressionUnescaped = unescaper.escape(expressionReplaced) else: expressionUnescaped = unescaper.escape(expression) if ((isinstance(length, basestring) and length.isdigit()) or isinstance(length, int)): length = int(length) else: length = None if (length == 0): return (0, '') if (length and ((lastChar > 0) or (firstChar > 0))): length = (min(length, (lastChar or length)) - firstChar) if (length and (length > MAX_BISECTION_LENGTH)): length = None showEta = (conf.eta and isinstance(length, int)) numThreads = (min(conf.threads, length) or 1) if showEta: progress = ProgressBar(maxValue=length) if (timeBasedCompare and (conf.threads > 1) and (not conf.forceThreads)): warnMsg = 'multi-threading is considered unsafe in time-based data retrieval. Going to switch it off automatically' singleTimeWarnMessage(warnMsg) if (numThreads > 1): if ((not timeBasedCompare) or conf.forceThreads): debugMsg = ('starting %d thread%s' % (numThreads, ('s' if (numThreads > 1) else ''))) logger.debug(debugMsg) else: numThreads = 1 if ((conf.threads == 1) and (not timeBasedCompare) and (not conf.predictOutput)): warnMsg = 'running in a single-thread mode. Please consider ' warnMsg += "usage of option '--threads' for faster data retrieval" singleTimeWarnMessage(warnMsg) if ((conf.verbose in (1, 2)) and (not showEta) and (not hasattr(conf, 'api'))): if (isinstance(length, int) and (conf.threads > 1)): dataToStdout(('[%s] [INFO] retrieved: %s' % (time.strftime('%X'), ('_' * min(length, conf.progressWidth))))) dataToStdout(('\r[%s] [INFO] retrieved: ' % time.strftime('%X'))) else: dataToStdout(('\r[%s] [INFO] retrieved: ' % time.strftime('%X'))) hintlock = threading.Lock() def tryHint(idx): with hintlock: hintValue = kb.hintValue if ((hintValue is not None) and (len(hintValue) >= idx)): if (Backend.getIdentifiedDbms() in (DBMS.SQLITE, DBMS.ACCESS, DBMS.MAXDB, DBMS.DB2)): posValue = hintValue[(idx - 1)] else: posValue = ord(hintValue[(idx - 1)]) forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, posValue)) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: return hintValue[(idx - 1)] with hintlock: kb.hintValue = None return None def validateChar(idx, value): '\n Used in inference - in time-based SQLi if original and retrieved value are not equal there will be a deliberate delay\n ' validationPayload = re.sub(('(%s.*?)%s(.*?%s)' % (PAYLOAD_DELIMITER, INFERENCE_GREATER_CHAR, PAYLOAD_DELIMITER)), ('\\g<1>%s\\g<2>' % INFERENCE_NOT_EQUALS_CHAR), payload) if (("'%s'" % CHAR_INFERENCE_MARK) not in payload): forgedPayload = safeStringFormat(validationPayload, (expressionUnescaped, idx, value)) else: markingValue = ("'%s'" % CHAR_INFERENCE_MARK) unescapedCharValue = unescaper.escape(("'%s'" % decodeIntToUnicode(value))) forgedPayload = safeStringFormat(validationPayload, (expressionUnescaped, idx)).replace(markingValue, unescapedCharValue) result = (not Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False)) if (result and timeBasedCompare): result = (threadData.lastCode == kb.injection.data[kb.technique].trueCode) if (not result): warnMsg = ("detected HTTP code '%s' in validation phase is differing from expected '%s'" % (threadData.lastCode, kb.injection.data[kb.technique].trueCode)) singleTimeWarnMessage(warnMsg) incrementCounter(kb.technique) return result def getChar(idx, charTbl=None, continuousOrder=True, expand=(charsetType is None), shiftTable=None, retried=None): "\n continuousOrder means that distance between each two neighbour's\n numerical values is exactly 1\n " result = tryHint(idx) if result: return result if (charTbl is None): charTbl = type(asciiTbl)(asciiTbl) originalTbl = type(charTbl)(charTbl) if (continuousOrder and (shiftTable is None)): shiftTable = [2, 2, 3, 3, 5, 4] if (("'%s'" % CHAR_INFERENCE_MARK) in payload): for char in ('\n', '\r'): if (ord(char) in charTbl): charTbl.remove(ord(char)) if (not charTbl): return None elif (len(charTbl) == 1): forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, charTbl[0])) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: return decodeIntToUnicode(charTbl[0]) else: return None maxChar = maxValue = charTbl[(-1)] minChar = minValue = charTbl[0] firstCheck = False lastCheck = False unexpectedCode = False while (len(charTbl) != 1): position = None if (charsetType is None): if (not firstCheck): try: try: lastChar = [_ for _ in threadData.shared.value if (_ is not None)][(-1)] except IndexError: lastChar = None if ('a' <= lastChar <= 'z'): position = charTbl.index((ord('a') - 1)) elif ('A' <= lastChar <= 'Z'): position = charTbl.index((ord('A') - 1)) elif ('0' <= lastChar <= '9'): position = charTbl.index((ord('0') - 1)) except ValueError: pass finally: firstCheck = True elif ((not lastCheck) and (numThreads == 1)): if (charTbl[(len(charTbl) >> 1)] < ord(' ')): try: position = charTbl.index(1) except ValueError: pass finally: lastCheck = True if (position is None): position = (len(charTbl) >> 1) posValue = charTbl[position] falsePayload = None if (("'%s'" % CHAR_INFERENCE_MARK) not in payload): forgedPayload = safeStringFormat(payload, (expressionUnescaped, idx, posValue)) falsePayload = safeStringFormat(payload, (expressionUnescaped, idx, RANDOM_INTEGER_MARKER)) else: markingValue = ("'%s'" % CHAR_INFERENCE_MARK) unescapedCharValue = unescaper.escape(("'%s'" % decodeIntToUnicode(posValue))) forgedPayload = safeStringFormat(payload, (expressionUnescaped, idx)).replace(markingValue, unescapedCharValue) falsePayload = safeStringFormat(payload, (expressionUnescaped, idx)).replace(markingValue, NULL) if timeBasedCompare: if kb.responseTimeMode: kb.responseTimePayload = falsePayload else: kb.responseTimePayload = None result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if (not timeBasedCompare): unexpectedCode |= (threadData.lastCode not in (kb.injection.data[kb.technique].falseCode, kb.injection.data[kb.technique].trueCode)) if unexpectedCode: warnMsg = ("unexpected HTTP code '%s' detected. Will use (extra) validation step in similar cases" % threadData.lastCode) singleTimeWarnMessage(warnMsg) if result: minValue = posValue if (type(charTbl) != xrange): charTbl = charTbl[position:] else: charTbl = xrange(charTbl[position], (charTbl[(-1)] + 1)) else: maxValue = posValue if (type(charTbl) != xrange): charTbl = charTbl[:position] else: charTbl = xrange(charTbl[0], charTbl[position]) if (len(charTbl) == 1): if continuousOrder: if (maxValue == 1): return None elif (minValue == maxChar): if (expand and shiftTable): charTbl = xrange((maxChar + 1), ((maxChar + 1) << shiftTable.pop())) originalTbl = xrange(charTbl) maxChar = maxValue = charTbl[(-1)] minChar = minValue = charTbl[0] else: return None else: retVal = (minValue + 1) if ((retVal in originalTbl) or ((retVal == ord('\n')) and (CHAR_INFERENCE_MARK in payload))): if ((timeBasedCompare or unexpectedCode) and (not validateChar(idx, retVal))): if (not kb.originalTimeDelay): kb.originalTimeDelay = conf.timeSec threadData.validationRun = 0 if (retried < MAX_REVALIDATION_STEPS): errMsg = 'invalid character detected. retrying..' logger.error(errMsg) if timeBasedCompare: if (kb.adjustTimeDelay is not ADJUST_TIME_DELAY.DISABLE): conf.timeSec += 1 warnMsg = ('increasing time delay to %d second%s ' % (conf.timeSec, ('s' if (conf.timeSec > 1) else ''))) logger.warn(warnMsg) if (kb.adjustTimeDelay is ADJUST_TIME_DELAY.YES): dbgMsg = 'turning off time auto-adjustment mechanism' logger.debug(dbgMsg) kb.adjustTimeDelay = ADJUST_TIME_DELAY.NO return getChar(idx, originalTbl, continuousOrder, expand, shiftTable, ((retried or 0) + 1)) else: errMsg = ("unable to properly validate last character value ('%s').." % decodeIntToUnicode(retVal)) logger.error(errMsg) conf.timeSec = kb.originalTimeDelay return decodeIntToUnicode(retVal) else: if timeBasedCompare: threadData.validationRun += 1 if ((kb.adjustTimeDelay is ADJUST_TIME_DELAY.NO) and (threadData.validationRun > VALID_TIME_CHARS_RUN_THRESHOLD)): dbgMsg = 'turning back on time auto-adjustment mechanism' logger.debug(dbgMsg) kb.adjustTimeDelay = ADJUST_TIME_DELAY.YES return decodeIntToUnicode(retVal) else: return None else: if ((minValue == maxChar) or (maxValue == minChar)): return None for index in xrange(len(originalTbl)): if (originalTbl[index] == minValue): break for retVal in (originalTbl[index], originalTbl[(index + 1)]): forgedPayload = safeStringFormat(payload.replace(INFERENCE_GREATER_CHAR, INFERENCE_EQUALS_CHAR), (expressionUnescaped, idx, retVal)) result = Request.queryPage(forgedPayload, timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: return decodeIntToUnicode(retVal) return None if ((conf.threads > 1) and isinstance(length, int) and (length > 1)): threadData.shared.value = ([None] * length) threadData.shared.index = [firstChar] threadData.shared.start = firstChar try: def blindThread(): threadData = getCurrentThreadData() while kb.threadContinue: kb.locks.index.acquire() if ((threadData.shared.index[0] - firstChar) >= length): kb.locks.index.release() return threadData.shared.index[0] += 1 curidx = threadData.shared.index[0] kb.locks.index.release() if kb.threadContinue: charStart = time.time() val = getChar(curidx) if (val is None): val = INFERENCE_UNKNOWN_CHAR else: break with kb.locks.value: threadData.shared.value[((curidx - 1) - firstChar)] = val currentValue = list(threadData.shared.value) if kb.threadContinue: if showEta: progress.progress((time.time() - charStart), threadData.shared.index[0]) elif (conf.verbose >= 1): startCharIndex = 0 endCharIndex = 0 for i in xrange(length): if (currentValue[i] is not None): endCharIndex = max(endCharIndex, i) output = '' if (endCharIndex > conf.progressWidth): startCharIndex = (endCharIndex - conf.progressWidth) count = threadData.shared.start for i in xrange(startCharIndex, (endCharIndex + 1)): output += ('_' if (currentValue[i] is None) else currentValue[i]) for i in xrange(length): count += (1 if (currentValue[i] is not None) else 0) if (startCharIndex > 0): output = ('..' + output[2:]) if (((endCharIndex - startCharIndex) == conf.progressWidth) and (endCharIndex < (length - 1))): output = (output[:(-2)] + '..') if ((conf.verbose in (1, 2)) and (not showEta) and (not hasattr(conf, 'api'))): _ = (count - firstChar) output += ('_' * (min(length, conf.progressWidth) - len(output))) status = (' %d/%d (%d%%)' % (_, length, round(((100.0 * _) / length)))) output += (status if (_ != length) else (' ' * len(status))) dataToStdout(('\r[%s] [INFO] retrieved: %s' % (time.strftime('%X'), filterControlChars(output)))) runThreads(numThreads, blindThread, startThreadMsg=False) except KeyboardInterrupt: abortedFlag = True finally: value = [_ for _ in partialValue] value.extend((_ for _ in threadData.shared.value)) infoMsg = None if (None in value): partialValue = ''.join(value[:value.index(None)]) if partialValue: infoMsg = ('\r[%s] [INFO] partially retrieved: %s' % (time.strftime('%X'), filterControlChars(partialValue))) else: finalValue = ''.join(value) infoMsg = ('\r[%s] [INFO] retrieved: %s' % (time.strftime('%X'), filterControlChars(finalValue))) if ((conf.verbose in (1, 2)) and (not showEta) and infoMsg and (not hasattr(conf, 'api'))): dataToStdout(infoMsg) else: index = firstChar threadData.shared.value = '' while True: index += 1 charStart = time.time() if (conf.predictOutput and (len(partialValue) > 0) and (kb.partRun is not None)): val = None (commonValue, commonPattern, commonCharset, otherCharset) = goGoodSamaritan(partialValue, asciiTbl) if (commonValue is not None): testValue = (unescaper.escape(("'%s'" % commonValue)) if ("'" not in commonValue) else unescaper.escape(('%s' % commonValue), quote=False)) query = kb.injection.data[kb.technique].vector query = agent.prefixQuery(query.replace('[INFERENCE]', ('(%s)=%s' % (expressionUnescaped, testValue)))) query = agent.suffixQuery(query) result = Request.queryPage(agent.payload(newValue=query), timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: if showEta: progress.progress((time.time() - charStart), len(commonValue)) elif ((conf.verbose in (1, 2)) or hasattr(conf, 'api')): dataToStdout(filterControlChars(commonValue[(index - 1):])) finalValue = commonValue break if (commonPattern is not None): subquery = (queries[Backend.getIdentifiedDbms()].substring.query % (expressionUnescaped, 1, len(commonPattern))) testValue = (unescaper.escape(("'%s'" % commonPattern)) if ("'" not in commonPattern) else unescaper.escape(('%s' % commonPattern), quote=False)) query = kb.injection.data[kb.technique].vector query = agent.prefixQuery(query.replace('[INFERENCE]', ('(%s)=%s' % (subquery, testValue)))) query = agent.suffixQuery(query) result = Request.queryPage(agent.payload(newValue=query), timeBasedCompare=timeBasedCompare, raise404=False) incrementCounter(kb.technique) if result: val = commonPattern[(index - 1):] index += (len(val) - 1) if ((not val) and commonCharset): val = getChar(index, commonCharset, False) if (not val): val = getChar(index, otherCharset, (otherCharset == asciiTbl)) else: val = getChar(index, asciiTbl) if (val is None): finalValue = partialValue break if kb.data.processChar: val = kb.data.processChar(val) threadData.shared.value = partialValue = (partialValue + val) if showEta: progress.progress((time.time() - charStart), index) elif ((conf.verbose in (1, 2)) or hasattr(conf, 'api')): dataToStdout(filterControlChars(val)) if ((len(partialValue) > INFERENCE_BLANK_BREAK) and partialValue[(- INFERENCE_BLANK_BREAK):].isspace() and (partialValue.strip(' ')[(-1):] != '\n')): finalValue = partialValue[:(- INFERENCE_BLANK_BREAK)] break if ((lastChar > 0) and (index >= lastChar)): finalValue = ('' if (length == 0) else partialValue) finalValue = (finalValue.rstrip() if (len(finalValue) > 1) else finalValue) partialValue = None break except KeyboardInterrupt: abortedFlag = True finally: kb.prependFlag = False kb.stickyLevel = None retrievedLength = len((finalValue or '')) if (finalValue is not None): finalValue = (decodeHexValue(finalValue) if conf.hexConvert else finalValue) hashDBWrite(expression, finalValue) elif partialValue: hashDBWrite(expression, ('%s%s' % ((PARTIAL_VALUE_MARKER if (not conf.hexConvert) else PARTIAL_HEX_VALUE_MARKER), partialValue))) if (conf.hexConvert and (not abortedFlag) and (not hasattr(conf, 'api'))): infoMsg = ('\r[%s] [INFO] retrieved: %s %s\n' % (time.strftime('%X'), filterControlChars(finalValue), (' ' * retrievedLength))) dataToStdout(infoMsg) else: if ((conf.verbose in (1, 2)) and (not showEta) and (not hasattr(conf, 'api'))): dataToStdout('\n') if (((conf.verbose in (1, 2)) and showEta) or (conf.verbose >= 3)): infoMsg = ('retrieved: %s' % filterControlChars(finalValue)) logger.info(infoMsg) if kb.threadException: raise SqlmapThreadException('something unexpected happened inside the threads') if abortedFlag: raise KeyboardInterrupt _ = (finalValue or partialValue) return (getCounter(kb.technique), (safecharencode(_) if kb.safeCharEncode else _))
null
null
null
What does this function do?
def certificates(config, unused_plugins): cert_manager.certificates(config)
null
null
null
Display information about certs configured with Certbot
pcsd
def certificates config unused plugins cert manager certificates config
7933
def certificates(config, unused_plugins): cert_manager.certificates(config)
Display information about certs configured with Certbot
display information about certs configured with certbot
Question: What does this function do? Code: def certificates(config, unused_plugins): cert_manager.certificates(config)
null
null
null
What does this function do?
def transfer_accept(context, transfer_id, user_id, project_id): return IMPL.transfer_accept(context, transfer_id, user_id, project_id)
null
null
null
Accept a volume transfer.
pcsd
def transfer accept context transfer id user id project id return IMPL transfer accept context transfer id user id project id
7934
def transfer_accept(context, transfer_id, user_id, project_id): return IMPL.transfer_accept(context, transfer_id, user_id, project_id)
Accept a volume transfer.
accept a volume transfer .
Question: What does this function do? Code: def transfer_accept(context, transfer_id, user_id, project_id): return IMPL.transfer_accept(context, transfer_id, user_id, project_id)
null
null
null
What does this function do?
def upgrade(migrate_engine): if (migrate_engine.name in ('sqlite', 'postgresql')): for (table_name, index_name, column_names) in INDEXES: ensure_index_exists(migrate_engine, table_name, index_name, column_names) elif (migrate_engine.name == 'mysql'): ensure_index_removed(migrate_engine, 'dns_domains', 'project_id') ensure_index_exists(migrate_engine, 'dns_domains', 'dns_domains_project_id_idx', ['project_id']) ensure_index_removed(migrate_engine, 'virtual_interfaces', 'network_id') ensure_index_exists(migrate_engine, 'virtual_interfaces', 'virtual_interfaces_network_id_idx', ['network_id'])
null
null
null
Add indexes missing on SQLite and PostgreSQL.
pcsd
def upgrade migrate engine if migrate engine name in 'sqlite' 'postgresql' for table name index name column names in INDEXES ensure index exists migrate engine table name index name column names elif migrate engine name == 'mysql' ensure index removed migrate engine 'dns domains' 'project id' ensure index exists migrate engine 'dns domains' 'dns domains project id idx' ['project id'] ensure index removed migrate engine 'virtual interfaces' 'network id' ensure index exists migrate engine 'virtual interfaces' 'virtual interfaces network id idx' ['network id']
7950
def upgrade(migrate_engine): if (migrate_engine.name in ('sqlite', 'postgresql')): for (table_name, index_name, column_names) in INDEXES: ensure_index_exists(migrate_engine, table_name, index_name, column_names) elif (migrate_engine.name == 'mysql'): ensure_index_removed(migrate_engine, 'dns_domains', 'project_id') ensure_index_exists(migrate_engine, 'dns_domains', 'dns_domains_project_id_idx', ['project_id']) ensure_index_removed(migrate_engine, 'virtual_interfaces', 'network_id') ensure_index_exists(migrate_engine, 'virtual_interfaces', 'virtual_interfaces_network_id_idx', ['network_id'])
Add indexes missing on SQLite and PostgreSQL.
add indexes missing on sqlite and postgresql .
Question: What does this function do? Code: def upgrade(migrate_engine): if (migrate_engine.name in ('sqlite', 'postgresql')): for (table_name, index_name, column_names) in INDEXES: ensure_index_exists(migrate_engine, table_name, index_name, column_names) elif (migrate_engine.name == 'mysql'): ensure_index_removed(migrate_engine, 'dns_domains', 'project_id') ensure_index_exists(migrate_engine, 'dns_domains', 'dns_domains_project_id_idx', ['project_id']) ensure_index_removed(migrate_engine, 'virtual_interfaces', 'network_id') ensure_index_exists(migrate_engine, 'virtual_interfaces', 'virtual_interfaces_network_id_idx', ['network_id'])
null
null
null
What does this function do?
def partition_entropy_by(inputs, attribute): partitions = partition_by(inputs, attribute) return partition_entropy(partitions.values())
null
null
null
computes the entropy corresponding to the given partition
pcsd
def partition entropy by inputs attribute partitions = partition by inputs attribute return partition entropy partitions values
7952
def partition_entropy_by(inputs, attribute): partitions = partition_by(inputs, attribute) return partition_entropy(partitions.values())
computes the entropy corresponding to the given partition
computes the entropy corresponding to the given partition
Question: What does this function do? Code: def partition_entropy_by(inputs, attribute): partitions = partition_by(inputs, attribute) return partition_entropy(partitions.values())
null
null
null
What does this function do?
def imports_on_separate_lines(logical_line): line = logical_line if line.startswith('import '): found = line.find(',') if (found > (-1)): return (found, 'E401 multiple imports on one line')
null
null
null
Imports should usually be on separate lines.
pcsd
def imports on separate lines logical line line = logical line if line startswith 'import ' found = line find ' ' if found > -1 return found 'E401 multiple imports on one line'
7955
def imports_on_separate_lines(logical_line): line = logical_line if line.startswith('import '): found = line.find(',') if (found > (-1)): return (found, 'E401 multiple imports on one line')
Imports should usually be on separate lines.
imports should usually be on separate lines .
Question: What does this function do? Code: def imports_on_separate_lines(logical_line): line = logical_line if line.startswith('import '): found = line.find(',') if (found > (-1)): return (found, 'E401 multiple imports on one line')
null
null
null
What does this function do?
@verbose def _read_cov(fid, node, cov_kind, limited=False, verbose=None): covs = dir_tree_find(node, FIFF.FIFFB_MNE_COV) if (len(covs) == 0): raise ValueError('No covariance matrices found') for p in range(len(covs)): tag = find_tag(fid, covs[p], FIFF.FIFF_MNE_COV_KIND) if ((tag is not None) and (int(tag.data) == cov_kind)): this = covs[p] tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_DIM) if (tag is None): raise ValueError('Covariance matrix dimension not found') dim = int(tag.data) tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_NFREE) if (tag is None): nfree = (-1) else: nfree = int(tag.data) tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_METHOD) if (tag is None): method = None else: method = tag.data tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_SCORE) if (tag is None): score = None else: score = tag.data[0] tag = find_tag(fid, this, FIFF.FIFF_MNE_ROW_NAMES) if (tag is None): names = [] else: names = tag.data.split(':') if (len(names) != dim): raise ValueError('Number of names does not match covariance matrix dimension') tag = find_tag(fid, this, FIFF.FIFF_MNE_COV) if (tag is None): tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_DIAG) if (tag is None): raise ValueError('No covariance matrix data found') else: data = tag.data diag = True logger.info((' %d x %d diagonal covariance (kind = %d) found.' % (dim, dim, cov_kind))) else: from scipy import sparse if (not sparse.issparse(tag.data)): vals = tag.data data = np.zeros((dim, dim)) data[(np.tril(np.ones((dim, dim))) > 0)] = vals data = (data + data.T) data.flat[::(dim + 1)] /= 2.0 diag = False logger.info((' %d x %d full covariance (kind = %d) found.' % (dim, dim, cov_kind))) else: diag = False data = tag.data logger.info((' %d x %d sparse covariance (kind = %d) found.' % (dim, dim, cov_kind))) tag1 = find_tag(fid, this, FIFF.FIFF_MNE_COV_EIGENVALUES) tag2 = find_tag(fid, this, FIFF.FIFF_MNE_COV_EIGENVECTORS) if ((tag1 is not None) and (tag2 is not None)): eig = tag1.data eigvec = tag2.data else: eig = None eigvec = None projs = _read_proj(fid, this) bads = read_bad_channels(fid, this) assert (dim == len(data)) assert (data.ndim == (1 if diag else 2)) cov = dict(kind=cov_kind, diag=diag, dim=dim, names=names, data=data, projs=projs, bads=bads, nfree=nfree, eig=eig, eigvec=eigvec) if (score is not None): cov['loglik'] = score if (method is not None): cov['method'] = method if limited: del cov['kind'], cov['dim'], cov['diag'] return cov logger.info((' Did not find the desired covariance matrix (kind = %d)' % cov_kind)) return None
null
null
null
Read a noise covariance matrix.
pcsd
@verbose def read cov fid node cov kind limited=False verbose=None covs = dir tree find node FIFF FIFFB MNE COV if len covs == 0 raise Value Error 'No covariance matrices found' for p in range len covs tag = find tag fid covs[p] FIFF FIFF MNE COV KIND if tag is not None and int tag data == cov kind this = covs[p] tag = find tag fid this FIFF FIFF MNE COV DIM if tag is None raise Value Error 'Covariance matrix dimension not found' dim = int tag data tag = find tag fid this FIFF FIFF MNE COV NFREE if tag is None nfree = -1 else nfree = int tag data tag = find tag fid this FIFF FIFF MNE COV METHOD if tag is None method = None else method = tag data tag = find tag fid this FIFF FIFF MNE COV SCORE if tag is None score = None else score = tag data[0] tag = find tag fid this FIFF FIFF MNE ROW NAMES if tag is None names = [] else names = tag data split ' ' if len names != dim raise Value Error 'Number of names does not match covariance matrix dimension' tag = find tag fid this FIFF FIFF MNE COV if tag is None tag = find tag fid this FIFF FIFF MNE COV DIAG if tag is None raise Value Error 'No covariance matrix data found' else data = tag data diag = True logger info ' %d x %d diagonal covariance kind = %d found ' % dim dim cov kind else from scipy import sparse if not sparse issparse tag data vals = tag data data = np zeros dim dim data[ np tril np ones dim dim > 0 ] = vals data = data + data T data flat[ dim + 1 ] /= 2 0 diag = False logger info ' %d x %d full covariance kind = %d found ' % dim dim cov kind else diag = False data = tag data logger info ' %d x %d sparse covariance kind = %d found ' % dim dim cov kind tag1 = find tag fid this FIFF FIFF MNE COV EIGENVALUES tag2 = find tag fid this FIFF FIFF MNE COV EIGENVECTORS if tag1 is not None and tag2 is not None eig = tag1 data eigvec = tag2 data else eig = None eigvec = None projs = read proj fid this bads = read bad channels fid this assert dim == len data assert data ndim == 1 if diag else 2 cov = dict kind=cov kind diag=diag dim=dim names=names data=data projs=projs bads=bads nfree=nfree eig=eig eigvec=eigvec if score is not None cov['loglik'] = score if method is not None cov['method'] = method if limited del cov['kind'] cov['dim'] cov['diag'] return cov logger info ' Did not find the desired covariance matrix kind = %d ' % cov kind return None
7957
@verbose def _read_cov(fid, node, cov_kind, limited=False, verbose=None): covs = dir_tree_find(node, FIFF.FIFFB_MNE_COV) if (len(covs) == 0): raise ValueError('No covariance matrices found') for p in range(len(covs)): tag = find_tag(fid, covs[p], FIFF.FIFF_MNE_COV_KIND) if ((tag is not None) and (int(tag.data) == cov_kind)): this = covs[p] tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_DIM) if (tag is None): raise ValueError('Covariance matrix dimension not found') dim = int(tag.data) tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_NFREE) if (tag is None): nfree = (-1) else: nfree = int(tag.data) tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_METHOD) if (tag is None): method = None else: method = tag.data tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_SCORE) if (tag is None): score = None else: score = tag.data[0] tag = find_tag(fid, this, FIFF.FIFF_MNE_ROW_NAMES) if (tag is None): names = [] else: names = tag.data.split(':') if (len(names) != dim): raise ValueError('Number of names does not match covariance matrix dimension') tag = find_tag(fid, this, FIFF.FIFF_MNE_COV) if (tag is None): tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_DIAG) if (tag is None): raise ValueError('No covariance matrix data found') else: data = tag.data diag = True logger.info((' %d x %d diagonal covariance (kind = %d) found.' % (dim, dim, cov_kind))) else: from scipy import sparse if (not sparse.issparse(tag.data)): vals = tag.data data = np.zeros((dim, dim)) data[(np.tril(np.ones((dim, dim))) > 0)] = vals data = (data + data.T) data.flat[::(dim + 1)] /= 2.0 diag = False logger.info((' %d x %d full covariance (kind = %d) found.' % (dim, dim, cov_kind))) else: diag = False data = tag.data logger.info((' %d x %d sparse covariance (kind = %d) found.' % (dim, dim, cov_kind))) tag1 = find_tag(fid, this, FIFF.FIFF_MNE_COV_EIGENVALUES) tag2 = find_tag(fid, this, FIFF.FIFF_MNE_COV_EIGENVECTORS) if ((tag1 is not None) and (tag2 is not None)): eig = tag1.data eigvec = tag2.data else: eig = None eigvec = None projs = _read_proj(fid, this) bads = read_bad_channels(fid, this) assert (dim == len(data)) assert (data.ndim == (1 if diag else 2)) cov = dict(kind=cov_kind, diag=diag, dim=dim, names=names, data=data, projs=projs, bads=bads, nfree=nfree, eig=eig, eigvec=eigvec) if (score is not None): cov['loglik'] = score if (method is not None): cov['method'] = method if limited: del cov['kind'], cov['dim'], cov['diag'] return cov logger.info((' Did not find the desired covariance matrix (kind = %d)' % cov_kind)) return None
Read a noise covariance matrix.
read a noise covariance matrix .
Question: What does this function do? Code: @verbose def _read_cov(fid, node, cov_kind, limited=False, verbose=None): covs = dir_tree_find(node, FIFF.FIFFB_MNE_COV) if (len(covs) == 0): raise ValueError('No covariance matrices found') for p in range(len(covs)): tag = find_tag(fid, covs[p], FIFF.FIFF_MNE_COV_KIND) if ((tag is not None) and (int(tag.data) == cov_kind)): this = covs[p] tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_DIM) if (tag is None): raise ValueError('Covariance matrix dimension not found') dim = int(tag.data) tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_NFREE) if (tag is None): nfree = (-1) else: nfree = int(tag.data) tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_METHOD) if (tag is None): method = None else: method = tag.data tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_SCORE) if (tag is None): score = None else: score = tag.data[0] tag = find_tag(fid, this, FIFF.FIFF_MNE_ROW_NAMES) if (tag is None): names = [] else: names = tag.data.split(':') if (len(names) != dim): raise ValueError('Number of names does not match covariance matrix dimension') tag = find_tag(fid, this, FIFF.FIFF_MNE_COV) if (tag is None): tag = find_tag(fid, this, FIFF.FIFF_MNE_COV_DIAG) if (tag is None): raise ValueError('No covariance matrix data found') else: data = tag.data diag = True logger.info((' %d x %d diagonal covariance (kind = %d) found.' % (dim, dim, cov_kind))) else: from scipy import sparse if (not sparse.issparse(tag.data)): vals = tag.data data = np.zeros((dim, dim)) data[(np.tril(np.ones((dim, dim))) > 0)] = vals data = (data + data.T) data.flat[::(dim + 1)] /= 2.0 diag = False logger.info((' %d x %d full covariance (kind = %d) found.' % (dim, dim, cov_kind))) else: diag = False data = tag.data logger.info((' %d x %d sparse covariance (kind = %d) found.' % (dim, dim, cov_kind))) tag1 = find_tag(fid, this, FIFF.FIFF_MNE_COV_EIGENVALUES) tag2 = find_tag(fid, this, FIFF.FIFF_MNE_COV_EIGENVECTORS) if ((tag1 is not None) and (tag2 is not None)): eig = tag1.data eigvec = tag2.data else: eig = None eigvec = None projs = _read_proj(fid, this) bads = read_bad_channels(fid, this) assert (dim == len(data)) assert (data.ndim == (1 if diag else 2)) cov = dict(kind=cov_kind, diag=diag, dim=dim, names=names, data=data, projs=projs, bads=bads, nfree=nfree, eig=eig, eigvec=eigvec) if (score is not None): cov['loglik'] = score if (method is not None): cov['method'] = method if limited: del cov['kind'], cov['dim'], cov['diag'] return cov logger.info((' Did not find the desired covariance matrix (kind = %d)' % cov_kind)) return None
null
null
null
What does this function do?
def stem(word): return fix_ending(remove_ending(word))
null
null
null
Returns the stemmed version of the argument string.
pcsd
def stem word return fix ending remove ending word
7963
def stem(word): return fix_ending(remove_ending(word))
Returns the stemmed version of the argument string.
returns the stemmed version of the argument string .
Question: What does this function do? Code: def stem(word): return fix_ending(remove_ending(word))
null
null
null
What does this function do?
def _image_tag_delete_all(context, image_id, delete_time=None, session=None): tags_updated_count = _image_child_entry_delete_all(models.ImageTag, image_id, delete_time, session) return tags_updated_count
null
null
null
Delete all image tags for given image
pcsd
def image tag delete all context image id delete time=None session=None tags updated count = image child entry delete all models Image Tag image id delete time session return tags updated count
7966
def _image_tag_delete_all(context, image_id, delete_time=None, session=None): tags_updated_count = _image_child_entry_delete_all(models.ImageTag, image_id, delete_time, session) return tags_updated_count
Delete all image tags for given image
delete all image tags for given image
Question: What does this function do? Code: def _image_tag_delete_all(context, image_id, delete_time=None, session=None): tags_updated_count = _image_child_entry_delete_all(models.ImageTag, image_id, delete_time, session) return tags_updated_count
null
null
null
What does this function do?
def clip(x, min_value, max_value): if ((max_value is not None) and (max_value < min_value)): max_value = min_value if (max_value is None): max_value = np.inf min_value = _to_tensor(min_value, x.dtype.base_dtype) max_value = _to_tensor(max_value, x.dtype.base_dtype) return tf.clip_by_value(x, min_value, max_value)
null
null
null
Element-wise value clipping. # Returns A tensor.
pcsd
def clip x min value max value if max value is not None and max value < min value max value = min value if max value is None max value = np inf min value = to tensor min value x dtype base dtype max value = to tensor max value x dtype base dtype return tf clip by value x min value max value
7969
def clip(x, min_value, max_value): if ((max_value is not None) and (max_value < min_value)): max_value = min_value if (max_value is None): max_value = np.inf min_value = _to_tensor(min_value, x.dtype.base_dtype) max_value = _to_tensor(max_value, x.dtype.base_dtype) return tf.clip_by_value(x, min_value, max_value)
Element-wise value clipping. # Returns A tensor.
element - wise value clipping .
Question: What does this function do? Code: def clip(x, min_value, max_value): if ((max_value is not None) and (max_value < min_value)): max_value = min_value if (max_value is None): max_value = np.inf min_value = _to_tensor(min_value, x.dtype.base_dtype) max_value = _to_tensor(max_value, x.dtype.base_dtype) return tf.clip_by_value(x, min_value, max_value)
null
null
null
What does this function do?
def initialize_scheduler(): from headphones import updater, searcher, librarysync, postprocessor, torrentfinished with SCHED_LOCK: start_jobs = (not len(SCHED.get_jobs())) minutes = CONFIG.SEARCH_INTERVAL schedule_job(searcher.searchforalbum, 'Search for Wanted', hours=0, minutes=minutes) minutes = CONFIG.DOWNLOAD_SCAN_INTERVAL schedule_job(postprocessor.checkFolder, 'Download Scan', hours=0, minutes=minutes) hours = CONFIG.LIBRARYSCAN_INTERVAL schedule_job(librarysync.libraryScan, 'Library Scan', hours=hours, minutes=0) hours = CONFIG.UPDATE_DB_INTERVAL schedule_job(updater.dbUpdate, 'MusicBrainz Update', hours=hours, minutes=0) if CONFIG.CHECK_GITHUB: if CONFIG.CHECK_GITHUB_INTERVAL: minutes = CONFIG.CHECK_GITHUB_INTERVAL else: minutes = 0 schedule_job(versioncheck.checkGithub, 'Check GitHub for updates', hours=0, minutes=minutes) minutes = CONFIG.TORRENT_REMOVAL_INTERVAL schedule_job(torrentfinished.checkTorrentFinished, 'Torrent removal check', hours=0, minutes=minutes) if (start_jobs and len(SCHED.get_jobs())): try: SCHED.start() except Exception as e: logger.info(e)
null
null
null
Start the scheduled background tasks. Re-schedule if interval settings changed.
pcsd
def initialize scheduler from headphones import updater searcher librarysync postprocessor torrentfinished with SCHED LOCK start jobs = not len SCHED get jobs minutes = CONFIG SEARCH INTERVAL schedule job searcher searchforalbum 'Search for Wanted' hours=0 minutes=minutes minutes = CONFIG DOWNLOAD SCAN INTERVAL schedule job postprocessor check Folder 'Download Scan' hours=0 minutes=minutes hours = CONFIG LIBRARYSCAN INTERVAL schedule job librarysync library Scan 'Library Scan' hours=hours minutes=0 hours = CONFIG UPDATE DB INTERVAL schedule job updater db Update 'Music Brainz Update' hours=hours minutes=0 if CONFIG CHECK GITHUB if CONFIG CHECK GITHUB INTERVAL minutes = CONFIG CHECK GITHUB INTERVAL else minutes = 0 schedule job versioncheck check Github 'Check Git Hub for updates' hours=0 minutes=minutes minutes = CONFIG TORRENT REMOVAL INTERVAL schedule job torrentfinished check Torrent Finished 'Torrent removal check' hours=0 minutes=minutes if start jobs and len SCHED get jobs try SCHED start except Exception as e logger info e
7976
def initialize_scheduler(): from headphones import updater, searcher, librarysync, postprocessor, torrentfinished with SCHED_LOCK: start_jobs = (not len(SCHED.get_jobs())) minutes = CONFIG.SEARCH_INTERVAL schedule_job(searcher.searchforalbum, 'Search for Wanted', hours=0, minutes=minutes) minutes = CONFIG.DOWNLOAD_SCAN_INTERVAL schedule_job(postprocessor.checkFolder, 'Download Scan', hours=0, minutes=minutes) hours = CONFIG.LIBRARYSCAN_INTERVAL schedule_job(librarysync.libraryScan, 'Library Scan', hours=hours, minutes=0) hours = CONFIG.UPDATE_DB_INTERVAL schedule_job(updater.dbUpdate, 'MusicBrainz Update', hours=hours, minutes=0) if CONFIG.CHECK_GITHUB: if CONFIG.CHECK_GITHUB_INTERVAL: minutes = CONFIG.CHECK_GITHUB_INTERVAL else: minutes = 0 schedule_job(versioncheck.checkGithub, 'Check GitHub for updates', hours=0, minutes=minutes) minutes = CONFIG.TORRENT_REMOVAL_INTERVAL schedule_job(torrentfinished.checkTorrentFinished, 'Torrent removal check', hours=0, minutes=minutes) if (start_jobs and len(SCHED.get_jobs())): try: SCHED.start() except Exception as e: logger.info(e)
Start the scheduled background tasks. Re-schedule if interval settings changed.
start the scheduled background tasks .
Question: What does this function do? Code: def initialize_scheduler(): from headphones import updater, searcher, librarysync, postprocessor, torrentfinished with SCHED_LOCK: start_jobs = (not len(SCHED.get_jobs())) minutes = CONFIG.SEARCH_INTERVAL schedule_job(searcher.searchforalbum, 'Search for Wanted', hours=0, minutes=minutes) minutes = CONFIG.DOWNLOAD_SCAN_INTERVAL schedule_job(postprocessor.checkFolder, 'Download Scan', hours=0, minutes=minutes) hours = CONFIG.LIBRARYSCAN_INTERVAL schedule_job(librarysync.libraryScan, 'Library Scan', hours=hours, minutes=0) hours = CONFIG.UPDATE_DB_INTERVAL schedule_job(updater.dbUpdate, 'MusicBrainz Update', hours=hours, minutes=0) if CONFIG.CHECK_GITHUB: if CONFIG.CHECK_GITHUB_INTERVAL: minutes = CONFIG.CHECK_GITHUB_INTERVAL else: minutes = 0 schedule_job(versioncheck.checkGithub, 'Check GitHub for updates', hours=0, minutes=minutes) minutes = CONFIG.TORRENT_REMOVAL_INTERVAL schedule_job(torrentfinished.checkTorrentFinished, 'Torrent removal check', hours=0, minutes=minutes) if (start_jobs and len(SCHED.get_jobs())): try: SCHED.start() except Exception as e: logger.info(e)
null
null
null
What does this function do?
def create_bucket(bucket_name): storage_client = storage.Client() bucket = storage_client.create_bucket(bucket_name) print 'Bucket {} created'.format(bucket.name)
null
null
null
Creates a new bucket.
pcsd
def create bucket bucket name storage client = storage Client bucket = storage client create bucket bucket name print 'Bucket {} created' format bucket name
7979
def create_bucket(bucket_name): storage_client = storage.Client() bucket = storage_client.create_bucket(bucket_name) print 'Bucket {} created'.format(bucket.name)
Creates a new bucket.
creates a new bucket .
Question: What does this function do? Code: def create_bucket(bucket_name): storage_client = storage.Client() bucket = storage_client.create_bucket(bucket_name) print 'Bucket {} created'.format(bucket.name)
null
null
null
What does this function do?
def register(linter): linter.register_checker(TypeChecker(linter))
null
null
null
required method to auto register this checker
pcsd
def register linter linter register checker Type Checker linter
7984
def register(linter): linter.register_checker(TypeChecker(linter))
required method to auto register this checker
required method to auto register this checker
Question: What does this function do? Code: def register(linter): linter.register_checker(TypeChecker(linter))
null
null
null
What does this function do?
def _CheckFacetDepth(depth): if (depth is None): return None else: return _CheckInteger(depth, 'depth', zero_ok=False, upper_bound=MAXIMUM_DEPTH_FOR_FACETED_SEARCH)
null
null
null
Checks the facet depth to return is an integer within range.
pcsd
def Check Facet Depth depth if depth is None return None else return Check Integer depth 'depth' zero ok=False upper bound=MAXIMUM DEPTH FOR FACETED SEARCH
7988
def _CheckFacetDepth(depth): if (depth is None): return None else: return _CheckInteger(depth, 'depth', zero_ok=False, upper_bound=MAXIMUM_DEPTH_FOR_FACETED_SEARCH)
Checks the facet depth to return is an integer within range.
checks the facet depth to return is an integer within range .
Question: What does this function do? Code: def _CheckFacetDepth(depth): if (depth is None): return None else: return _CheckInteger(depth, 'depth', zero_ok=False, upper_bound=MAXIMUM_DEPTH_FOR_FACETED_SEARCH)
null
null
null
What does this function do?
def _edge_betweenness(G, source, nodes=None, cutoff=False): (pred, length) = nx.predecessor(G, source, cutoff=cutoff, return_seen=True) onodes = [n for (n, d) in sorted(length.items(), key=itemgetter(1))] between = {} for (u, v) in G.edges(nodes): between[(u, v)] = 1.0 between[(v, u)] = 1.0 while onodes: v = onodes.pop() if (v in pred): num_paths = len(pred[v]) for w in pred[v]: if (w in pred): num_paths = len(pred[w]) for x in pred[w]: between[(w, x)] += (between[(v, w)] / num_paths) between[(x, w)] += (between[(w, v)] / num_paths) return between
null
null
null
Edge betweenness helper.
pcsd
def edge betweenness G source nodes=None cutoff=False pred length = nx predecessor G source cutoff=cutoff return seen=True onodes = [n for n d in sorted length items key=itemgetter 1 ] between = {} for u v in G edges nodes between[ u v ] = 1 0 between[ v u ] = 1 0 while onodes v = onodes pop if v in pred num paths = len pred[v] for w in pred[v] if w in pred num paths = len pred[w] for x in pred[w] between[ w x ] += between[ v w ] / num paths between[ x w ] += between[ w v ] / num paths return between
7990
def _edge_betweenness(G, source, nodes=None, cutoff=False): (pred, length) = nx.predecessor(G, source, cutoff=cutoff, return_seen=True) onodes = [n for (n, d) in sorted(length.items(), key=itemgetter(1))] between = {} for (u, v) in G.edges(nodes): between[(u, v)] = 1.0 between[(v, u)] = 1.0 while onodes: v = onodes.pop() if (v in pred): num_paths = len(pred[v]) for w in pred[v]: if (w in pred): num_paths = len(pred[w]) for x in pred[w]: between[(w, x)] += (between[(v, w)] / num_paths) between[(x, w)] += (between[(w, v)] / num_paths) return between
Edge betweenness helper.
edge betweenness helper .
Question: What does this function do? Code: def _edge_betweenness(G, source, nodes=None, cutoff=False): (pred, length) = nx.predecessor(G, source, cutoff=cutoff, return_seen=True) onodes = [n for (n, d) in sorted(length.items(), key=itemgetter(1))] between = {} for (u, v) in G.edges(nodes): between[(u, v)] = 1.0 between[(v, u)] = 1.0 while onodes: v = onodes.pop() if (v in pred): num_paths = len(pred[v]) for w in pred[v]: if (w in pred): num_paths = len(pred[w]) for x in pred[w]: between[(w, x)] += (between[(v, w)] / num_paths) between[(x, w)] += (between[(w, v)] / num_paths) return between
null
null
null
What does this function do?
def main(): args = vars(ArgParser().parse_args()) r_time = 0 ports = [4505, 4506] print('Sniffing device {0}'.format(args['iface'])) stat = {'4506/new': 0, '4506/est': 0, '4506/fin': 0, '4505/new': 0, '4505/est': 0, '4505/fin': 0, 'ips/4505': 0, 'ips/4506': 0} if args['only_ip']: print('IPs making new connections (ports:{0}, interval:{1})'.format(ports, args['ival'])) else: print('Salt-Master Network Status (ports:{0}, interval:{1})'.format(ports, args['ival'])) try: while 1: s_time = int(time.time()) packet = next(PCAPParser(args['iface']).run()) p_state = filter_new_cons(packet) ips_auth = [] ips_push = [] if (p_state == 10): stat['4505/new'] += 1 if (packet['ip']['s_addr'] not in ips_auth): ips_auth.append(packet['ip']['s_addr']) elif (p_state == 12): stat['4505/fin'] += 1 elif (p_state == 100): stat['4506/new'] += 1 if (packet['ip']['s_addr'] not in ips_push): ips_push.append(packet['ip']['s_addr']) elif (p_state == 120): stat['4506/fin'] += 1 (stat['4505/est'], stat['4506/est']) = next(SaltNetstat().run()) if ((s_time % args['ival']) == 0): if (r_time != s_time): if args['only_ip']: msg = 'IPs/4505: {0}, IPs/4506: {1}'.format(len(ips_auth), len(ips_push)) else: msg = '4505=>[ est: {0}, '.format(stat['4505/est']) msg += 'new: {0}/s, '.format((stat['4505/new'] / args['ival'])) msg += 'fin: {0}/s ] '.format((stat['4505/fin'] / args['ival'])) msg += ' 4506=>[ est: {0}, '.format(stat['4506/est']) msg += 'new: {0}/s, '.format((stat['4506/new'] / args['ival'])) msg += 'fin: {0}/s ]'.format((stat['4506/fin'] / args['ival'])) print(msg) for item in stat: stat[item] = 0 r_time = s_time except KeyboardInterrupt: sys.exit(1)
null
null
null
main loop for whole script
pcsd
def main args = vars Arg Parser parse args r time = 0 ports = [4505 4506] print 'Sniffing device {0}' format args['iface'] stat = {'4506/new' 0 '4506/est' 0 '4506/fin' 0 '4505/new' 0 '4505/est' 0 '4505/fin' 0 'ips/4505' 0 'ips/4506' 0} if args['only ip'] print 'I Ps making new connections ports {0} interval {1} ' format ports args['ival'] else print 'Salt-Master Network Status ports {0} interval {1} ' format ports args['ival'] try while 1 s time = int time time packet = next PCAP Parser args['iface'] run p state = filter new cons packet ips auth = [] ips push = [] if p state == 10 stat['4505/new'] += 1 if packet['ip']['s addr'] not in ips auth ips auth append packet['ip']['s addr'] elif p state == 12 stat['4505/fin'] += 1 elif p state == 100 stat['4506/new'] += 1 if packet['ip']['s addr'] not in ips push ips push append packet['ip']['s addr'] elif p state == 120 stat['4506/fin'] += 1 stat['4505/est'] stat['4506/est'] = next Salt Netstat run if s time % args['ival'] == 0 if r time != s time if args['only ip'] msg = 'I Ps/4505 {0} I Ps/4506 {1}' format len ips auth len ips push else msg = '4505=>[ est {0} ' format stat['4505/est'] msg += 'new {0}/s ' format stat['4505/new'] / args['ival'] msg += 'fin {0}/s ] ' format stat['4505/fin'] / args['ival'] msg += ' 4506=>[ est {0} ' format stat['4506/est'] msg += 'new {0}/s ' format stat['4506/new'] / args['ival'] msg += 'fin {0}/s ]' format stat['4506/fin'] / args['ival'] print msg for item in stat stat[item] = 0 r time = s time except Keyboard Interrupt sys exit 1
7998
def main(): args = vars(ArgParser().parse_args()) r_time = 0 ports = [4505, 4506] print('Sniffing device {0}'.format(args['iface'])) stat = {'4506/new': 0, '4506/est': 0, '4506/fin': 0, '4505/new': 0, '4505/est': 0, '4505/fin': 0, 'ips/4505': 0, 'ips/4506': 0} if args['only_ip']: print('IPs making new connections (ports:{0}, interval:{1})'.format(ports, args['ival'])) else: print('Salt-Master Network Status (ports:{0}, interval:{1})'.format(ports, args['ival'])) try: while 1: s_time = int(time.time()) packet = next(PCAPParser(args['iface']).run()) p_state = filter_new_cons(packet) ips_auth = [] ips_push = [] if (p_state == 10): stat['4505/new'] += 1 if (packet['ip']['s_addr'] not in ips_auth): ips_auth.append(packet['ip']['s_addr']) elif (p_state == 12): stat['4505/fin'] += 1 elif (p_state == 100): stat['4506/new'] += 1 if (packet['ip']['s_addr'] not in ips_push): ips_push.append(packet['ip']['s_addr']) elif (p_state == 120): stat['4506/fin'] += 1 (stat['4505/est'], stat['4506/est']) = next(SaltNetstat().run()) if ((s_time % args['ival']) == 0): if (r_time != s_time): if args['only_ip']: msg = 'IPs/4505: {0}, IPs/4506: {1}'.format(len(ips_auth), len(ips_push)) else: msg = '4505=>[ est: {0}, '.format(stat['4505/est']) msg += 'new: {0}/s, '.format((stat['4505/new'] / args['ival'])) msg += 'fin: {0}/s ] '.format((stat['4505/fin'] / args['ival'])) msg += ' 4506=>[ est: {0}, '.format(stat['4506/est']) msg += 'new: {0}/s, '.format((stat['4506/new'] / args['ival'])) msg += 'fin: {0}/s ]'.format((stat['4506/fin'] / args['ival'])) print(msg) for item in stat: stat[item] = 0 r_time = s_time except KeyboardInterrupt: sys.exit(1)
main loop for whole script
main loop for whole script
Question: What does this function do? Code: def main(): args = vars(ArgParser().parse_args()) r_time = 0 ports = [4505, 4506] print('Sniffing device {0}'.format(args['iface'])) stat = {'4506/new': 0, '4506/est': 0, '4506/fin': 0, '4505/new': 0, '4505/est': 0, '4505/fin': 0, 'ips/4505': 0, 'ips/4506': 0} if args['only_ip']: print('IPs making new connections (ports:{0}, interval:{1})'.format(ports, args['ival'])) else: print('Salt-Master Network Status (ports:{0}, interval:{1})'.format(ports, args['ival'])) try: while 1: s_time = int(time.time()) packet = next(PCAPParser(args['iface']).run()) p_state = filter_new_cons(packet) ips_auth = [] ips_push = [] if (p_state == 10): stat['4505/new'] += 1 if (packet['ip']['s_addr'] not in ips_auth): ips_auth.append(packet['ip']['s_addr']) elif (p_state == 12): stat['4505/fin'] += 1 elif (p_state == 100): stat['4506/new'] += 1 if (packet['ip']['s_addr'] not in ips_push): ips_push.append(packet['ip']['s_addr']) elif (p_state == 120): stat['4506/fin'] += 1 (stat['4505/est'], stat['4506/est']) = next(SaltNetstat().run()) if ((s_time % args['ival']) == 0): if (r_time != s_time): if args['only_ip']: msg = 'IPs/4505: {0}, IPs/4506: {1}'.format(len(ips_auth), len(ips_push)) else: msg = '4505=>[ est: {0}, '.format(stat['4505/est']) msg += 'new: {0}/s, '.format((stat['4505/new'] / args['ival'])) msg += 'fin: {0}/s ] '.format((stat['4505/fin'] / args['ival'])) msg += ' 4506=>[ est: {0}, '.format(stat['4506/est']) msg += 'new: {0}/s, '.format((stat['4506/new'] / args['ival'])) msg += 'fin: {0}/s ]'.format((stat['4506/fin'] / args['ival'])) print(msg) for item in stat: stat[item] = 0 r_time = s_time except KeyboardInterrupt: sys.exit(1)
null
null
null
What does this function do?
@status('Getting the list of files that have been added/changed', info=(lambda x: n_files_str(len(x)))) def changed_files(): if os.path.isdir(os.path.join(SRCDIR, '.hg')): cmd = 'hg status --added --modified --no-status' if mq_patches_applied(): cmd += ' --rev qparent' with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st: return [x.decode().rstrip() for x in st.stdout] elif os.path.isdir(os.path.join(SRCDIR, '.git')): cmd = 'git status --porcelain' filenames = [] with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st: for line in st.stdout: line = line.decode().rstrip() status = set(line[:2]) if (not status.intersection('MAU')): continue filename = line[3:] if (' -> ' in filename): filename = filename.split(' -> ', 2)[1].strip() filenames.append(filename) return filenames else: sys.exit('need a Mercurial or git checkout to get modified files')
null
null
null
Get the list of changed or added files from Mercurial or git.
pcsd
@status 'Getting the list of files that have been added/changed' info= lambda x n files str len x def changed files if os path isdir os path join SRCDIR ' hg' cmd = 'hg status --added --modified --no-status' if mq patches applied cmd += ' --rev qparent' with subprocess Popen cmd split stdout=subprocess PIPE as st return [x decode rstrip for x in st stdout] elif os path isdir os path join SRCDIR ' git' cmd = 'git status --porcelain' filenames = [] with subprocess Popen cmd split stdout=subprocess PIPE as st for line in st stdout line = line decode rstrip status = set line[ 2] if not status intersection 'MAU' continue filename = line[3 ] if ' -> ' in filename filename = filename split ' -> ' 2 [1] strip filenames append filename return filenames else sys exit 'need a Mercurial or git checkout to get modified files'
7999
@status('Getting the list of files that have been added/changed', info=(lambda x: n_files_str(len(x)))) def changed_files(): if os.path.isdir(os.path.join(SRCDIR, '.hg')): cmd = 'hg status --added --modified --no-status' if mq_patches_applied(): cmd += ' --rev qparent' with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st: return [x.decode().rstrip() for x in st.stdout] elif os.path.isdir(os.path.join(SRCDIR, '.git')): cmd = 'git status --porcelain' filenames = [] with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st: for line in st.stdout: line = line.decode().rstrip() status = set(line[:2]) if (not status.intersection('MAU')): continue filename = line[3:] if (' -> ' in filename): filename = filename.split(' -> ', 2)[1].strip() filenames.append(filename) return filenames else: sys.exit('need a Mercurial or git checkout to get modified files')
Get the list of changed or added files from Mercurial or git.
get the list of changed or added files from mercurial or git .
Question: What does this function do? Code: @status('Getting the list of files that have been added/changed', info=(lambda x: n_files_str(len(x)))) def changed_files(): if os.path.isdir(os.path.join(SRCDIR, '.hg')): cmd = 'hg status --added --modified --no-status' if mq_patches_applied(): cmd += ' --rev qparent' with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st: return [x.decode().rstrip() for x in st.stdout] elif os.path.isdir(os.path.join(SRCDIR, '.git')): cmd = 'git status --porcelain' filenames = [] with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as st: for line in st.stdout: line = line.decode().rstrip() status = set(line[:2]) if (not status.intersection('MAU')): continue filename = line[3:] if (' -> ' in filename): filename = filename.split(' -> ', 2)[1].strip() filenames.append(filename) return filenames else: sys.exit('need a Mercurial or git checkout to get modified files')
null
null
null
What does this function do?
def restore_warnings_state(state): warnings.warn(warn_txt, DeprecationWarning, stacklevel=2) warnings.filters = state[:]
null
null
null
Restores the state of the warnings module when passed an object that was returned by get_warnings_state()
pcsd
def restore warnings state state warnings warn warn txt Deprecation Warning stacklevel=2 warnings filters = state[ ]
8001
def restore_warnings_state(state): warnings.warn(warn_txt, DeprecationWarning, stacklevel=2) warnings.filters = state[:]
Restores the state of the warnings module when passed an object that was returned by get_warnings_state()
restores the state of the warnings module when passed an object that was returned by get _ warnings _ state ( )
Question: What does this function do? Code: def restore_warnings_state(state): warnings.warn(warn_txt, DeprecationWarning, stacklevel=2) warnings.filters = state[:]
null
null
null
What does this function do?
def get_model_field_name(field): field = slugify(field) field = field.replace('-', '_') field = field.replace(':', '_') if (field in ('id',)): field += '_' if (field.upper() in PG_RESERVED_KEYWORDS): field += '_' if (field[(-1):] == '_'): field += 'field' try: int(field) float(field) field = ('_%s' % field) except ValueError: pass return field
null
null
null
Get the field name usable without quotes.
pcsd
def get model field name field field = slugify field field = field replace '-' ' ' field = field replace ' ' ' ' if field in 'id' field += ' ' if field upper in PG RESERVED KEYWORDS field += ' ' if field[ -1 ] == ' ' field += 'field' try int field float field field = ' %s' % field except Value Error pass return field
8003
def get_model_field_name(field): field = slugify(field) field = field.replace('-', '_') field = field.replace(':', '_') if (field in ('id',)): field += '_' if (field.upper() in PG_RESERVED_KEYWORDS): field += '_' if (field[(-1):] == '_'): field += 'field' try: int(field) float(field) field = ('_%s' % field) except ValueError: pass return field
Get the field name usable without quotes.
get the field name usable without quotes .
Question: What does this function do? Code: def get_model_field_name(field): field = slugify(field) field = field.replace('-', '_') field = field.replace(':', '_') if (field in ('id',)): field += '_' if (field.upper() in PG_RESERVED_KEYWORDS): field += '_' if (field[(-1):] == '_'): field += 'field' try: int(field) float(field) field = ('_%s' % field) except ValueError: pass return field
null
null
null
What does this function do?
def register(linter): linter.register_reporter(TextReporter) linter.register_reporter(ParseableTextReporter) linter.register_reporter(VSTextReporter) linter.register_reporter(ColorizedTextReporter)
null
null
null
Register the reporter classes with the linter.
pcsd
def register linter linter register reporter Text Reporter linter register reporter Parseable Text Reporter linter register reporter VS Text Reporter linter register reporter Colorized Text Reporter
8010
def register(linter): linter.register_reporter(TextReporter) linter.register_reporter(ParseableTextReporter) linter.register_reporter(VSTextReporter) linter.register_reporter(ColorizedTextReporter)
Register the reporter classes with the linter.
register the reporter classes with the linter .
Question: What does this function do? Code: def register(linter): linter.register_reporter(TextReporter) linter.register_reporter(ParseableTextReporter) linter.register_reporter(VSTextReporter) linter.register_reporter(ColorizedTextReporter)
null
null
null
What does this function do?
def update_patch_log(patchmodule): frappe.get_doc({u'doctype': u'Patch Log', u'patch': patchmodule}).insert()
null
null
null
update patch_file in patch log
pcsd
def update patch log patchmodule frappe get doc {u'doctype' u'Patch Log' u'patch' patchmodule} insert
8012
def update_patch_log(patchmodule): frappe.get_doc({u'doctype': u'Patch Log', u'patch': patchmodule}).insert()
update patch_file in patch log
update patch _ file in patch log
Question: What does this function do? Code: def update_patch_log(patchmodule): frappe.get_doc({u'doctype': u'Patch Log', u'patch': patchmodule}).insert()
null
null
null
What does this function do?
def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None): actual_decorator = user_passes_test((lambda u: u.is_authenticated), login_url=login_url, redirect_field_name=redirect_field_name) if function: return actual_decorator(function) return actual_decorator
null
null
null
Decorator for views that checks that the user is logged in, redirecting to the log-in page if necessary.
pcsd
def login required function=None redirect field name=REDIRECT FIELD NAME login url=None actual decorator = user passes test lambda u u is authenticated login url=login url redirect field name=redirect field name if function return actual decorator function return actual decorator
8013
def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None): actual_decorator = user_passes_test((lambda u: u.is_authenticated), login_url=login_url, redirect_field_name=redirect_field_name) if function: return actual_decorator(function) return actual_decorator
Decorator for views that checks that the user is logged in, redirecting to the log-in page if necessary.
decorator for views that checks that the user is logged in , redirecting to the log - in page if necessary .
Question: What does this function do? Code: def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME, login_url=None): actual_decorator = user_passes_test((lambda u: u.is_authenticated), login_url=login_url, redirect_field_name=redirect_field_name) if function: return actual_decorator(function) return actual_decorator
null
null
null
What does this function do?
def index2(): table = s3db.table('cr_shelter', None) module_name = settings.modules[module].name_nice response.title = module_name response.view = 'inv/index.html' if s3.debug: from s3.s3data import S3DataTable representation = request.extension if ((representation == 'html') or (get_vars.id == 'warehouse_list_1')): resource = s3db.resource('inv_warehouse') totalrows = resource.count() list_fields = ['id', 'name', 'organisation_id'] orderby = 'inv_warehouse.name asc' if (representation == 'aadata'): (query, orderby, left) = resource.datatable_filter(list_fields, get_vars) if (orderby is None): orderby = default_orderby start = (int(get_vars.displayStart) if get_vars.displayStart else 0) limit = (int(get_vars.pageLength) if get_vars.pageLength else s3.ROWSPERPAGE) data = resource.select(list_fields, start=start, limit=limit, orderby=orderby, count=True, represent=True) filteredrows = data['numrows'] if (totalrows is None): totalrows = filteredrows rfields = data['rfields'] rows = data['rows'] dt = S3DataTable(rfields, rows) dt.defaultActionButtons(resource) if (representation == 'html'): warehouses = dt.html(totalrows, filteredrows, 'warehouse_list_1', dt_ajax_url=URL(c='inv', f='index2', extension='aadata', vars={'id': 'warehouse_list_1'}), dt_group=2, dt_searching='true') else: warehouse = dt.json(totalrows, filteredrows, 'warehouse_list_1', int(get_vars.draw)) return warehouse if ((representation == 'html') or (get_vars.id == 'inventory_list_1')): if ('Adjust' in request.post_vars): if (request.post_vars.selected == ''): inventory = 'Well you could have selected something :(' else: inventory = ('Adjustment not currently supported... :-) you selected the following items: %s' % request.post_vars.selected) else: resource = s3db.resource('inv_inv_item') totalrows = resource.count() table = resource.table stable = s3db.supply_item list_fields = ['id', 'site_id', 'item_id$name', 'quantity', 'pack_value', 'total_value'] orderby = 'inv_inv_item.site_id asc' if (representation == 'aadata'): (query, orderby, left) = resource.datatable_filter(list_fields, get_vars) if (orderby is None): orderby = default_orderby site_list = {} data = resource.select(list_fields, limit=None, orderby=orderby, count=True) filteredrows = data['numrows'] if (totalrows is None): totalrows = filteredrows rows = data['rows'] for row in rows: site_id = row['inv_inv_item.site_id'] if (site_id not in site_list): site_list[site_id] = 1 else: site_list[site_id] += 1 formatted_site_list = {} repr = table.site_id.represent for (key, value) in site_list.items(): formatted_site_list[str(repr(key))] = value if isinstance(orderby, bool): orderby = [table.site_id, stable.name, (~ table.quantity)] start = (int(get_vars.displayStart) if get_vars.displayStart else 0) limit = (int(get_vars.pageLength) if get_vars.pageLength else s3.ROWSPERPAGE) data = resource.select(list_fields, orderby=orderby, start=start, limit=limit, represent=True) rfields = data['rfields'] rows = data['rows'] dt = S3DataTable(rfields, rows, orderby=orderby) custom_actions = [dict(label=str(T('Warehouse')), _class='action-icon', img=('/%s/static/img/markers/gis_marker.image.Agri_Commercial_Food_Distribution_Center_S1.png' % appname), url=URL(c='inv', f='warehouse', args=['[id]', 'update']))] dt.defaultActionButtons(resource, custom_actions) if (representation == 'html'): rows = current.db((table.quantity < 100.0)).select(table.id, table.quantity) errorList = [] warningList = [] alertList = [] for row in rows: if (row.quantity < 0.0): errorList.append(row.id) elif (row.quantity == 0.0): warningList.append(row.id) else: alertList.append(row.id) inventory = dt.html(totalrows, filteredrows, 'inventory_list_1', dt_action_col=(-1), dt_ajax_url=URL(c='inv', f='index2', extension='aadata', vars={'id': 'inventory_list_1'}), dt_bulk_actions='Adjust', dt_group=[1, 2], dt_group_totals=[formatted_site_list], dt_searching='true', dt_styles={'dtdisable': errorList, 'dtwarning': warningList, 'dtalert': alertList}, dt_shrink_groups='accordion') s3.actions = None elif (representation == 'aadata'): inventory = dt.json(totalrows, filteredrows, 'inventory_list_1', int(get_vars.draw), dt_action_col=(-1), dt_bulk_actions='Adjust', dt_group_totals=[formatted_site_list]) return inventory else: s3db.configure('inv_inv_item', list_fields=list_fields, report_groupby='site_id', pdf_groupby='site_id') s3.filter = filter r = s3_request('inv', 'inv_item', vars={'orderby': orderby}) r.resource = resource output = r(pdf_groupby='site_id', dt_group=1) return output if ((representation == 'html') or (get_vars.id == 'supply_list_1')): resource = s3db.resource('supply_item') list_fields = ['id', 'name', 'um', 'model'] orderby = 'inv_inv_item.site_id asc' if (representation == 'aadata'): (query, orderby, left) = resource.datatable_filter(list_fields, get_vars) if (orderby is None): orderby = default_orderby data = resource.select(list_fields, limit=None, orderby=orderby, count=True, represent=True) rows = data['rows'] rfields = data['rfields'] numrows = data['numrows'] dt = S3DataTable(rfields, rows) dt.defaultActionButtons(resource) if (representation == 'html'): supply_items = dt.html(numrows, numrows, 'supply_list_1', dt_action_col=1, dt_ajax_url=URL(c='inv', f='index2', extension='aadata', vars={'id': 'supply_list_1'}), dt_pageLength=10) else: supply_items = dt.json(numrows, numrows, 'supply_list_1', int(get_vars.draw), dt_action_col=1) return supply_items r = s3_request(prefix='inv', name='inv_item') return dict(module_name=module_name, warehouses=warehouses, inventory=inventory, supply_items=supply_items, r=r) return dict(module_name=module_name)
null
null
null
Alternative Application Home page - custom View
pcsd
def index2 table = s3db table 'cr shelter' None module name = settings modules[module] name nice response title = module name response view = 'inv/index html' if s3 debug from s3 s3data import S3Data Table representation = request extension if representation == 'html' or get vars id == 'warehouse list 1' resource = s3db resource 'inv warehouse' totalrows = resource count list fields = ['id' 'name' 'organisation id'] orderby = 'inv warehouse name asc' if representation == 'aadata' query orderby left = resource datatable filter list fields get vars if orderby is None orderby = default orderby start = int get vars display Start if get vars display Start else 0 limit = int get vars page Length if get vars page Length else s3 ROWSPERPAGE data = resource select list fields start=start limit=limit orderby=orderby count=True represent=True filteredrows = data['numrows'] if totalrows is None totalrows = filteredrows rfields = data['rfields'] rows = data['rows'] dt = S3Data Table rfields rows dt default Action Buttons resource if representation == 'html' warehouses = dt html totalrows filteredrows 'warehouse list 1' dt ajax url=URL c='inv' f='index2' extension='aadata' vars={'id' 'warehouse list 1'} dt group=2 dt searching='true' else warehouse = dt json totalrows filteredrows 'warehouse list 1' int get vars draw return warehouse if representation == 'html' or get vars id == 'inventory list 1' if 'Adjust' in request post vars if request post vars selected == '' inventory = 'Well you could have selected something ' else inventory = 'Adjustment not currently supported - you selected the following items %s' % request post vars selected else resource = s3db resource 'inv inv item' totalrows = resource count table = resource table stable = s3db supply item list fields = ['id' 'site id' 'item id$name' 'quantity' 'pack value' 'total value'] orderby = 'inv inv item site id asc' if representation == 'aadata' query orderby left = resource datatable filter list fields get vars if orderby is None orderby = default orderby site list = {} data = resource select list fields limit=None orderby=orderby count=True filteredrows = data['numrows'] if totalrows is None totalrows = filteredrows rows = data['rows'] for row in rows site id = row['inv inv item site id'] if site id not in site list site list[site id] = 1 else site list[site id] += 1 formatted site list = {} repr = table site id represent for key value in site list items formatted site list[str repr key ] = value if isinstance orderby bool orderby = [table site id stable name ~ table quantity ] start = int get vars display Start if get vars display Start else 0 limit = int get vars page Length if get vars page Length else s3 ROWSPERPAGE data = resource select list fields orderby=orderby start=start limit=limit represent=True rfields = data['rfields'] rows = data['rows'] dt = S3Data Table rfields rows orderby=orderby custom actions = [dict label=str T 'Warehouse' class='action-icon' img= '/%s/static/img/markers/gis marker image Agri Commercial Food Distribution Center S1 png' % appname url=URL c='inv' f='warehouse' args=['[id]' 'update'] ] dt default Action Buttons resource custom actions if representation == 'html' rows = current db table quantity < 100 0 select table id table quantity error List = [] warning List = [] alert List = [] for row in rows if row quantity < 0 0 error List append row id elif row quantity == 0 0 warning List append row id else alert List append row id inventory = dt html totalrows filteredrows 'inventory list 1' dt action col= -1 dt ajax url=URL c='inv' f='index2' extension='aadata' vars={'id' 'inventory list 1'} dt bulk actions='Adjust' dt group=[1 2] dt group totals=[formatted site list] dt searching='true' dt styles={'dtdisable' error List 'dtwarning' warning List 'dtalert' alert List} dt shrink groups='accordion' s3 actions = None elif representation == 'aadata' inventory = dt json totalrows filteredrows 'inventory list 1' int get vars draw dt action col= -1 dt bulk actions='Adjust' dt group totals=[formatted site list] return inventory else s3db configure 'inv inv item' list fields=list fields report groupby='site id' pdf groupby='site id' s3 filter = filter r = s3 request 'inv' 'inv item' vars={'orderby' orderby} r resource = resource output = r pdf groupby='site id' dt group=1 return output if representation == 'html' or get vars id == 'supply list 1' resource = s3db resource 'supply item' list fields = ['id' 'name' 'um' 'model'] orderby = 'inv inv item site id asc' if representation == 'aadata' query orderby left = resource datatable filter list fields get vars if orderby is None orderby = default orderby data = resource select list fields limit=None orderby=orderby count=True represent=True rows = data['rows'] rfields = data['rfields'] numrows = data['numrows'] dt = S3Data Table rfields rows dt default Action Buttons resource if representation == 'html' supply items = dt html numrows numrows 'supply list 1' dt action col=1 dt ajax url=URL c='inv' f='index2' extension='aadata' vars={'id' 'supply list 1'} dt page Length=10 else supply items = dt json numrows numrows 'supply list 1' int get vars draw dt action col=1 return supply items r = s3 request prefix='inv' name='inv item' return dict module name=module name warehouses=warehouses inventory=inventory supply items=supply items r=r return dict module name=module name
8016
def index2(): table = s3db.table('cr_shelter', None) module_name = settings.modules[module].name_nice response.title = module_name response.view = 'inv/index.html' if s3.debug: from s3.s3data import S3DataTable representation = request.extension if ((representation == 'html') or (get_vars.id == 'warehouse_list_1')): resource = s3db.resource('inv_warehouse') totalrows = resource.count() list_fields = ['id', 'name', 'organisation_id'] orderby = 'inv_warehouse.name asc' if (representation == 'aadata'): (query, orderby, left) = resource.datatable_filter(list_fields, get_vars) if (orderby is None): orderby = default_orderby start = (int(get_vars.displayStart) if get_vars.displayStart else 0) limit = (int(get_vars.pageLength) if get_vars.pageLength else s3.ROWSPERPAGE) data = resource.select(list_fields, start=start, limit=limit, orderby=orderby, count=True, represent=True) filteredrows = data['numrows'] if (totalrows is None): totalrows = filteredrows rfields = data['rfields'] rows = data['rows'] dt = S3DataTable(rfields, rows) dt.defaultActionButtons(resource) if (representation == 'html'): warehouses = dt.html(totalrows, filteredrows, 'warehouse_list_1', dt_ajax_url=URL(c='inv', f='index2', extension='aadata', vars={'id': 'warehouse_list_1'}), dt_group=2, dt_searching='true') else: warehouse = dt.json(totalrows, filteredrows, 'warehouse_list_1', int(get_vars.draw)) return warehouse if ((representation == 'html') or (get_vars.id == 'inventory_list_1')): if ('Adjust' in request.post_vars): if (request.post_vars.selected == ''): inventory = 'Well you could have selected something :(' else: inventory = ('Adjustment not currently supported... :-) you selected the following items: %s' % request.post_vars.selected) else: resource = s3db.resource('inv_inv_item') totalrows = resource.count() table = resource.table stable = s3db.supply_item list_fields = ['id', 'site_id', 'item_id$name', 'quantity', 'pack_value', 'total_value'] orderby = 'inv_inv_item.site_id asc' if (representation == 'aadata'): (query, orderby, left) = resource.datatable_filter(list_fields, get_vars) if (orderby is None): orderby = default_orderby site_list = {} data = resource.select(list_fields, limit=None, orderby=orderby, count=True) filteredrows = data['numrows'] if (totalrows is None): totalrows = filteredrows rows = data['rows'] for row in rows: site_id = row['inv_inv_item.site_id'] if (site_id not in site_list): site_list[site_id] = 1 else: site_list[site_id] += 1 formatted_site_list = {} repr = table.site_id.represent for (key, value) in site_list.items(): formatted_site_list[str(repr(key))] = value if isinstance(orderby, bool): orderby = [table.site_id, stable.name, (~ table.quantity)] start = (int(get_vars.displayStart) if get_vars.displayStart else 0) limit = (int(get_vars.pageLength) if get_vars.pageLength else s3.ROWSPERPAGE) data = resource.select(list_fields, orderby=orderby, start=start, limit=limit, represent=True) rfields = data['rfields'] rows = data['rows'] dt = S3DataTable(rfields, rows, orderby=orderby) custom_actions = [dict(label=str(T('Warehouse')), _class='action-icon', img=('/%s/static/img/markers/gis_marker.image.Agri_Commercial_Food_Distribution_Center_S1.png' % appname), url=URL(c='inv', f='warehouse', args=['[id]', 'update']))] dt.defaultActionButtons(resource, custom_actions) if (representation == 'html'): rows = current.db((table.quantity < 100.0)).select(table.id, table.quantity) errorList = [] warningList = [] alertList = [] for row in rows: if (row.quantity < 0.0): errorList.append(row.id) elif (row.quantity == 0.0): warningList.append(row.id) else: alertList.append(row.id) inventory = dt.html(totalrows, filteredrows, 'inventory_list_1', dt_action_col=(-1), dt_ajax_url=URL(c='inv', f='index2', extension='aadata', vars={'id': 'inventory_list_1'}), dt_bulk_actions='Adjust', dt_group=[1, 2], dt_group_totals=[formatted_site_list], dt_searching='true', dt_styles={'dtdisable': errorList, 'dtwarning': warningList, 'dtalert': alertList}, dt_shrink_groups='accordion') s3.actions = None elif (representation == 'aadata'): inventory = dt.json(totalrows, filteredrows, 'inventory_list_1', int(get_vars.draw), dt_action_col=(-1), dt_bulk_actions='Adjust', dt_group_totals=[formatted_site_list]) return inventory else: s3db.configure('inv_inv_item', list_fields=list_fields, report_groupby='site_id', pdf_groupby='site_id') s3.filter = filter r = s3_request('inv', 'inv_item', vars={'orderby': orderby}) r.resource = resource output = r(pdf_groupby='site_id', dt_group=1) return output if ((representation == 'html') or (get_vars.id == 'supply_list_1')): resource = s3db.resource('supply_item') list_fields = ['id', 'name', 'um', 'model'] orderby = 'inv_inv_item.site_id asc' if (representation == 'aadata'): (query, orderby, left) = resource.datatable_filter(list_fields, get_vars) if (orderby is None): orderby = default_orderby data = resource.select(list_fields, limit=None, orderby=orderby, count=True, represent=True) rows = data['rows'] rfields = data['rfields'] numrows = data['numrows'] dt = S3DataTable(rfields, rows) dt.defaultActionButtons(resource) if (representation == 'html'): supply_items = dt.html(numrows, numrows, 'supply_list_1', dt_action_col=1, dt_ajax_url=URL(c='inv', f='index2', extension='aadata', vars={'id': 'supply_list_1'}), dt_pageLength=10) else: supply_items = dt.json(numrows, numrows, 'supply_list_1', int(get_vars.draw), dt_action_col=1) return supply_items r = s3_request(prefix='inv', name='inv_item') return dict(module_name=module_name, warehouses=warehouses, inventory=inventory, supply_items=supply_items, r=r) return dict(module_name=module_name)
Alternative Application Home page - custom View
alternative application home page - custom view
Question: What does this function do? Code: def index2(): table = s3db.table('cr_shelter', None) module_name = settings.modules[module].name_nice response.title = module_name response.view = 'inv/index.html' if s3.debug: from s3.s3data import S3DataTable representation = request.extension if ((representation == 'html') or (get_vars.id == 'warehouse_list_1')): resource = s3db.resource('inv_warehouse') totalrows = resource.count() list_fields = ['id', 'name', 'organisation_id'] orderby = 'inv_warehouse.name asc' if (representation == 'aadata'): (query, orderby, left) = resource.datatable_filter(list_fields, get_vars) if (orderby is None): orderby = default_orderby start = (int(get_vars.displayStart) if get_vars.displayStart else 0) limit = (int(get_vars.pageLength) if get_vars.pageLength else s3.ROWSPERPAGE) data = resource.select(list_fields, start=start, limit=limit, orderby=orderby, count=True, represent=True) filteredrows = data['numrows'] if (totalrows is None): totalrows = filteredrows rfields = data['rfields'] rows = data['rows'] dt = S3DataTable(rfields, rows) dt.defaultActionButtons(resource) if (representation == 'html'): warehouses = dt.html(totalrows, filteredrows, 'warehouse_list_1', dt_ajax_url=URL(c='inv', f='index2', extension='aadata', vars={'id': 'warehouse_list_1'}), dt_group=2, dt_searching='true') else: warehouse = dt.json(totalrows, filteredrows, 'warehouse_list_1', int(get_vars.draw)) return warehouse if ((representation == 'html') or (get_vars.id == 'inventory_list_1')): if ('Adjust' in request.post_vars): if (request.post_vars.selected == ''): inventory = 'Well you could have selected something :(' else: inventory = ('Adjustment not currently supported... :-) you selected the following items: %s' % request.post_vars.selected) else: resource = s3db.resource('inv_inv_item') totalrows = resource.count() table = resource.table stable = s3db.supply_item list_fields = ['id', 'site_id', 'item_id$name', 'quantity', 'pack_value', 'total_value'] orderby = 'inv_inv_item.site_id asc' if (representation == 'aadata'): (query, orderby, left) = resource.datatable_filter(list_fields, get_vars) if (orderby is None): orderby = default_orderby site_list = {} data = resource.select(list_fields, limit=None, orderby=orderby, count=True) filteredrows = data['numrows'] if (totalrows is None): totalrows = filteredrows rows = data['rows'] for row in rows: site_id = row['inv_inv_item.site_id'] if (site_id not in site_list): site_list[site_id] = 1 else: site_list[site_id] += 1 formatted_site_list = {} repr = table.site_id.represent for (key, value) in site_list.items(): formatted_site_list[str(repr(key))] = value if isinstance(orderby, bool): orderby = [table.site_id, stable.name, (~ table.quantity)] start = (int(get_vars.displayStart) if get_vars.displayStart else 0) limit = (int(get_vars.pageLength) if get_vars.pageLength else s3.ROWSPERPAGE) data = resource.select(list_fields, orderby=orderby, start=start, limit=limit, represent=True) rfields = data['rfields'] rows = data['rows'] dt = S3DataTable(rfields, rows, orderby=orderby) custom_actions = [dict(label=str(T('Warehouse')), _class='action-icon', img=('/%s/static/img/markers/gis_marker.image.Agri_Commercial_Food_Distribution_Center_S1.png' % appname), url=URL(c='inv', f='warehouse', args=['[id]', 'update']))] dt.defaultActionButtons(resource, custom_actions) if (representation == 'html'): rows = current.db((table.quantity < 100.0)).select(table.id, table.quantity) errorList = [] warningList = [] alertList = [] for row in rows: if (row.quantity < 0.0): errorList.append(row.id) elif (row.quantity == 0.0): warningList.append(row.id) else: alertList.append(row.id) inventory = dt.html(totalrows, filteredrows, 'inventory_list_1', dt_action_col=(-1), dt_ajax_url=URL(c='inv', f='index2', extension='aadata', vars={'id': 'inventory_list_1'}), dt_bulk_actions='Adjust', dt_group=[1, 2], dt_group_totals=[formatted_site_list], dt_searching='true', dt_styles={'dtdisable': errorList, 'dtwarning': warningList, 'dtalert': alertList}, dt_shrink_groups='accordion') s3.actions = None elif (representation == 'aadata'): inventory = dt.json(totalrows, filteredrows, 'inventory_list_1', int(get_vars.draw), dt_action_col=(-1), dt_bulk_actions='Adjust', dt_group_totals=[formatted_site_list]) return inventory else: s3db.configure('inv_inv_item', list_fields=list_fields, report_groupby='site_id', pdf_groupby='site_id') s3.filter = filter r = s3_request('inv', 'inv_item', vars={'orderby': orderby}) r.resource = resource output = r(pdf_groupby='site_id', dt_group=1) return output if ((representation == 'html') or (get_vars.id == 'supply_list_1')): resource = s3db.resource('supply_item') list_fields = ['id', 'name', 'um', 'model'] orderby = 'inv_inv_item.site_id asc' if (representation == 'aadata'): (query, orderby, left) = resource.datatable_filter(list_fields, get_vars) if (orderby is None): orderby = default_orderby data = resource.select(list_fields, limit=None, orderby=orderby, count=True, represent=True) rows = data['rows'] rfields = data['rfields'] numrows = data['numrows'] dt = S3DataTable(rfields, rows) dt.defaultActionButtons(resource) if (representation == 'html'): supply_items = dt.html(numrows, numrows, 'supply_list_1', dt_action_col=1, dt_ajax_url=URL(c='inv', f='index2', extension='aadata', vars={'id': 'supply_list_1'}), dt_pageLength=10) else: supply_items = dt.json(numrows, numrows, 'supply_list_1', int(get_vars.draw), dt_action_col=1) return supply_items r = s3_request(prefix='inv', name='inv_item') return dict(module_name=module_name, warehouses=warehouses, inventory=inventory, supply_items=supply_items, r=r) return dict(module_name=module_name)
null
null
null
What does this function do?
def is_valid_ip(ip): if ((not ip) or ('\x00' in ip)): return False try: res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror as e: if (e.args[0] == socket.EAI_NONAME): return False raise return True
null
null
null
Returns true if the given string is a well-formed IP address. Supports IPv4 and IPv6.
pcsd
def is valid ip ip if not ip or '\x00' in ip return False try res = socket getaddrinfo ip 0 socket AF UNSPEC socket SOCK STREAM 0 socket AI NUMERICHOST return bool res except socket gaierror as e if e args[0] == socket EAI NONAME return False raise return True
8019
def is_valid_ip(ip): if ((not ip) or ('\x00' in ip)): return False try: res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror as e: if (e.args[0] == socket.EAI_NONAME): return False raise return True
Returns true if the given string is a well-formed IP address. Supports IPv4 and IPv6.
returns true if the given string is a well - formed ip address .
Question: What does this function do? Code: def is_valid_ip(ip): if ((not ip) or ('\x00' in ip)): return False try: res = socket.getaddrinfo(ip, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST) return bool(res) except socket.gaierror as e: if (e.args[0] == socket.EAI_NONAME): return False raise return True
null
null
null
What does this function do?
def true(*args, **kwargs): return True
null
null
null
Always returns True.
pcsd
def true *args **kwargs return True
8026
def true(*args, **kwargs): return True
Always returns True.
always returns true .
Question: What does this function do? Code: def true(*args, **kwargs): return True
null
null
null
What does this function do?
def print_name_status(changes): for change in changes: if (not change): continue if (type(change) is list): change = change[0] if (change.type == CHANGE_ADD): path1 = change.new.path path2 = '' kind = 'A' elif (change.type == CHANGE_DELETE): path1 = change.old.path path2 = '' kind = 'D' elif (change.type == CHANGE_MODIFY): path1 = change.new.path path2 = '' kind = 'M' elif (change.type in RENAME_CHANGE_TYPES): path1 = change.old.path path2 = change.new.path if (change.type == CHANGE_RENAME): kind = 'R' elif (change.type == CHANGE_COPY): kind = 'C' (yield ('%-8s%-20s%-20s' % (kind, path1, path2)))
null
null
null
Print a simple status summary, listing changed files.
pcsd
def print name status changes for change in changes if not change continue if type change is list change = change[0] if change type == CHANGE ADD path1 = change new path path2 = '' kind = 'A' elif change type == CHANGE DELETE path1 = change old path path2 = '' kind = 'D' elif change type == CHANGE MODIFY path1 = change new path path2 = '' kind = 'M' elif change type in RENAME CHANGE TYPES path1 = change old path path2 = change new path if change type == CHANGE RENAME kind = 'R' elif change type == CHANGE COPY kind = 'C' yield '%-8s%-20s%-20s' % kind path1 path2
8031
def print_name_status(changes): for change in changes: if (not change): continue if (type(change) is list): change = change[0] if (change.type == CHANGE_ADD): path1 = change.new.path path2 = '' kind = 'A' elif (change.type == CHANGE_DELETE): path1 = change.old.path path2 = '' kind = 'D' elif (change.type == CHANGE_MODIFY): path1 = change.new.path path2 = '' kind = 'M' elif (change.type in RENAME_CHANGE_TYPES): path1 = change.old.path path2 = change.new.path if (change.type == CHANGE_RENAME): kind = 'R' elif (change.type == CHANGE_COPY): kind = 'C' (yield ('%-8s%-20s%-20s' % (kind, path1, path2)))
Print a simple status summary, listing changed files.
print a simple status summary , listing changed files .
Question: What does this function do? Code: def print_name_status(changes): for change in changes: if (not change): continue if (type(change) is list): change = change[0] if (change.type == CHANGE_ADD): path1 = change.new.path path2 = '' kind = 'A' elif (change.type == CHANGE_DELETE): path1 = change.old.path path2 = '' kind = 'D' elif (change.type == CHANGE_MODIFY): path1 = change.new.path path2 = '' kind = 'M' elif (change.type in RENAME_CHANGE_TYPES): path1 = change.old.path path2 = change.new.path if (change.type == CHANGE_RENAME): kind = 'R' elif (change.type == CHANGE_COPY): kind = 'C' (yield ('%-8s%-20s%-20s' % (kind, path1, path2)))
null
null
null
What does this function do?
def stop(port): global client_cancel client_cancel = True try: if transparent_torification: s = socket.socket() s.connect(('127.0.0.1', port)) s.sendall('GET /{0:s}/shutdown HTTP/1.1\r\n\r\n'.format(shutdown_slug)) else: urlopen('http://127.0.0.1:{0:d}/{1:s}/shutdown'.format(port, shutdown_slug)).read() except: pass
null
null
null
Stop the flask web server by loading /shutdown.
pcsd
def stop port global client cancel client cancel = True try if transparent torification s = socket socket s connect '127 0 0 1' port s sendall 'GET /{0 s}/shutdown HTTP/1 1\r \r ' format shutdown slug else urlopen 'http //127 0 0 1 {0 d}/{1 s}/shutdown' format port shutdown slug read except pass
8042
def stop(port): global client_cancel client_cancel = True try: if transparent_torification: s = socket.socket() s.connect(('127.0.0.1', port)) s.sendall('GET /{0:s}/shutdown HTTP/1.1\r\n\r\n'.format(shutdown_slug)) else: urlopen('http://127.0.0.1:{0:d}/{1:s}/shutdown'.format(port, shutdown_slug)).read() except: pass
Stop the flask web server by loading /shutdown.
stop the flask web server by loading / shutdown .
Question: What does this function do? Code: def stop(port): global client_cancel client_cancel = True try: if transparent_torification: s = socket.socket() s.connect(('127.0.0.1', port)) s.sendall('GET /{0:s}/shutdown HTTP/1.1\r\n\r\n'.format(shutdown_slug)) else: urlopen('http://127.0.0.1:{0:d}/{1:s}/shutdown'.format(port, shutdown_slug)).read() except: pass
null
null
null
What does this function do?
def OSXGetRawDevice(path): device_map = GetMountpoints() path = utils.SmartUnicode(path) mount_point = path = utils.NormalizePath(path, '/') result = rdf_paths.PathSpec(pathtype=rdf_paths.PathSpec.PathType.OS) while mount_point: try: (result.path, fs_type) = device_map[mount_point] if (fs_type in ['ext2', 'ext3', 'ext4', 'vfat', 'ntfs', 'Apple_HFS', 'hfs', 'msdos']): result.pathtype = rdf_paths.PathSpec.PathType.OS else: result.pathtype = rdf_paths.PathSpec.PathType.UNSET path = utils.NormalizePath(path[len(mount_point):]) return (result, path) except KeyError: mount_point = os.path.dirname(mount_point)
null
null
null
Resolve the raw device that contains the path.
pcsd
def OSX Get Raw Device path device map = Get Mountpoints path = utils Smart Unicode path mount point = path = utils Normalize Path path '/' result = rdf paths Path Spec pathtype=rdf paths Path Spec Path Type OS while mount point try result path fs type = device map[mount point] if fs type in ['ext2' 'ext3' 'ext4' 'vfat' 'ntfs' 'Apple HFS' 'hfs' 'msdos'] result pathtype = rdf paths Path Spec Path Type OS else result pathtype = rdf paths Path Spec Path Type UNSET path = utils Normalize Path path[len mount point ] return result path except Key Error mount point = os path dirname mount point
8048
def OSXGetRawDevice(path): device_map = GetMountpoints() path = utils.SmartUnicode(path) mount_point = path = utils.NormalizePath(path, '/') result = rdf_paths.PathSpec(pathtype=rdf_paths.PathSpec.PathType.OS) while mount_point: try: (result.path, fs_type) = device_map[mount_point] if (fs_type in ['ext2', 'ext3', 'ext4', 'vfat', 'ntfs', 'Apple_HFS', 'hfs', 'msdos']): result.pathtype = rdf_paths.PathSpec.PathType.OS else: result.pathtype = rdf_paths.PathSpec.PathType.UNSET path = utils.NormalizePath(path[len(mount_point):]) return (result, path) except KeyError: mount_point = os.path.dirname(mount_point)
Resolve the raw device that contains the path.
resolve the raw device that contains the path .
Question: What does this function do? Code: def OSXGetRawDevice(path): device_map = GetMountpoints() path = utils.SmartUnicode(path) mount_point = path = utils.NormalizePath(path, '/') result = rdf_paths.PathSpec(pathtype=rdf_paths.PathSpec.PathType.OS) while mount_point: try: (result.path, fs_type) = device_map[mount_point] if (fs_type in ['ext2', 'ext3', 'ext4', 'vfat', 'ntfs', 'Apple_HFS', 'hfs', 'msdos']): result.pathtype = rdf_paths.PathSpec.PathType.OS else: result.pathtype = rdf_paths.PathSpec.PathType.UNSET path = utils.NormalizePath(path[len(mount_point):]) return (result, path) except KeyError: mount_point = os.path.dirname(mount_point)
null
null
null
What does this function do?
def get_seq_number(name): (head, tail) = os.path.splitext(name) if (tail == '.ts'): (match, set, num) = match_ts(name) else: num = tail[1:] if num.isdigit(): return int(num) else: return 0
null
null
null
Return sequence number if name as an int
pcsd
def get seq number name head tail = os path splitext name if tail == ' ts' match set num = match ts name else num = tail[1 ] if num isdigit return int num else return 0
8055
def get_seq_number(name): (head, tail) = os.path.splitext(name) if (tail == '.ts'): (match, set, num) = match_ts(name) else: num = tail[1:] if num.isdigit(): return int(num) else: return 0
Return sequence number if name as an int
return sequence number if name as an int
Question: What does this function do? Code: def get_seq_number(name): (head, tail) = os.path.splitext(name) if (tail == '.ts'): (match, set, num) = match_ts(name) else: num = tail[1:] if num.isdigit(): return int(num) else: return 0
null
null
null
What does this function do?
def _make_cipher(initialization_vector, secret): return AES.new(secret[:KEY_SIZE], AES.MODE_CBC, initialization_vector[:AES.block_size])
null
null
null
Return a block cipher object for use in `encrypt` and `decrypt`.
pcsd
def make cipher initialization vector secret return AES new secret[ KEY SIZE] AES MODE CBC initialization vector[ AES block size]
8058
def _make_cipher(initialization_vector, secret): return AES.new(secret[:KEY_SIZE], AES.MODE_CBC, initialization_vector[:AES.block_size])
Return a block cipher object for use in `encrypt` and `decrypt`.
return a block cipher object for use in encrypt and decrypt .
Question: What does this function do? Code: def _make_cipher(initialization_vector, secret): return AES.new(secret[:KEY_SIZE], AES.MODE_CBC, initialization_vector[:AES.block_size])
null
null
null
What does this function do?
def check_auth(name, sock_dir=None, queue=None, timeout=300): event = salt.utils.event.SaltEvent('master', sock_dir, listen=True) starttime = time.mktime(time.localtime()) newtimeout = timeout log.debug('In check_auth, waiting for {0} to become available'.format(name)) while (newtimeout > 0): newtimeout = (timeout - (time.mktime(time.localtime()) - starttime)) ret = event.get_event(full=True) if (ret is None): continue if ((ret['tag'] == 'minion_start') and (ret['data']['id'] == name)): queue.put(name) newtimeout = 0 log.debug('Minion {0} is ready to receive commands'.format(name))
null
null
null
This function is called from a multiprocess instance, to wait for a minion to become available to receive salt commands
pcsd
def check auth name sock dir=None queue=None timeout=300 event = salt utils event Salt Event 'master' sock dir listen=True starttime = time mktime time localtime newtimeout = timeout log debug 'In check auth waiting for {0} to become available' format name while newtimeout > 0 newtimeout = timeout - time mktime time localtime - starttime ret = event get event full=True if ret is None continue if ret['tag'] == 'minion start' and ret['data']['id'] == name queue put name newtimeout = 0 log debug 'Minion {0} is ready to receive commands' format name
8062
def check_auth(name, sock_dir=None, queue=None, timeout=300): event = salt.utils.event.SaltEvent('master', sock_dir, listen=True) starttime = time.mktime(time.localtime()) newtimeout = timeout log.debug('In check_auth, waiting for {0} to become available'.format(name)) while (newtimeout > 0): newtimeout = (timeout - (time.mktime(time.localtime()) - starttime)) ret = event.get_event(full=True) if (ret is None): continue if ((ret['tag'] == 'minion_start') and (ret['data']['id'] == name)): queue.put(name) newtimeout = 0 log.debug('Minion {0} is ready to receive commands'.format(name))
This function is called from a multiprocess instance, to wait for a minion to become available to receive salt commands
this function is called from a multiprocess instance , to wait for a minion to become available to receive salt commands
Question: What does this function do? Code: def check_auth(name, sock_dir=None, queue=None, timeout=300): event = salt.utils.event.SaltEvent('master', sock_dir, listen=True) starttime = time.mktime(time.localtime()) newtimeout = timeout log.debug('In check_auth, waiting for {0} to become available'.format(name)) while (newtimeout > 0): newtimeout = (timeout - (time.mktime(time.localtime()) - starttime)) ret = event.get_event(full=True) if (ret is None): continue if ((ret['tag'] == 'minion_start') and (ret['data']['id'] == name)): queue.put(name) newtimeout = 0 log.debug('Minion {0} is ready to receive commands'.format(name))
null
null
null
What does this function do?
def in6_ptoc(addr): try: d = struct.unpack('!IIII', inet_pton(socket.AF_INET6, addr)) except: return None res = 0 m = [(2 ** 96), (2 ** 64), (2 ** 32), 1] for i in xrange(4): res += (d[i] * m[i]) rem = res res = [] while rem: res.append(_rfc1924map[(rem % 85)]) rem = (rem / 85) res.reverse() return ''.join(res)
null
null
null
Converts an IPv6 address in printable representation to RFC 1924 Compact Representation ;-) Returns None on error.
pcsd
def in6 ptoc addr try d = struct unpack '!IIII' inet pton socket AF INET6 addr except return None res = 0 m = [ 2 ** 96 2 ** 64 2 ** 32 1] for i in xrange 4 res += d[i] * m[i] rem = res res = [] while rem res append rfc1924map[ rem % 85 ] rem = rem / 85 res reverse return '' join res
8063
def in6_ptoc(addr): try: d = struct.unpack('!IIII', inet_pton(socket.AF_INET6, addr)) except: return None res = 0 m = [(2 ** 96), (2 ** 64), (2 ** 32), 1] for i in xrange(4): res += (d[i] * m[i]) rem = res res = [] while rem: res.append(_rfc1924map[(rem % 85)]) rem = (rem / 85) res.reverse() return ''.join(res)
Converts an IPv6 address in printable representation to RFC 1924 Compact Representation ;-) Returns None on error.
converts an ipv6 address in printable representation to rfc 1924 compact representation ; - )
Question: What does this function do? Code: def in6_ptoc(addr): try: d = struct.unpack('!IIII', inet_pton(socket.AF_INET6, addr)) except: return None res = 0 m = [(2 ** 96), (2 ** 64), (2 ** 32), 1] for i in xrange(4): res += (d[i] * m[i]) rem = res res = [] while rem: res.append(_rfc1924map[(rem % 85)]) rem = (rem / 85) res.reverse() return ''.join(res)
null
null
null
What does this function do?
def swapaxes(y, axis1, axis2): y = as_tensor_variable(y) ndim = y.ndim li = list(range(0, ndim)) (li[axis1], li[axis2]) = (li[axis2], li[axis1]) return y.dimshuffle(li)
null
null
null
swap axes of inputted tensor
pcsd
def swapaxes y axis1 axis2 y = as tensor variable y ndim = y ndim li = list range 0 ndim li[axis1] li[axis2] = li[axis2] li[axis1] return y dimshuffle li
8065
def swapaxes(y, axis1, axis2): y = as_tensor_variable(y) ndim = y.ndim li = list(range(0, ndim)) (li[axis1], li[axis2]) = (li[axis2], li[axis1]) return y.dimshuffle(li)
swap axes of inputted tensor
swap axes of inputted tensor
Question: What does this function do? Code: def swapaxes(y, axis1, axis2): y = as_tensor_variable(y) ndim = y.ndim li = list(range(0, ndim)) (li[axis1], li[axis2]) = (li[axis2], li[axis1]) return y.dimshuffle(li)
null
null
null
What does this function do?
def acos(x): np = import_module('numpy') if isinstance(x, (int, float)): if (abs(x) > 1): return interval((- np.inf), np.inf, is_valid=False) else: return interval(np.arccos(x), np.arccos(x)) elif isinstance(x, interval): if ((x.is_valid is False) or (x.start > 1) or (x.end < (-1))): return interval((- np.inf), np.inf, is_valid=False) elif ((x.start < (-1)) or (x.end > 1)): return interval((- np.inf), np.inf, is_valid=None) else: start = np.arccos(x.start) end = np.arccos(x.end) return interval(start, end, is_valid=x.is_valid)
null
null
null
Evaluates the inverse cos of an interval
pcsd
def acos x np = import module 'numpy' if isinstance x int float if abs x > 1 return interval - np inf np inf is valid=False else return interval np arccos x np arccos x elif isinstance x interval if x is valid is False or x start > 1 or x end < -1 return interval - np inf np inf is valid=False elif x start < -1 or x end > 1 return interval - np inf np inf is valid=None else start = np arccos x start end = np arccos x end return interval start end is valid=x is valid
8072
def acos(x): np = import_module('numpy') if isinstance(x, (int, float)): if (abs(x) > 1): return interval((- np.inf), np.inf, is_valid=False) else: return interval(np.arccos(x), np.arccos(x)) elif isinstance(x, interval): if ((x.is_valid is False) or (x.start > 1) or (x.end < (-1))): return interval((- np.inf), np.inf, is_valid=False) elif ((x.start < (-1)) or (x.end > 1)): return interval((- np.inf), np.inf, is_valid=None) else: start = np.arccos(x.start) end = np.arccos(x.end) return interval(start, end, is_valid=x.is_valid)
Evaluates the inverse cos of an interval
evaluates the inverse cos of an interval
Question: What does this function do? Code: def acos(x): np = import_module('numpy') if isinstance(x, (int, float)): if (abs(x) > 1): return interval((- np.inf), np.inf, is_valid=False) else: return interval(np.arccos(x), np.arccos(x)) elif isinstance(x, interval): if ((x.is_valid is False) or (x.start > 1) or (x.end < (-1))): return interval((- np.inf), np.inf, is_valid=False) elif ((x.start < (-1)) or (x.end > 1)): return interval((- np.inf), np.inf, is_valid=None) else: start = np.arccos(x.start) end = np.arccos(x.end) return interval(start, end, is_valid=x.is_valid)
null
null
null
What does this function do?
def _objective_func(f, x, k_params, alpha, *args): x_arr = np.asarray(x) params = x_arr[:k_params].ravel() u = x_arr[k_params:] objective_func_arr = (f(params, *args) + (alpha * u).sum()) return matrix(objective_func_arr)
null
null
null
The regularized objective function.
pcsd
def objective func f x k params alpha *args x arr = np asarray x params = x arr[ k params] ravel u = x arr[k params ] objective func arr = f params *args + alpha * u sum return matrix objective func arr
8075
def _objective_func(f, x, k_params, alpha, *args): x_arr = np.asarray(x) params = x_arr[:k_params].ravel() u = x_arr[k_params:] objective_func_arr = (f(params, *args) + (alpha * u).sum()) return matrix(objective_func_arr)
The regularized objective function.
the regularized objective function .
Question: What does this function do? Code: def _objective_func(f, x, k_params, alpha, *args): x_arr = np.asarray(x) params = x_arr[:k_params].ravel() u = x_arr[k_params:] objective_func_arr = (f(params, *args) + (alpha * u).sum()) return matrix(objective_func_arr)
null
null
null
What does this function do?
def norm_l21_tf(Z, shape, n_orient): if Z.shape[0]: Z2 = Z.reshape(*shape) l21_norm = np.sqrt(stft_norm2(Z2).reshape((-1), n_orient).sum(axis=1)) l21_norm = l21_norm.sum() else: l21_norm = 0.0 return l21_norm
null
null
null
L21 norm for TF.
pcsd
def norm l21 tf Z shape n orient if Z shape[0] Z2 = Z reshape *shape l21 norm = np sqrt stft norm2 Z2 reshape -1 n orient sum axis=1 l21 norm = l21 norm sum else l21 norm = 0 0 return l21 norm
8077
def norm_l21_tf(Z, shape, n_orient): if Z.shape[0]: Z2 = Z.reshape(*shape) l21_norm = np.sqrt(stft_norm2(Z2).reshape((-1), n_orient).sum(axis=1)) l21_norm = l21_norm.sum() else: l21_norm = 0.0 return l21_norm
L21 norm for TF.
l21 norm for tf .
Question: What does this function do? Code: def norm_l21_tf(Z, shape, n_orient): if Z.shape[0]: Z2 = Z.reshape(*shape) l21_norm = np.sqrt(stft_norm2(Z2).reshape((-1), n_orient).sum(axis=1)) l21_norm = l21_norm.sum() else: l21_norm = 0.0 return l21_norm
null
null
null
What does this function do?
@register.inclusion_tag('zinnia/tags/dummy.html') def get_featured_entries(number=5, template='zinnia/tags/entries_featured.html'): return {'template': template, 'entries': Entry.published.filter(featured=True)[:number]}
null
null
null
Return the featured entries.
pcsd
@register inclusion tag 'zinnia/tags/dummy html' def get featured entries number=5 template='zinnia/tags/entries featured html' return {'template' template 'entries' Entry published filter featured=True [ number]}
8082
@register.inclusion_tag('zinnia/tags/dummy.html') def get_featured_entries(number=5, template='zinnia/tags/entries_featured.html'): return {'template': template, 'entries': Entry.published.filter(featured=True)[:number]}
Return the featured entries.
return the featured entries .
Question: What does this function do? Code: @register.inclusion_tag('zinnia/tags/dummy.html') def get_featured_entries(number=5, template='zinnia/tags/entries_featured.html'): return {'template': template, 'entries': Entry.published.filter(featured=True)[:number]}
null
null
null
What does this function do?
def build_model(tparams, options): opt_ret = dict() trng = RandomStreams(1234) x = tensor.matrix('x', dtype='int64') mask = tensor.matrix('mask', dtype='float32') ctx = tensor.matrix('ctx', dtype='float32') n_timesteps = x.shape[0] n_samples = x.shape[1] emb = tparams['Wemb'][x.flatten()].reshape([n_timesteps, n_samples, options['dim_word']]) emb_shifted = tensor.zeros_like(emb) emb_shifted = tensor.set_subtensor(emb_shifted[1:], emb[:(-1)]) emb = emb_shifted init_state = get_layer('ff')[1](tparams, ctx, options, prefix='ff_state', activ='tanh') proj = get_layer(options['decoder'])[1](tparams, emb, init_state, options, prefix='decoder', mask=mask) if options['doutput']: hid = get_layer('ff')[1](tparams, proj[0], options, prefix='ff_hid', activ='tanh') logit = get_layer('ff')[1](tparams, hid, options, prefix='ff_logit', activ='linear') else: logit = get_layer('ff')[1](tparams, proj[0], options, prefix='ff_logit', activ='linear') logit_shp = logit.shape probs = tensor.nnet.softmax(logit.reshape([(logit_shp[0] * logit_shp[1]), logit_shp[2]])) x_flat = x.flatten() p_flat = probs.flatten() cost = (- tensor.log((p_flat[((tensor.arange(x_flat.shape[0]) * probs.shape[1]) + x_flat)] + 1e-08))) cost = cost.reshape([x.shape[0], x.shape[1]]) cost = (cost * mask).sum(0) cost = cost.sum() return (trng, [x, mask, ctx], cost)
null
null
null
Computation graph for the model
pcsd
def build model tparams options opt ret = dict trng = Random Streams 1234 x = tensor matrix 'x' dtype='int64' mask = tensor matrix 'mask' dtype='float32' ctx = tensor matrix 'ctx' dtype='float32' n timesteps = x shape[0] n samples = x shape[1] emb = tparams['Wemb'][x flatten ] reshape [n timesteps n samples options['dim word']] emb shifted = tensor zeros like emb emb shifted = tensor set subtensor emb shifted[1 ] emb[ -1 ] emb = emb shifted init state = get layer 'ff' [1] tparams ctx options prefix='ff state' activ='tanh' proj = get layer options['decoder'] [1] tparams emb init state options prefix='decoder' mask=mask if options['doutput'] hid = get layer 'ff' [1] tparams proj[0] options prefix='ff hid' activ='tanh' logit = get layer 'ff' [1] tparams hid options prefix='ff logit' activ='linear' else logit = get layer 'ff' [1] tparams proj[0] options prefix='ff logit' activ='linear' logit shp = logit shape probs = tensor nnet softmax logit reshape [ logit shp[0] * logit shp[1] logit shp[2]] x flat = x flatten p flat = probs flatten cost = - tensor log p flat[ tensor arange x flat shape[0] * probs shape[1] + x flat ] + 1e-08 cost = cost reshape [x shape[0] x shape[1]] cost = cost * mask sum 0 cost = cost sum return trng [x mask ctx] cost
8084
def build_model(tparams, options): opt_ret = dict() trng = RandomStreams(1234) x = tensor.matrix('x', dtype='int64') mask = tensor.matrix('mask', dtype='float32') ctx = tensor.matrix('ctx', dtype='float32') n_timesteps = x.shape[0] n_samples = x.shape[1] emb = tparams['Wemb'][x.flatten()].reshape([n_timesteps, n_samples, options['dim_word']]) emb_shifted = tensor.zeros_like(emb) emb_shifted = tensor.set_subtensor(emb_shifted[1:], emb[:(-1)]) emb = emb_shifted init_state = get_layer('ff')[1](tparams, ctx, options, prefix='ff_state', activ='tanh') proj = get_layer(options['decoder'])[1](tparams, emb, init_state, options, prefix='decoder', mask=mask) if options['doutput']: hid = get_layer('ff')[1](tparams, proj[0], options, prefix='ff_hid', activ='tanh') logit = get_layer('ff')[1](tparams, hid, options, prefix='ff_logit', activ='linear') else: logit = get_layer('ff')[1](tparams, proj[0], options, prefix='ff_logit', activ='linear') logit_shp = logit.shape probs = tensor.nnet.softmax(logit.reshape([(logit_shp[0] * logit_shp[1]), logit_shp[2]])) x_flat = x.flatten() p_flat = probs.flatten() cost = (- tensor.log((p_flat[((tensor.arange(x_flat.shape[0]) * probs.shape[1]) + x_flat)] + 1e-08))) cost = cost.reshape([x.shape[0], x.shape[1]]) cost = (cost * mask).sum(0) cost = cost.sum() return (trng, [x, mask, ctx], cost)
Computation graph for the model
computation graph for the model
Question: What does this function do? Code: def build_model(tparams, options): opt_ret = dict() trng = RandomStreams(1234) x = tensor.matrix('x', dtype='int64') mask = tensor.matrix('mask', dtype='float32') ctx = tensor.matrix('ctx', dtype='float32') n_timesteps = x.shape[0] n_samples = x.shape[1] emb = tparams['Wemb'][x.flatten()].reshape([n_timesteps, n_samples, options['dim_word']]) emb_shifted = tensor.zeros_like(emb) emb_shifted = tensor.set_subtensor(emb_shifted[1:], emb[:(-1)]) emb = emb_shifted init_state = get_layer('ff')[1](tparams, ctx, options, prefix='ff_state', activ='tanh') proj = get_layer(options['decoder'])[1](tparams, emb, init_state, options, prefix='decoder', mask=mask) if options['doutput']: hid = get_layer('ff')[1](tparams, proj[0], options, prefix='ff_hid', activ='tanh') logit = get_layer('ff')[1](tparams, hid, options, prefix='ff_logit', activ='linear') else: logit = get_layer('ff')[1](tparams, proj[0], options, prefix='ff_logit', activ='linear') logit_shp = logit.shape probs = tensor.nnet.softmax(logit.reshape([(logit_shp[0] * logit_shp[1]), logit_shp[2]])) x_flat = x.flatten() p_flat = probs.flatten() cost = (- tensor.log((p_flat[((tensor.arange(x_flat.shape[0]) * probs.shape[1]) + x_flat)] + 1e-08))) cost = cost.reshape([x.shape[0], x.shape[1]]) cost = (cost * mask).sum(0) cost = cost.sum() return (trng, [x, mask, ctx], cost)
null
null
null
What does this function do?
@api_wrapper def get_volume(module, system): try: return system.volumes.get(name=module.params['name']) except: return None
null
null
null
Return Volume or None
pcsd
@api wrapper def get volume module system try return system volumes get name=module params['name'] except return None
8095
@api_wrapper def get_volume(module, system): try: return system.volumes.get(name=module.params['name']) except: return None
Return Volume or None
return volume or none
Question: What does this function do? Code: @api_wrapper def get_volume(module, system): try: return system.volumes.get(name=module.params['name']) except: return None
null
null
null
What does this function do?
def addValueToOutput(depth, keyInput, output, value): depthStart = (' ' * depth) output.write(('%s%s:' % (depthStart, keyInput))) if (value.__class__ == dict): output.write('\n') keys = value.keys() keys.sort() for key in keys: addValueToOutput((depth + 1), key, output, value[key]) return if (value.__class__ == list): output.write('\n') for (elementIndex, element) in enumerate(value): addValueToOutput((depth + 1), elementIndex, output, element) return output.write((' %s\n' % value))
null
null
null
Add value to the output.
pcsd
def add Value To Output depth key Input output value depth Start = ' ' * depth output write '%s%s ' % depth Start key Input if value class == dict output write ' ' keys = value keys keys sort for key in keys add Value To Output depth + 1 key output value[key] return if value class == list output write ' ' for element Index element in enumerate value add Value To Output depth + 1 element Index output element return output write ' %s ' % value
8096
def addValueToOutput(depth, keyInput, output, value): depthStart = (' ' * depth) output.write(('%s%s:' % (depthStart, keyInput))) if (value.__class__ == dict): output.write('\n') keys = value.keys() keys.sort() for key in keys: addValueToOutput((depth + 1), key, output, value[key]) return if (value.__class__ == list): output.write('\n') for (elementIndex, element) in enumerate(value): addValueToOutput((depth + 1), elementIndex, output, element) return output.write((' %s\n' % value))
Add value to the output.
add value to the output .
Question: What does this function do? Code: def addValueToOutput(depth, keyInput, output, value): depthStart = (' ' * depth) output.write(('%s%s:' % (depthStart, keyInput))) if (value.__class__ == dict): output.write('\n') keys = value.keys() keys.sort() for key in keys: addValueToOutput((depth + 1), key, output, value[key]) return if (value.__class__ == list): output.write('\n') for (elementIndex, element) in enumerate(value): addValueToOutput((depth + 1), elementIndex, output, element) return output.write((' %s\n' % value))
null
null
null
What does this function do?
def format_freshdesk_ticket_creation_message(ticket): cleaned_description = convert_html_to_markdown(ticket.description) content = ('%s <%s> created [ticket #%s](%s):\n\n' % (ticket.requester_name, ticket.requester_email, ticket.id, ticket.url)) content += ('~~~ quote\n%s\n~~~\n\n' % (cleaned_description,)) content += ('Type: **%s**\nPriority: **%s**\nStatus: **%s**' % (ticket.type, ticket.priority, ticket.status)) return content
null
null
null
They send us the description as HTML.
pcsd
def format freshdesk ticket creation message ticket cleaned description = convert html to markdown ticket description content = '%s <%s> created [ticket #%s] %s ' % ticket requester name ticket requester email ticket id ticket url content += '~~~ quote %s ~~~ ' % cleaned description content += 'Type **%s** Priority **%s** Status **%s**' % ticket type ticket priority ticket status return content
8098
def format_freshdesk_ticket_creation_message(ticket): cleaned_description = convert_html_to_markdown(ticket.description) content = ('%s <%s> created [ticket #%s](%s):\n\n' % (ticket.requester_name, ticket.requester_email, ticket.id, ticket.url)) content += ('~~~ quote\n%s\n~~~\n\n' % (cleaned_description,)) content += ('Type: **%s**\nPriority: **%s**\nStatus: **%s**' % (ticket.type, ticket.priority, ticket.status)) return content
They send us the description as HTML.
they send us the description as html .
Question: What does this function do? Code: def format_freshdesk_ticket_creation_message(ticket): cleaned_description = convert_html_to_markdown(ticket.description) content = ('%s <%s> created [ticket #%s](%s):\n\n' % (ticket.requester_name, ticket.requester_email, ticket.id, ticket.url)) content += ('~~~ quote\n%s\n~~~\n\n' % (cleaned_description,)) content += ('Type: **%s**\nPriority: **%s**\nStatus: **%s**' % (ticket.type, ticket.priority, ticket.status)) return content
null
null
null
What does this function do?
def worker(buffer, n, offset, mod, process_packet): def update_timer(): if ((time.time() - os.stat(TRAILS_FILE).st_mtime) >= config.UPDATE_PERIOD): _ = None while True: _ = load_trails(True) if _: trails.clear() trails.update(_) break else: time.sleep(LOAD_TRAILS_RETRY_SLEEP_TIME) threading.Timer(config.UPDATE_PERIOD, update_timer).start() update_timer() count = 0L while True: try: if ((count % mod) == offset): if (count >= n.value): time.sleep(REGULAR_SENSOR_SLEEP_TIME) continue content = read_block(buffer, count) if (content is None): break if (len(content) < 12): continue (sec, usec, ip_offset) = struct.unpack('=III', content[:12]) packet = content[12:] process_packet(packet, sec, usec, ip_offset) count += 1 except KeyboardInterrupt: break
null
null
null
Worker process used in multiprocessing mode
pcsd
def worker buffer n offset mod process packet def update timer if time time - os stat TRAILS FILE st mtime >= config UPDATE PERIOD = None while True = load trails True if trails clear trails update break else time sleep LOAD TRAILS RETRY SLEEP TIME threading Timer config UPDATE PERIOD update timer start update timer count = 0L while True try if count % mod == offset if count >= n value time sleep REGULAR SENSOR SLEEP TIME continue content = read block buffer count if content is None break if len content < 12 continue sec usec ip offset = struct unpack '=III' content[ 12] packet = content[12 ] process packet packet sec usec ip offset count += 1 except Keyboard Interrupt break
8107
def worker(buffer, n, offset, mod, process_packet): def update_timer(): if ((time.time() - os.stat(TRAILS_FILE).st_mtime) >= config.UPDATE_PERIOD): _ = None while True: _ = load_trails(True) if _: trails.clear() trails.update(_) break else: time.sleep(LOAD_TRAILS_RETRY_SLEEP_TIME) threading.Timer(config.UPDATE_PERIOD, update_timer).start() update_timer() count = 0L while True: try: if ((count % mod) == offset): if (count >= n.value): time.sleep(REGULAR_SENSOR_SLEEP_TIME) continue content = read_block(buffer, count) if (content is None): break if (len(content) < 12): continue (sec, usec, ip_offset) = struct.unpack('=III', content[:12]) packet = content[12:] process_packet(packet, sec, usec, ip_offset) count += 1 except KeyboardInterrupt: break
Worker process used in multiprocessing mode
worker process used in multiprocessing mode
Question: What does this function do? Code: def worker(buffer, n, offset, mod, process_packet): def update_timer(): if ((time.time() - os.stat(TRAILS_FILE).st_mtime) >= config.UPDATE_PERIOD): _ = None while True: _ = load_trails(True) if _: trails.clear() trails.update(_) break else: time.sleep(LOAD_TRAILS_RETRY_SLEEP_TIME) threading.Timer(config.UPDATE_PERIOD, update_timer).start() update_timer() count = 0L while True: try: if ((count % mod) == offset): if (count >= n.value): time.sleep(REGULAR_SENSOR_SLEEP_TIME) continue content = read_block(buffer, count) if (content is None): break if (len(content) < 12): continue (sec, usec, ip_offset) = struct.unpack('=III', content[:12]) packet = content[12:] process_packet(packet, sec, usec, ip_offset) count += 1 except KeyboardInterrupt: break
null
null
null
What does this function do?
def build_fragments_list(boot_info): res = [] segment_run_table = boot_info[u'segments'][0] segment_run_entry = segment_run_table[u'segment_run'][0] n_frags = segment_run_entry[1] fragment_run_entry_table = boot_info[u'fragments'][0][u'fragments'] first_frag_number = fragment_run_entry_table[0][u'first'] for (i, frag_number) in zip(range(1, (n_frags + 1)), itertools.count(first_frag_number)): res.append((1, frag_number)) return res
null
null
null
Return a list of (segment, fragment) for each fragment in the video
pcsd
def build fragments list boot info res = [] segment run table = boot info[u'segments'][0] segment run entry = segment run table[u'segment run'][0] n frags = segment run entry[1] fragment run entry table = boot info[u'fragments'][0][u'fragments'] first frag number = fragment run entry table[0][u'first'] for i frag number in zip range 1 n frags + 1 itertools count first frag number res append 1 frag number return res
8110
def build_fragments_list(boot_info): res = [] segment_run_table = boot_info[u'segments'][0] segment_run_entry = segment_run_table[u'segment_run'][0] n_frags = segment_run_entry[1] fragment_run_entry_table = boot_info[u'fragments'][0][u'fragments'] first_frag_number = fragment_run_entry_table[0][u'first'] for (i, frag_number) in zip(range(1, (n_frags + 1)), itertools.count(first_frag_number)): res.append((1, frag_number)) return res
Return a list of (segment, fragment) for each fragment in the video
return a list of for each fragment in the video
Question: What does this function do? Code: def build_fragments_list(boot_info): res = [] segment_run_table = boot_info[u'segments'][0] segment_run_entry = segment_run_table[u'segment_run'][0] n_frags = segment_run_entry[1] fragment_run_entry_table = boot_info[u'fragments'][0][u'fragments'] first_frag_number = fragment_run_entry_table[0][u'first'] for (i, frag_number) in zip(range(1, (n_frags + 1)), itertools.count(first_frag_number)): res.append((1, frag_number)) return res
null
null
null
What does this function do?
def _map_rect_to_scene(self, rect): return self.sceneTransform().mapRect(rect)
null
null
null
Only available in newer PyQt4 versions
pcsd
def map rect to scene self rect return self scene Transform map Rect rect
8120
def _map_rect_to_scene(self, rect): return self.sceneTransform().mapRect(rect)
Only available in newer PyQt4 versions
only available in newer pyqt4 versions
Question: What does this function do? Code: def _map_rect_to_scene(self, rect): return self.sceneTransform().mapRect(rect)
null
null
null
What does this function do?
def select_indirect_adjacent(cache, left, right): right = (always_in if (right is None) else frozenset(right)) for parent in left: for sibling in cache.itersiblings(parent): if (sibling in right): (yield sibling)
null
null
null
right is a sibling after left, immediately or not
pcsd
def select indirect adjacent cache left right right = always in if right is None else frozenset right for parent in left for sibling in cache itersiblings parent if sibling in right yield sibling
8122
def select_indirect_adjacent(cache, left, right): right = (always_in if (right is None) else frozenset(right)) for parent in left: for sibling in cache.itersiblings(parent): if (sibling in right): (yield sibling)
right is a sibling after left, immediately or not
right is a sibling after left , immediately or not
Question: What does this function do? Code: def select_indirect_adjacent(cache, left, right): right = (always_in if (right is None) else frozenset(right)) for parent in left: for sibling in cache.itersiblings(parent): if (sibling in right): (yield sibling)