idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
58,800
def run ( self ) : import fnmatch import shutil import glob matches = [ ] matches . extend ( glob . glob ( './*.pyc' ) ) matches . extend ( glob . glob ( './*.pyd' ) ) matches . extend ( glob . glob ( './*.pyo' ) ) matches . extend ( glob . glob ( './*.so' ) ) dirs = [ ] dirs . extend ( glob . glob ( './__pycache__' ) ...
Run CleanUp .
58,801
def run ( self ) : if os . system ( 'git add .' ) : sys . exit ( 1 ) if self . message is not None : os . system ( 'git commit -a -m "' + self . message + '"' ) else : os . system ( 'git commit -a' )
Run git add and commit with message if provided .
58,802
def uri ( self , value ) : jsonpointer . set_pointer ( self . record , self . pointer , value )
Set new uri value in record .
58,803
def open ( self , mode = 'r' , ** kwargs ) : _fs , filename = opener . parse ( self . uri ) return _fs . open ( filename , mode = mode , ** kwargs )
Open file uri under the pointer .
58,804
def move ( self , dst , ** kwargs ) : _fs , filename = opener . parse ( self . uri ) _fs_dst , filename_dst = opener . parse ( dst ) movefile ( _fs , filename , _fs_dst , filename_dst , ** kwargs ) self . uri = dst
Move file to a new destination and update uri .
58,805
def setcontents ( self , source , ** kwargs ) : if isinstance ( source , six . string_types ) : _file = opener . open ( source , 'rb' ) else : _file = source data = _file . read ( ) _fs , filename = opener . parse ( self . uri ) _fs . setcontents ( filename , data , ** kwargs ) _fs . close ( ) if isinstance ( source , ...
Create a new file from a string or file - like object .
58,806
def remove ( self , force = False ) : if force : _fs , filename = opener . parse ( self . uri ) _fs . remove ( filename ) self . uri = None
Remove file reference from record .
58,807
def tobytes ( self , root = None , encoding = 'UTF-8' , doctype = None , canonicalized = True , xml_declaration = True , pretty_print = True , with_comments = True , ) : if root is None : root = self . root if canonicalized == True : return self . canonicalized_bytes ( root ) else : return etree . tostring ( root , enc...
return the content of the XML document as a byte string suitable for writing
58,808
def tostring ( self , root = None , doctype = None , pretty_print = True ) : if root is None : root = self . root return etree . tounicode ( root , doctype = doctype or self . info . doctype , pretty_print = pretty_print )
return the content of the XML document as a unicode string
58,809
def digest ( self , ** args ) : return String ( XML . canonicalized_string ( self . root ) ) . digest ( ** args )
calculate a digest based on the hash of the XML content
58,810
def element ( self , tag_path , test = None , ** attributes ) : xpath = tag_path tests = [ "@%s='%s'" % ( k , attributes [ k ] ) for k in attributes ] if test is not None : tests . insert ( 0 , test ) if len ( tests ) > 0 : xpath += "[%s]" % ' and ' . join ( tests ) e = self . find ( self . root , xpath ) if e is None ...
given a tag in xpath form and optional attributes find the element in self . root or return a new one .
58,811
def namespace ( self , elem = None ) : if elem is None : elem = self . root return XML . tag_namespace ( elem . tag )
return the URL if any for the doc root or elem if given .
58,812
def tag_namespace ( cls , tag ) : md = re . match ( "^(?:\{([^\}]*)\})" , tag ) if md is not None : return md . group ( 1 )
return the namespace for a given tag or if no namespace given
58,813
def tag_name ( cls , tag ) : while isinstance ( tag , etree . _Element ) : tag = tag . tag return tag . split ( '}' ) [ - 1 ]
return the name of the tag with the namespace removed
58,814
def element_map ( self , tags = None , xpath = "//*" , exclude_attribs = [ ] , include_attribs = [ ] , attrib_vals = False , hierarchy = False , minimize = False , ) : if tags is None : tags = Dict ( ) for elem in self . root . xpath ( xpath ) : if elem . tag not in tags . keys ( ) : tags [ elem . tag ] = Dict ( ** { '...
return a dict of element tags their attribute names and optionally attribute values in the XML document
58,815
def dict_key_tag ( Class , key , namespaces = None ) : namespaces = namespaces or Class . NS ns = Class . tag_namespace ( key ) tag = Class . tag_name ( key ) if ns is None and ':' in key : prefix , tag = key . split ( ':' ) if prefix in namespaces . keys ( ) : ns = namespaces [ prefix ] if ns is not None : tag = "{%s}...
convert a dict key into an element or attribute name
58,816
def replace_with_contents ( c , elem ) : "removes an element and leaves its contents in its place. Namespaces supported." parent = elem . getparent ( ) index = parent . index ( elem ) children = elem . getchildren ( ) previous = elem . getprevious ( ) if index == 0 : parent . text = ( parent . text or '' ) + ( elem . t...
removes an element and leaves its contents in its place . Namespaces supported .
58,817
def remove_range ( cls , elem , end_elem , delete_end = True ) : while elem is not None and elem != end_elem and end_elem not in elem . xpath ( "descendant::*" ) : parent = elem . getparent ( ) nxt = elem . getnext ( ) parent . remove ( elem ) if DEBUG == True : print ( etree . tounicode ( elem ) ) elem = nxt if elem =...
delete everything from elem to end_elem including elem . if delete_end == True also including end_elem ; otherwise leave it .
58,818
def wrap_content ( cls , container , wrapper ) : "wrap the content of container element with wrapper element" wrapper . text = ( container . text or '' ) + ( wrapper . text or '' ) container . text = '' for ch in container : wrapper . append ( ch ) container . insert ( 0 , wrapper ) return container
wrap the content of container element with wrapper element
58,819
def merge_contiguous ( C , node , xpath , namespaces = None ) : new_node = deepcopy ( node ) elems = XML . xpath ( new_node , xpath , namespaces = namespaces ) elems . reverse ( ) for elem in elems : nxt = elem . getnext ( ) if elem . attrib == { } : XML . replace_with_contents ( elem ) elif ( elem . tail in [ None , '...
Within a given node merge elements that are next to each other if they have the same tag and attributes .
58,820
def unnest ( c , elem , ignore_whitespace = False ) : parent = elem . getparent ( ) gparent = parent . getparent ( ) index = parent . index ( elem ) preparent = etree . Element ( parent . tag ) preparent . text , parent . text = ( parent . text or '' ) , '' for k in parent . attrib . keys ( ) : preparent . set ( k , pa...
unnest the element from its parent within doc . MUTABLE CHANGES
58,821
def interior_nesting ( cls , elem1 , xpath , namespaces = None ) : for elem2 in elem1 . xpath ( xpath , namespaces = namespaces ) : child_elem1 = etree . Element ( elem1 . tag ) for k in elem1 . attrib : child_elem1 . set ( k , elem1 . get ( k ) ) child_elem1 . text , elem2 . text = elem2 . text , '' for ch in elem2 . ...
for elem1 containing elements at xpath embed elem1 inside each of those elements and then remove the original elem1
58,822
def fragment_nesting ( cls , elem1 , tag2 , namespaces = None ) : elems2 = elem1 . xpath ( "child::%s" % tag2 , namespaces = namespaces ) while len ( elems2 ) > 0 : elem2 = elems2 [ 0 ] parent2 = elem2 . getparent ( ) index2 = parent2 . index ( elem2 ) child_elem1 = etree . Element ( elem1 . tag ) for k in elem1 . attr...
for elem1 containing elements with tag2 fragment elem1 into elems that are adjacent to and nested within tag2
58,823
def communityvisibilitystate ( self ) : if self . _communityvisibilitystate == None : return None elif self . _communityvisibilitystate in self . VisibilityState : return self . VisibilityState [ self . _communityvisibilitystate ] else : return None
Return the Visibility State of the Users Profile
58,824
def personastate ( self ) : if self . _personastate == None : return None elif self . _personastate in self . PersonaState : return self . PersonaState [ self . _personastate ] else : return None
Return the Persona State of the Users Profile
58,825
def mcus ( ) : ls = [ ] for h in hwpack_names ( ) : for b in board_names ( h ) : ls += [ mcu ( b , h ) ] ls = sorted ( list ( set ( ls ) ) ) return ls
MCU list .
58,826
def logpath2dt ( filepath ) : return datetime . datetime . strptime ( re . match ( r'.*/(.*) .*$' , filepath ) . groups ( ) [ 0 ] , '%Y-%m-%d %H-%M' )
given a dataflashlog in the format produced by Mission Planner return a datetime which says when the file was downloaded from the APM
58,827
def url ( self ) : path = '/web/itemdetails.html?id={}' . format ( self . id ) return self . connector . get_url ( path , attach_api_key = False )
url of the item
58,828
async def update ( self , fields = '' ) : path = 'Users/{{UserId}}/Items/{}' . format ( self . id ) info = await self . connector . getJson ( path , remote = False , Fields = 'Path,Overview,' + fields ) self . object_dict . update ( info ) self . extras = { } return self
reload object info from emby
58,829
async def send ( self ) : path = 'Items/{}' . format ( self . id ) resp = await self . connector . post ( path , data = self . object_dict , remote = False ) if resp . status == 400 : await EmbyObject ( self . object_dict , self . connector ) . update ( ) resp = await self . connector . post ( path , data = self . obje...
send data that was changed to emby
58,830
def remove_lib ( lib_name ) : targ_dlib = libraries_dir ( ) / lib_name log . debug ( 'remove %s' , targ_dlib ) targ_dlib . rmtree ( )
remove library .
58,831
def _read_holidays ( self , filename ) : cal = Calendar . from_ical ( open ( filename , 'rb' ) . read ( ) ) holidays = [ ] for component in cal . walk ( 'VEVENT' ) : start = component . decoded ( 'DTSTART' ) try : end = component . decoded ( 'DTEND' ) except KeyError : if isinstance ( start , datetime ) : end = start e...
Read holidays from an iCalendar - format file .
58,832
def in_hours ( self , office = None , when = None ) : if when == None : when = datetime . now ( tz = utc ) if office == None : for office in self . offices . itervalues ( ) : if office . in_hours ( when ) : return True return False else : return self . offices [ office ] . in_hours ( when )
Finds if it is business hours in the given office .
58,833
def setup_logging ( namespace ) : loglevel = { 0 : logging . ERROR , 1 : logging . WARNING , 2 : logging . INFO , 3 : logging . DEBUG , } . get ( namespace . verbosity , logging . DEBUG ) if namespace . verbosity > 1 : logformat = '%(levelname)s csvpandas %(lineno)s %(message)s' else : logformat = 'csvpandas %(message)...
setup global logging
58,834
def parse_subcommands ( parser , subcommands , argv ) : subparsers = parser . add_subparsers ( dest = 'subparser_name' ) parser_help = subparsers . add_parser ( 'help' , help = 'Detailed help for actions using `help <action>`' ) parser_help . add_argument ( 'action' , nargs = 1 ) modules = [ name for _ , name , _ in pk...
Setup all sub - commands
58,835
def opener ( mode = 'r' ) : def open_file ( f ) : if f is sys . stdout or f is sys . stdin : return f elif f == '-' : return sys . stdin if 'r' in mode else sys . stdout elif f . endswith ( '.bz2' ) : return bz2 . BZ2File ( f , mode ) elif f . endswith ( '.gz' ) : return gzip . open ( f , mode ) else : return open ( f ...
Factory for creating file objects
58,836
def get ( self , id , no_summary = False ) : resp = self . client . accounts . get ( id ) if no_summary : return self . display ( resp ) results = [ ] client = LunrClient ( self . get_admin ( ) , debug = self . debug ) volumes = client . volumes . list ( account_id = resp [ 'id' ] ) for volume in volumes : if volume [ ...
List details for a specific tenant id
58,837
def create ( self , id ) : resp = self . client . accounts . create ( id = id ) self . display ( resp )
Create a new tenant id
58,838
def delete ( self , id ) : resp = self . client . accounts . delete ( id ) self . display ( resp )
Delete an tenant id
58,839
def main ( ) : parser = argparse . ArgumentParser ( ) group_tcp = parser . add_argument_group ( 'TCP' ) group_tcp . add_argument ( '--tcp' , dest = 'mode' , action = 'store_const' , const = PROP_MODE_TCP , help = "Set tcp mode" ) group_tcp . add_argument ( '--host' , dest = 'hostname' , help = "Specify hostname" , defa...
Main method for debug purposes .
58,840
def _open_connection ( self ) : if ( self . _mode == PROP_MODE_SERIAL ) : self . _serial = serial . Serial ( self . _serial_device , self . _serial_speed ) elif ( self . _mode == PROP_MODE_TCP ) : self . _socket = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) self . _socket . connect ( ( self . _ip , self...
Open a connection to the easyfire unit .
58,841
def _close_connection ( self ) : if ( self . _mode == PROP_MODE_SERIAL ) : self . _serial . close ( ) elif ( self . _mode == PROP_MODE_TCP ) : self . _socket . close ( ) elif ( self . _mode == PROP_MODE_FILE ) : self . _file . close ( )
Close the connection to the easyfire unit .
58,842
def _add_to_checksum ( self , checksum , value ) : checksum = self . _byte_rot_left ( checksum , 1 ) checksum = checksum + value if ( checksum > 255 ) : checksum = checksum - 255 self . _debug ( PROP_LOGLEVEL_TRACE , "C: " + str ( checksum ) + " V: " + str ( value ) ) return checksum
Add a byte to the checksum .
58,843
def _read_byte ( self ) : to_return = "" if ( self . _mode == PROP_MODE_SERIAL ) : to_return = self . _serial . read ( 1 ) elif ( self . _mode == PROP_MODE_TCP ) : to_return = self . _socket . recv ( 1 ) elif ( self . _mode == PROP_MODE_FILE ) : to_return = struct . pack ( "B" , int ( self . _file . readline ( ) ) ) _L...
Read a byte from input .
58,844
def _decode_temp ( byte_1 , byte_2 ) : temp = ( byte_1 << 8 ) + byte_2 if ( temp > 32767 ) : temp = temp - 65536 temp = temp / 10 return temp
Decode a signed short temperature as two bytes to a single number .
58,845
def _read_packet ( self ) : status = STATUS_WAITING mode = 0 checksum = 0 checksum_calculated = 0 length = 0 version = 0 i = 0 cnt = 0 packet = bytearray ( 0 ) while ( status != STATUS_PACKET_DONE ) : read = self . _read_ord_byte ( ) if ( status != STATUS_CTRL_CHECKSUM and status != STATUS_SENSE_CHECKSUM ) : checksum_c...
Read a packet from the input .
58,846
def _decode_sense_packet ( self , version , packet ) : data = self . _sense_packet_to_data ( packet ) offset = 4 i = 0 datalen = len ( data ) - offset - 6 temp_count = int ( datalen / 2 ) temp = [ ] for i in range ( temp_count ) : temp_index = i * 2 + offset temp . append ( self . _decode_temp ( data [ temp_index ] , d...
Decode a sense packet into the list of sensors .
58,847
def _decode_ctrl_packet ( self , version , packet ) : for i in range ( 5 ) : input_bit = packet [ i ] self . _debug ( PROP_LOGLEVEL_DEBUG , "Byte " + str ( i ) + ": " + str ( ( input_bit >> 7 ) & 1 ) + str ( ( input_bit >> 6 ) & 1 ) + str ( ( input_bit >> 5 ) & 1 ) + str ( ( input_bit >> 4 ) & 1 ) + str ( ( input_bit >...
Decode a control packet into the list of sensors .
58,848
def run ( self ) : while ( self . _run_thread ) : ( mode , version , packet ) = self . _read_packet ( ) if ( mode == PROP_PACKET_SENSE ) : self . _decode_sense_packet ( version , packet ) elif ( mode == PROP_PACKET_CTRL ) : self . _decode_ctrl_packet ( version , packet )
Main thread that reads from input and populates the sensors .
58,849
def run_thread ( self ) : self . _run_thread = True self . _thread . setDaemon ( True ) self . _thread . start ( )
Run the main thread .
58,850
def unused ( self , _dict ) : for key , value in _dict . items ( ) : if value is None : del _dict [ key ] return _dict
Remove empty parameters from the dict
58,851
def required ( self , method , _dict , require ) : for key in require : if key not in _dict : raise LunrError ( "'%s' is required argument for method '%s'" % ( key , method ) )
Ensure the required items are in the dictionary
58,852
def allowed ( self , method , _dict , allow ) : for key in _dict . keys ( ) : if key not in allow : raise LunrError ( "'%s' is not an argument for method '%s'" % ( key , method ) )
Only these items are allowed in the dictionary
58,853
def parse_event_name ( name ) : try : app , event = name . split ( '.' ) return '{}.{}' . format ( app , EVENTS_MODULE_NAME ) , event except ValueError : raise InvalidEventNameError ( ( u'The name "{}" is invalid. ' u'Make sure you are using the "app.KlassName" format' ) . format ( name ) )
Returns the python module and obj given an event name
58,854
def find_event ( name ) : try : module , klass = parse_event_name ( name ) return getattr ( import_module ( module ) , klass ) except ( ImportError , AttributeError ) : raise EventNotFoundError ( ( 'Event "{}" not found. ' 'Make sure you have a class called "{}" inside the "{}" ' 'module.' . format ( name , klass , mod...
Actually import the event represented by name
58,855
def cleanup_handlers ( event = None ) : if event : if event in HANDLER_REGISTRY : del HANDLER_REGISTRY [ event ] if event in EXTERNAL_HANDLER_REGISTRY : del EXTERNAL_HANDLER_REGISTRY [ event ] else : HANDLER_REGISTRY . clear ( ) EXTERNAL_HANDLER_REGISTRY . clear ( )
Remove handlers of a given event . If no event is informed wipe out all events registered .
58,856
def find_handlers ( event_name , registry = HANDLER_REGISTRY ) : handlers = [ ] if isinstance ( event_name , basestring ) : matched_events = [ event for event in registry . keys ( ) if fnmatch . fnmatchcase ( event_name , event ) ] for matched_event in matched_events : handlers . extend ( registry . get ( matched_event...
Small helper to find all handlers associated to a given event
58,857
def get_default_values ( data ) : request = data . get ( 'request' ) result = { } result [ '__datetime__' ] = datetime . now ( ) result [ '__ip_address__' ] = request and get_ip ( request ) or '0.0.0.0' return result
Return all default values that an event should have
58,858
def filter_data_values ( data ) : banned = ( 'request' , ) return { key : val for key , val in data . items ( ) if not key in banned }
Remove special values that log function can take
58,859
def import_event_modules ( ) : for installed_app in getsetting ( 'INSTALLED_APPS' ) : module_name = u'{}.{}' . format ( installed_app , EVENTS_MODULE_NAME ) try : import_module ( module_name ) except ImportError : pass
Import all events declared for all currently installed apps
58,860
def handle_expired_accounts ( ) : ACTIVATED = RegistrationProfile . ACTIVATED expiration_date = datetime . timedelta ( days = settings . ACCOUNT_ACTIVATION_DAYS ) to_delete = [ ] print "Processing %s registration profiles..." % str ( RegistrationProfile . objects . all ( ) . count ( ) ) for profile in RegistrationProfi...
Check of expired accounts .
58,861
def activate ( self , request , activation_key ) : if SHA1_RE . search ( activation_key ) : try : profile = RegistrationProfile . objects . get ( activation_key = activation_key ) except RegistrationProfile . DoesNotExist : return False user = profile . user user . is_active = True user . save ( ) profile . activation_...
Override default activation process . This will activate the user even if its passed its expiration date .
58,862
def register ( self , request , ** kwargs ) : if Site . _meta . installed : site = Site . objects . get_current ( ) else : site = RequestSite ( request ) email = kwargs [ 'email' ] password = User . objects . make_random_password ( ) username = sha_constructor ( str ( email ) ) . hexdigest ( ) [ : 30 ] incr = 0 while U...
Create and immediately log in a new user . Only require a email to register username is generated automatically and a password is random generated and emailed to the user . Activation is still required for account uses after specified number of days .
58,863
def send_activation_email ( self , user , profile , password , site ) : ctx_dict = { 'password' : password , 'site' : site , 'activation_key' : profile . activation_key , 'expiration_days' : settings . ACCOUNT_ACTIVATION_DAYS } subject = render_to_string ( 'registration/email/emails/password_subject.txt' , ctx_dict ) s...
Custom send email method to supplied the activation link and new generated password .
58,864
def post_registration_redirect ( self , request , user ) : next_url = "/registration/register/complete/" if "next" in request . GET or "next" in request . POST : next_url = request . GET . get ( "next" , None ) or request . POST . get ( "next" , None ) or "/" return ( next_url , ( ) , { } )
After registration redirect to the home page or supplied next query string or hidden field value .
58,865
def next ( self ) : if self . start + self . size > self . total_size : result = None else : result = Batch ( self . start + self . size , self . size , self . total_size ) return result
Returns the next batch for the batched sequence or None if this batch is already the last batch .
58,866
def previous ( self ) : if self . start - self . size < 0 : result = None else : result = Batch ( self . start - self . size , self . size , self . total_size ) return result
Returns the previous batch for the batched sequence or None if this batch is already the first batch .
58,867
def last ( self ) : start = max ( self . number - 1 , 0 ) * self . size return Batch ( start , self . size , self . total_size )
Returns the last batch for the batched sequence .
58,868
def number ( self ) : return int ( math . ceil ( self . total_size / float ( self . size ) ) )
Returns the number of batches the batched sequence contains .
58,869
def watermark ( url , args = '' ) : args = args . split ( ',' ) params = dict ( name = args . pop ( 0 ) , opacity = 0.5 , tile = False , scale = 1.0 , greyscale = False , rotation = 0 , position = None , quality = QUALITY , obscure = OBSCURE_ORIGINAL , random_position_once = RANDOM_POSITION_ONCE , ) params [ 'url' ] = ...
Returns the URL to a watermarked copy of the image specified .
58,870
def _get_filesystem_path ( self , url_path , basedir = settings . MEDIA_ROOT ) : if url_path . startswith ( settings . MEDIA_URL ) : url_path = url_path [ len ( settings . MEDIA_URL ) : ] return os . path . normpath ( os . path . join ( basedir , url2pathname ( url_path ) ) )
Makes a filesystem path from the specified URL path
58,871
def generate_filename ( self , mark , ** kwargs ) : kwargs = kwargs . copy ( ) kwargs [ 'opacity' ] = int ( kwargs [ 'opacity' ] * 100 ) kwargs [ 'st_mtime' ] = kwargs [ 'fstat' ] . st_mtime kwargs [ 'st_size' ] = kwargs [ 'fstat' ] . st_size params = [ '%(original_basename)s' , 'wm' , 'w%(watermark)i' , 'o%(opacity)i'...
Comes up with a good filename for the watermarked image
58,872
def get_url_path ( self , basedir , original_basename , ext , name , obscure = True ) : try : hash = hashlib . sha1 ( smart_str ( name ) ) . hexdigest ( ) except TypeError : hash = hashlib . sha1 ( smart_str ( name ) . encode ( 'utf-8' ) ) . hexdigest ( ) if obscure is True : logger . debug ( 'Obscuring original image ...
Determines an appropriate watermark path
58,873
def create_watermark ( self , target , mark , fpath , quality = QUALITY , ** kwargs ) : im = utils . watermark ( target , mark , ** kwargs ) im . save ( fpath , quality = quality ) return im
Create the watermarked image on the filesystem
58,874
def _val ( var , is_percent = False ) : try : if is_percent : var = float ( int ( var . strip ( '%' ) ) / 100.0 ) else : var = int ( var ) except ValueError : raise ValueError ( 'invalid watermark parameter: ' + var ) return var
Tries to determine the appropriate value of a particular variable that is passed in . If the value is supposed to be a percentage a whole integer will be sought after and then turned into a floating point number between 0 and 1 . If the value is supposed to be an integer the variable is cast into an integer .
58,875
def reduce_opacity ( img , opacity ) : assert opacity >= 0 and opacity <= 1 if img . mode != 'RGBA' : img = img . convert ( 'RGBA' ) else : img = img . copy ( ) alpha = img . split ( ) [ 3 ] alpha = ImageEnhance . Brightness ( alpha ) . enhance ( opacity ) img . putalpha ( alpha ) return img
Returns an image with reduced opacity .
58,876
def determine_scale ( scale , img , mark ) : if scale : try : scale = float ( scale ) except ( ValueError , TypeError ) : pass if isinstance ( scale , six . string_types ) and scale . upper ( ) == 'F' : scale = min ( float ( img . size [ 0 ] ) / mark . size [ 0 ] , float ( img . size [ 1 ] ) / mark . size [ 1 ] ) elif ...
Scales an image using a specified ratio F or R . If scale is F the image is scaled to be as big as possible to fit in img without falling off the edges . If scale is R the watermark resizes to a percentage of minimum size of source image . Returns the scaled mark .
58,877
def determine_rotation ( rotation , mark ) : if isinstance ( rotation , six . string_types ) and rotation . lower ( ) == 'r' : rotation = random . randint ( 0 , 359 ) else : rotation = _int ( rotation ) return rotation
Determines the number of degrees to rotate the watermark image .
58,878
def watermark ( img , mark , position = ( 0 , 0 ) , opacity = 1 , scale = 1.0 , tile = False , greyscale = False , rotation = 0 , return_name = False , ** kwargs ) : if opacity < 1 : mark = reduce_opacity ( mark , opacity ) if not isinstance ( scale , tuple ) : scale = determine_scale ( scale , img , mark ) mark = mark...
Adds a watermark to an image
58,879
def parsed_file ( config_file ) : parser = ConfigParser ( allow_no_value = True ) parser . readfp ( config_file ) return parser
Parse an ini - style config file .
58,880
def commands ( config , names ) : commands = { cmd : Command ( ** dict ( ( minus_to_underscore ( k ) , v ) for k , v in config . items ( cmd ) ) ) for cmd in config . sections ( ) if cmd != 'packages' } try : return tuple ( commands [ x ] for x in names ) except KeyError as e : raise RuntimeError ( 'Section [commands] ...
Return the list of commands to run .
58,881
def project_path ( * names ) : return os . path . join ( os . path . dirname ( __file__ ) , * names )
Path to a file in the project .
58,882
def get_osa_commit ( repo , ref , rpc_product = None ) : osa_differ . checkout ( repo , ref ) functions_path = os . path . join ( repo . working_tree_dir , 'scripts/functions.sh' ) release_path = os . path . join ( repo . working_tree_dir , 'playbooks/vars/rpc-release.yml' ) if os . path . exists ( release_path ) : wit...
Get the OSA sha referenced by an RPCO Repo .
58,883
def publish_report ( report , args , old_commit , new_commit ) : output = "" if not args . quiet and not args . gist and not args . file : return report if args . gist : gist_url = post_gist ( report , old_commit , new_commit ) output += "\nReport posted to GitHub Gist: {0}" . format ( gist_url ) if args . file is not ...
Publish the RST report based on the user request .
58,884
def run_rpc_differ ( ) : args = parse_arguments ( ) if args . debug : log . setLevel ( logging . DEBUG ) elif args . verbose : log . setLevel ( logging . INFO ) try : storage_directory = osa_differ . prepare_storage_dir ( args . directory ) except OSError : print ( "ERROR: Couldn't create the storage directory {0}. " "...
The script starts here .
58,885
def main ( raw_args = None ) : parser = argparse . ArgumentParser ( description = "poor man's integration testing" ) parser . add_argument ( 'cmds' , metavar = 'cmd' , default = [ 'test' ] , nargs = '*' , help = 'Run command(s) defined in the configuration file. Each command ' 'is run on each package before proceeding ...
Console script entry point .
58,886
def remove ( self , list ) : xml = SP . DeleteList ( SP . listName ( list . id ) ) self . opener . post_soap ( LIST_WEBSERVICE , xml , soapaction = 'http://schemas.microsoft.com/sharepoint/soap/DeleteList' ) self . all_lists . remove ( list )
Removes a list from the site .
58,887
def create ( self , name , description = '' , template = 100 ) : try : template = int ( template ) except ValueError : template = LIST_TEMPLATES [ template ] if name in self : raise ValueError ( "List already exists: '{0}" . format ( name ) ) if uuid_re . match ( name ) : raise ValueError ( "Cannot create a list with a...
Creates a new list in the site .
58,888
def Row ( self ) : if not hasattr ( self , '_row_class' ) : attrs = { 'fields' : self . fields , 'list' : self , 'opener' : self . opener } for field in self . fields . values ( ) : attrs [ field . name ] = field . descriptor self . _row_class = type ( 'SharePointListRow' , ( SharePointListRow , ) , attrs ) return self...
The class for a row in this list .
58,889
def append ( self , row ) : if isinstance ( row , dict ) : row = self . Row ( row ) elif isinstance ( row , self . Row ) : pass elif isinstance ( row , SharePointListRow ) : raise TypeError ( "row must be a dict or an instance of SharePointList.Row, not SharePointListRow" ) else : raise TypeError ( "row must be a dict ...
Appends a row to the list . Takes a dictionary returns a row .
58,890
def remove ( self , row ) : self . _rows . remove ( row ) self . _deleted_rows . add ( row )
Removes the row from the list .
58,891
def save ( self ) : batches = E . Batch ( ListVersion = '1' , OnError = 'Return' ) xml = SP . UpdateListItems ( SP . listName ( self . id ) , SP . updates ( batches ) ) rows_by_batch_id , batch_id = { } , 1 for row in self . _rows : batch = row . get_batch_method ( ) if batch is None : continue batch . attrib [ 'ID' ] ...
Updates the list with changes .
58,892
def get_batch_method ( self ) : if not self . _changed : return None batch_method = E . Method ( Cmd = 'Update' if self . id else 'New' ) batch_method . append ( E . Field ( text_type ( self . id ) if self . id else 'New' , Name = 'ID' ) ) for field in self . fields . values ( ) : if field . name in self . _changed : v...
Returns a change batch for SharePoint s UpdateListItems operation .
58,893
def convert_to_python ( self , xmlrpc = None ) : if xmlrpc : return xmlrpc . get ( self . name , self . default ) elif self . default : return self . default else : return None
Extracts a value for the field from an XML - RPC response .
58,894
def get_outputs ( self , input_value ) : output_value = self . convert_to_xmlrpc ( input_value ) output = { } for name in self . output_names : output [ name ] = output_value return output
Generate a set of output values for a given input .
58,895
def struct ( self ) : data = { } for var , fmap in self . _def . items ( ) : if hasattr ( self , var ) : data . update ( fmap . get_outputs ( getattr ( self , var ) ) ) return data
XML - RPC - friendly representation of the current object state
58,896
def get_args ( self , client ) : default_args = self . default_args ( client ) if self . method_args or self . optional_args : optional_args = getattr ( self , 'optional_args' , tuple ( ) ) args = [ ] for arg in ( self . method_args + optional_args ) : if hasattr ( self , arg ) : obj = getattr ( self , arg ) if hasattr...
Builds final set of XML - RPC method arguments based on the method s arguments any default arguments and their defined respective ordering .
58,897
def process_result ( self , raw_result ) : if self . results_class and raw_result : if isinstance ( raw_result , dict_type ) : return self . results_class ( raw_result ) elif isinstance ( raw_result , collections . Iterable ) : return [ self . results_class ( result ) for result in raw_result ] return raw_result
Performs actions on the raw result from the XML - RPC response . If a results_class is defined the response will be converted into one or more object instances of that class .
58,898
def parse ( self , text ) : results = [ ] if isinstance ( text , str ) : if six . PY2 : text = unicode ( text , 'utf-8' ) self . clean_text = self . _normalize_string ( text ) addresses = set ( self . _get_addresses ( self . clean_text ) ) if addresses : results = list ( map ( self . _parse_address , addresses ) ) retu...
Returns a list of addresses found in text together with parsed address parts
58,899
def _parse_address ( self , address_string ) : match = utils . match ( self . rules , address_string , flags = re . VERBOSE | re . U ) if match : match_as_dict = match . groupdict ( ) match_as_dict . update ( { 'country_id' : self . country } ) cleaned_dict = self . _combine_results ( match_as_dict ) return address . A...
Parses address into parts