Best Python code snippet using elementium_python
__init__.py
Source:__init__.py  
1import re2from vFense.core._constants import CPUThrottleValues, DefaultStringLength3from vFense.core.customer._constants import CustomerDefaults4class CustomerCollections():5    Customers = 'customers'6    CustomersPerUser = 'customers_per_user'7class CustomerKeys():8    CustomerName = 'customer_name'9    Properties = 'properties'10    NetThrottle = 'net_throttle'11    CpuThrottle = 'cpu_throttle'12    PackageUrl = 'package_download_url_base'13    ServerQueueTTL = 'server_queue_ttl' # in minutes14    AgentQueueTTL = 'agent_queue_ttl' # in minutes15    Users = 'users' #Mapped Keys16    Groups = 'groups' #Mapped Keys17class CustomerPerUserKeys():18    CustomerName = 'customer_name'19    UserName = 'user_name'20    Id = 'id'21class CustomerPerUserIndexes():22    CustomerName = 'customer_name'23    UserName = 'user_name'24class Customer(object):25    """Used to represent an instance of a customer."""26    def __init__(27        self, name, net_throttle=None, cpu_throttle=None,28        server_queue_ttl=None, agent_queue_ttl=None,29        package_download_url=None30    ):31        """32        Args:33            name (str): The name of the customer34            net_throttle (int): The default net throttling for downloading35                packages for agents in this customer, in KB/s.36            cpu_throttle (str): The default cpu throttling for operations37                in this customer. Has to be a valid cpu throttling keyword.38                    valid: ['idle', 'below_normal', 'normal', 'above_normal', 'high']39            server_queue_ttl (int): The default time an operation will sit40                on the server queue, in minutes. Must be above 0.41            agent_queue_ttl (int): The default time an operation will sit42                on the agent queue, in minutes. Must be above 0.43            package_download_url (str): The base url used to construct the44                urls where the packages will be downloaded from.45                    Ex:46                        'https://192.168.1.1/packages/'47        """48        self.name = name49        self.net_throttle = net_throttle50        self.cpu_throttle = cpu_throttle51        self.server_queue_ttl = server_queue_ttl52        self.agent_queue_ttl = agent_queue_ttl53        self.package_download_url = package_download_url54        if net_throttle:55            self.net_throttle = int(net_throttle)56        if server_queue_ttl:57            self.server_queue_ttl = int(server_queue_ttl)58        if agent_queue_ttl:59            self.agent_queue_ttl = int(agent_queue_ttl)60    def fill_in_defaults(self):61        """Replace all the fields that have None as their value with62        the hardcoded default values.63        64        Use case(s):65            Useful when creating a new customer instance and only want to fill66            in a few fields, then allow the create customer functions call this67            method to fill in the rest.68        """69        if not self.net_throttle:70            self.net_throttle = CustomerDefaults.NET_THROTTLE71        if not self.cpu_throttle:72            self.cpu_throttle = CustomerDefaults.CPU_THROTTLE73        if not self.server_queue_ttl:74            self.server_queue_ttl = CustomerDefaults.SERVER_QUEUE_TTL75        if not self.agent_queue_ttl:76            self.agent_queue_ttl = CustomerDefaults.AGENT_QUEUE_TTL77    def get_invalid_fields(self):78        """Check the customer for any invalid fields.79        Returns:80            (list): List of key/value pair dictionaries corresponding81                to the invalid fields.82                Ex:83                    [84                        {'customer_name': 'the invalid name in question'},85                        {'net_throttle': -10}86                    ]87        """88        invalid_fields = []89        if isinstance(self.name, basestring):90            valid_symbols = re.search(91                '((?:[A-Za-z0-9_-](?!\s+")|\s(?!\s*")){1,36})', self.name92            )93            valid_length = len(self.name) <= DefaultStringLength.CUSTOMER_NAME94            if not valid_symbols or not valid_length:95                invalid_fields.append(96                    {CustomerKeys.CustomerName: self.name}97                )98        else:99            invalid_fields.append(100                {CustomerKeys.CustomerName: self.name}101            )102        if self.net_throttle:103            if isinstance(self.net_throttle, int):104                if self.net_throttle < 0:105                    invalid_fields.append(106                        {CustomerKeys.NetThrottle: self.net_throttle}107                    )108            else:109                invalid_fields.append(110                    {CustomerKeys.NetThrottle: self.net_throttle}111                )112        if self.cpu_throttle:113            if self.cpu_throttle not in CPUThrottleValues.VALID_VALUES:114                invalid_fields.append(115                    {CustomerKeys.CpuThrottle: self.cpu_throttle}116                )117        if self.server_queue_ttl:118            if isinstance(self.server_queue_ttl, int):119                if self.server_queue_ttl <= 0:120                    invalid_fields.append(121                        {CustomerKeys.ServerQueueTTL: self.server_queue_ttl}122                    )123            else:124                invalid_fields.append(125                    {CustomerKeys.ServerQueueTTL: self.server_queue_ttl}126                )127        if self.agent_queue_ttl:128            if isinstance(self.agent_queue_ttl, int):129                if self.agent_queue_ttl <= 0:130                    invalid_fields.append(131                        {CustomerKeys.AgentQueueTTL: self.agent_queue_ttl}132                    )133            else:134                invalid_fields.append(135                    {CustomerKeys.AgentQueueTTL: self.agent_queue_ttl}136                )137        # TODO: check for invalid package url138        return invalid_fields139    def to_dict(self):140        """ Turn the customer fields into a dictionary.141        Returns:142            (dict): A dictionary with the fields corresponding to the143                customer.144                Ex:145                {146                    "agent_queue_ttl": 100 ,147                    "cpu_throttle":  "high" ,148                    "customer_name":  "default" ,149                    "net_throttle": 100 ,150                    "package_download_url_base": https://192.168.8.14/packages/,151                    "server_queue_ttl": 100152                }153                    154        """155        return {156            CustomerKeys.CustomerName: self.name,157            CustomerKeys.NetThrottle: self.net_throttle,158            CustomerKeys.CpuThrottle: self.cpu_throttle,159            CustomerKeys.ServerQueueTTL: self.server_queue_ttl,160            CustomerKeys.AgentQueueTTL: self.agent_queue_ttl,161            CustomerKeys.PackageUrl: self.package_download_url162        }163    def to_dict_non_null(self):164        """ Use to get non None fields of customer. Useful when165        filling out just a few fields to update the customer in the db.166        Returns:167            (dict): a dictionary with the non None fields of this customer.168        """169        customer_dict = self.to_dict()170        return {k:customer_dict[k] for k in customer_dict...constants.py
Source:constants.py  
1import random2#  TTL (time to live) ç§3class CacheTTLBase(object):4    """5    çææææçç¶ç±»6    """7    # æææçåºç¡å¼8    TTL = 2 * 60 * 609    # æææéæºçæå¤§ä¸éåå·®10    MAX_DELTA = 10 * 6011    @classmethod12    def get_val(cls):13        return cls.TTL + random.randint(0, cls.MAX_DELTA)14class UserProfileCacheTTL(CacheTTLBase):15    # ç¨æ·èµæç¼åæææ16    pass17class UserNotExistsCacheTTL(CacheTTLBase):18    # è®°å½ç¨æ·ä¸åå¨çç¼åæææ19    TTL = 10 * 6020    MAX_DELTA = 6021class UserStatusCacheTTL(CacheTTLBase):22    """23    ç¨æ·ç¶æç¼åæ¶é´ï¼ç§24    """25    TTL = 60 * 6026class UserFollowingsCacheTTL(CacheTTLBase):27    """28    ç¨æ·å
³æ³¨å表ç¼åæ¶é´ï¼ç§29    """30    TTL = 30 * 6031class UserRelationshipCacheTTL(CacheTTLBase):32    """33    ç¨æ·å
³ç³»ç¼åæ¶é´ï¼ç§34    """35    TTL = 30 * 6036class UserRelationshipNotExistsCacheTTL(CacheTTLBase):37    """38    ç¨æ·å
³ç³»ä¸å卿°æ®ç¼åæ¶é´ï¼ç§39    """40    TTL = 5 * 6041    MAX_DELTA = 6042class UserAdditionalProfileCacheTTL(CacheTTLBase):43    """44    ç¨æ·è¯¦ç»èµæç¼åæ¶é´ï¼ç§45    """46    TTL = 10 * 6047    MAX_DELTA = 2 * 6048class UserFansCacheTTL(CacheTTLBase):49    """50    ç¨æ·ç²ä¸å表ç¼åæ¶é´ï¼ç§51    """52    TTL = 30 * 6053class UserChannelsCacheTTL(CacheTTLBase):54    """55    ç¨æ·é¢éç¼åæ¶é´ï¼ç§56    """57    TTL = 60 * 6058class UserArticleAttitudeCacheTTL(CacheTTLBase):59    """60    ç¨æ·æç« æåº¦ç¼åæ¶é´ï¼ç§61    """62    TTL = 30 * 6063class UserArticleAttitudeNotExistsCacheTTL(CacheTTLBase):64    """65    ç¨æ·æç« æåº¦ä¸å卿°æ®ç¼åæ¶é´ï¼ç§66    """67    TTL = 5 * 6068    MAX_DELTA = 6069class UserCommentLikingCacheTTL(CacheTTLBase):70    """71    ç¨æ·æç« è¯è®ºç¹èµç¼åæ¶é´ï¼ç§72    """73    TTL = 10 * 6074    MAX_DELTA = 2 * 6075class UserCommentLikingNotExistsCacheTTL(CacheTTLBase):76    """77    ç¨æ·æç« è¯è®ºç¹èµä¸å卿°æ®ç¼åæ¶é´ï¼ç§78    """79    TTL = 3 * 6080    MAX_DELTA = 6081class ArticleInfoCacheTTL(CacheTTLBase):82    """83    æç« ä¿¡æ¯ç¼åæ¶é´ï¼ç§84    """85    TTL = 30 * 6086class ArticleNotExistsCacheTTL(CacheTTLBase):87    """88    æç« ä¸åå¨ç»æç¼å89    为解å³ç¼åå»ç©¿ï¼æææä¸å®è¿é¿90    """91    TTL = 5 * 6092    MAX_DELTA = 6093class ArticleDetailCacheTTL(CacheTTLBase):94    """95    æç« è¯¦ç»å
容ç¼åæ¶é´ï¼ç§96    """97    TTL = 60 * 6098class ArticleUserNoAttitudeCacheTTL(CacheTTLBase):99    """100    ç¨æ·å¯¹æç« æ æåº¦ç¼å101    为解å³ç¼åå»ç©¿ï¼æææä¸å®è¿é¿102    """103    TTL = 3 * 60104    MAX_DELTA = 30105class UserArticlesCacheTTL(CacheTTLBase):106    """107    ç¨æ·æç« ä½åç¼åæ¶é´ï¼ç§108    """109    TTL = 10 * 60110    MAX_DELTA = 2 * 60111class UserArticleCollectionsCacheTTL(CacheTTLBase):112    """113    ç¨æ·æç« æ¶èç¼åæ¶é´ï¼ç§114    """115    TTL = 10 * 60116    MAX_DELTA = 2 * 60117class ArticleCommentsCacheTTL(CacheTTLBase):118    """119    æç« è¯è®ºå表ç¼åæ¶é´ï¼ç§120    """121    TTL = 30 * 60122class CommentRepliesCacheTTL(CacheTTLBase):123    """124    è¯è®ºåå¤å表ç¼åæ¶é´ï¼ç§125    """126    TTL = 30 * 60127class CommentCacheTTL(CacheTTLBase):128    """129    è¯è®ºä¿¡æ¯ç¼åæ¶é´ï¼ç§130    """131    TTL = 30 * 60132class CommentNotExistsCacheTTL(CacheTTLBase):133    """134    è¯è®ºä¸åå¨ç»æç¼å135    为解å³ç¼åå»ç©¿ï¼æææä¸å®è¿é¿136    """137    TTL = 5 * 60138    MAX_DELTA = 60139class AnnouncementDetailCacheTTL(CacheTTLBase):140    """141    ç³»ç»å
¬å详ç»ä¿¡æ¯ç¼åæ¶é´ï¼ç§142    """143    TTL = 2 * 60 * 60144class AnnouncementNotExistsCacheTTL(CacheTTLBase):145    """146    å
¬åä¸åå¨ç»æç¼å147    为解å³ç¼åå»ç©¿ï¼æææä¸å®è¿é¿148    """149    TTL = 5 * 60150    MAX_DELTA = 60151# ç¼åè¯è®ºæå¤§SCORE152COMMENTS_CACHE_MAX_SCORE = 2e19153# é»è®¤ç¨æ·å¤´å154DEFAULT_USER_PROFILE_PHOTO = 'Fkj6tQi3xJwVXi1u2swCElotfdCi'  # ç¨åºç¿155# é
读å岿¯äººä¿åæ°ç®156READING_HISTORY_COUNT_PER_USER = 100157# ç¨æ·æç´¢å岿¯äººä¿åæ°ç®158SEARCHING_HISTORY_COUNT_PER_USER = 4159# å
è®¸æ´æ°å
³æ³¨ç¼åçTTLéå¶ï¼ç§160ALLOW_UPDATE_FOLLOW_CACHE_TTL_LIMIT = 5161# é»è®¤ç¨æ·é¢éç¼åæææï¼ç§162DEFAULT_USER_CHANNELS_CACHE_TTL = 24 * 60 * 60163# å
¨é¨é¢éç¼åæææï¼ç§164ALL_CHANNELS_CACHE_TTL = 24 * 60 * 60165# å
è®¸æ´æ°æç« è¯è®ºå表ç¼åçTTLéå¶ï¼ç§166ALLOW_UPDATE_ARTICLE_COMMENTS_CACHE_TTL_LIMIT = 5167# ç³»ç»å
¬åç¼åæ¶é´ï¼ç§...Train.py
Source:Train.py  
1#  File: Train.py2#  Description: A turtle graphics attempt of drawing a choo-choo train3#  Student Name: Stephen Rauner 4#  Student UT EID: STR4285#  Course Name: CS 313E6#  Unique Number: 509457#  Date Created: 2/28/168#  Date Last Modified: 2/29/169import turtle10import math11def drawLine (ttl, x1, y1, x2, y2):12    ttl.penup()13    ttl.goto(x1, y1)14    ttl.pendown()15    ttl.goto(x2, y2)16    ttl.penup()17def tracks(ttl, start_x, num):18	ttl.penup()19	ttl.goto(start_x, -310)20	y = -31021	w = 2322	h = 523	for i in range(num):24		ttl.goto(start_x + (i*45), y)25		ttl.pendown()26		drawLine(ttl, start_x + (i * 45), y, start_x + (i * 45), y - h)27		drawLine(ttl, start_x + (i * 45), y - h, start_x + w + (i * 45), y - h)28		drawLine(ttl, start_x + w + (i * 45), y - h, start_x + w +(i * 45), y)29		ttl.penup()30def spokes(ttl, cen_x, cen_y, r):31	for i in range(8):32		ttl.penup()33		ttl.goto(cen_x, cen_y)34		ttl.tilt(45)35		ttl.pendown()36		ttl.forward(r - 10)37def wheels(ttl):38	# big wheel39	ttl.color("red")40	ttl.penup()41	ttl.goto(-200, -300)42	ttl.pendown()43	ttl.circle(50)44	ttl.penup()45	ttl.goto(-200, -290)46	ttl.pendown()47	ttl.circle(40)48	spokes(ttl, -200, -250, 50)49	ttl.penup()50	ttl.goto(-200, -260)51	ttl.pendown()52	ttl.circle(10)	53	# small wheel 154	ttl.penup()55	ttl.goto(-30, -300)56	ttl.pendown()57	ttl.circle(40)58	ttl.penup()59	ttl.goto(-30, -290)60	ttl.pendown()61	ttl.circle(30)62	spokes(ttl, -30, -260, 40)63	ttl.penup()64	ttl.goto(-30, -265)65	ttl.pendown()66	ttl.circle(5)	67	# small wheel 268	ttl.penup()69	ttl.goto(100, -300)70	ttl.pendown()71	ttl.circle(40)72	ttl.penup()73	ttl.goto(100, -290)74	ttl.pendown()75	ttl.circle(30)76	spokes(ttl, 100, -260, 40)77	ttl.penup()78	ttl.goto(100, -265)79	ttl.pendown()80	ttl.circle(5)81def main():82	turtle.title("Choo-Choo")83	turtle.setup(800, 800, 0, 0)84	turtle.speed(0)85	turtle.ht()86	ttl = turtle.Turtle()87	ttl.ht()88	drawLine(ttl, -300, -300, 300, -300)89	drawLine(ttl, -300, -310, 300, -310)90	count = 1091	tracks(ttl, -290, 13)92	wheels(ttl)93	turtle.done()...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
