Best Python code snippet using slash
models.py
Source:models.py  
1from django.contrib.auth.models import User2from django.db import models3from datetime import datetime4from .agave_adapter import AgaveAdapter5from .dropbox_adapter import DropboxAdapter6import hashlib7import os8class TransferBatch(models.Model):9    STATUS_CHOICES = (10        ('PD', 'pending'),11        ('RN', 'running'),12        ('ER', 'complete with errors'),13        ('CP', 'complete')14    )15    user = models.ForeignKey(User, on_delete=models.CASCADE)16    dateInitiated = models.DateTimeField(auto_now_add=True)17    status = models.CharField(18        default='PD',19        choices=STATUS_CHOICES,20        max_length=221    )22    hash = models.CharField(max_length=8, unique=True, default=None)23    def save(self, *args, **kwargs):24        if self.hash is None:25            self.hash = hashlib.sha256(26                (str(self.user) + str(datetime.now())).encode('utf-8')27            ).hexdigest()[0:8]28        super().save(*args, **kwargs)29class TransferFile(models.Model):30    STATUS_CHOICES = (31        ('PD', 'pending'),32        ('DL', 'downloading'),33        ('DF', 'download failed'),34        ('DS', 'download succeeded'),35        ('UP', 'uploading'),36        ('UF', 'upload failed'),37        ('US', 'upload succeeded'),38        ('CP', 'complete'),39        ('ED', 'expanding directory'),40    )41    # State transition table for files42    # PD => DL => DS => UP => US => CP43    # DL => DF => DL   (error condition)44    # UP => UF => UP   (error condition)45    # State transition table for directories46    # PD => ED => CP47    batch = models.ForeignKey(48        'TransferBatch',49        on_delete=models.CASCADE,50        related_name='files'51    )52    status = models.CharField(53        default='PD',54        choices=STATUS_CHOICES,55        max_length=256    )57    retries = models.PositiveIntegerField(default=0)58    fromPath = models.CharField(max_length=500)59    toPath = models.CharField(max_length=500)60    def get_from_adapter(self):61        from_tokens = self.fromPath.split('/')62        if from_tokens[1] == 'dropbox':63            return DropboxAdapter()64        elif from_tokens[1] == 'agave':65            return AgaveAdapter()66        else:67            raise ValueError68    def get_to_adapter(self):69        to_tokens = self.toPath.split('/')70        if to_tokens[1] == 'dropbox':71            return DropboxAdapter()72        elif to_tokens[1] == 'agave':73            return AgaveAdapter()74        else:75            raise ValueError76    def download(self):77        from_tokens = self.fromPath.split('/')78        local_path = '/'.join([''] + from_tokens[3:])79        adapter = self.get_from_adapter()80        adapter.download(81            local_path,82            self.fromPath,83            self.batch.user,84            self.batch.hash85        )86    def upload(self):87        from_tokens = self.fromPath.split('/')88        local_path = '/'.join([''] + from_tokens[3:])89        adapter = self.get_to_adapter()90        adapter.upload(91            local_path,92            self.toPath,93            self.batch.user,94            self.batch.hash95        )96    def cleanup(self):97        from_tokens = self.fromPath.split('/')98        localPath = '/'.join([''] + from_tokens[3:])99        fullLocalPath = '/transient/%s/' % self.batch.hash + localPath100        if os.path.exists(fullLocalPath):...pattern_matching.py
Source:pattern_matching.py  
...32    def __init__(self, matchers):33        super(BinaryMatching, self).__init__()34        self.matchers = matchers35    @classmethod36    def from_tokens(cls, t):37        return cls(t[0][0::2])38    def matches(self, metadata):39        # pylint: disable=not-callable40        return self.aggregator(matcher.matches(metadata) for matcher in self.matchers)41class AndMatching(BinaryMatching):42    aggregator = all43class OrMatching(BinaryMatching):44    aggregator = any45class Exclude(object):46    def __init__(self, t):47        super(Exclude, self).__init__()48        self.matcher = t[0][1]49    def matches(self, metadata):50        return not self.matcher.matches(metadata)...start_Spacing.py
Source:start_Spacing.py  
...12        return self.add_space(node)1314    def add_space(self, node):15        self.changed_lines += 116        space = Statement.from_tokens([Token(Token.EOL, '\n')])17        node.body.insert(-1, space)18        return self.generic_visit(node)1920    def get_changed_lines(self):21        return self.changed_lines222324class ChangeSpacingKeyword(ModelTransformer):25    def __init__(self):26        self.changed_lines: int = 02728    def visit_KeywordSection(self, node):29        return self.add_space(node)3031    def add_space(self, node):32        self.changed_lines += 133        space = Statement.from_tokens([Token(Token.EOL, '\n')])34        node.body.insert(-1, space)35        return self.generic_visit(node)3637    def get_changed_lines(self):38        return self.changed_lines394041class ChangeSpacingTestCase(ModelTransformer):42    def __init__(self):43        self.changed_lines: int = 04445    def visit_TestCaseSection(self, node):46        return self.add_space(node)4748    def add_space(self, node):49        self.changed_lines += 150        space = Statement.from_tokens([Token(Token.EOL, '\n')])51        node.body.insert(-1, space)52        return self.generic_visit(node)5354    def get_changed_lines(self):55        return self.changed_lines565758class ChangeSpacingVariable(ModelTransformer):59    def __init__(self):60        self.changed_lines: int = 06162    def visit_VariableSection(self, node):63        return self.add_space(node)6465    def add_space(self, node):66        self.changed_lines += 167        space = Statement.from_tokens([Token(Token.EOL, '\n')])68        node.body.insert(-1, space)69        return self.generic_visit(node)7071    def get_changed_lines(self):72        return self.changed_lines737475767778
...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!!
